Source Code Cross Referenced for PortletAdmin.java in  » Portal » Open-Portal » com » sun » portal » portlet » admin » mbeans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.portlet.admin.mbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /**
0002:         * $Id: PortletAdmin.java,v 1.22 2006/07/28 02:42:53 portalbld Exp $
0003:         * Copyright 2004 Sun Microsystems, Inc. All
0004:         * rights reserved. Use of this product is subject
0005:         * to license terms. Federal Acquisitions:
0006:         * Commercial Software -- Government Users
0007:         * Subject to Standard License Terms and
0008:         * Conditions.
0009:         *
0010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0011:         * are trademarks or registered trademarks of Sun Microsystems,
0012:         * Inc. in the United States and other countries.
0013:         */package com.sun.portal.portlet.admin.mbeans;
0014:
0015:        import java.io.*;
0016:        import java.util.*;
0017:        import java.util.logging.Level;
0018:        import java.util.logging.Logger;
0019:        import java.util.logging.LogRecord;
0020:        import java.net.UnknownHostException;
0021:        import java.net.InetAddress;
0022:
0023:        import com.sun.portal.desktop.context.AdminDPContext;
0024:        import com.sun.portal.desktop.admin.mbeans.tasks.DPHelper;
0025:        import com.sun.portal.desktop.admin.mbeans.tasks.DesktopDataException;
0026:
0027:        import com.sun.portal.admin.common.context.PSConfigContext;
0028:        import com.sun.portal.admin.common.PSConfigConstants;
0029:        import com.sun.portal.admin.common.context.PortalDomainContext;
0030:        import com.sun.portal.admin.common.PSMBeanException;
0031:        import com.sun.portal.admin.common.util.AdminUtil;
0032:        import com.sun.portal.admin.common.util.AdminClientUtil;
0033:        import com.sun.portal.admin.common.util.UploadDownloadException;
0034:        import com.sun.portal.admin.server.mbeans.PSResource;
0035:        import com.sun.portal.admin.server.AdminServerUtil;
0036:        import com.sun.portal.admin.server.PASModule;
0037:
0038:        import com.sun.portal.portlet.admin.mbeans.tasks.PDDeploy;
0039:        import com.sun.portal.portlet.admin.mbeans.tasks.PDUNDeploy;
0040:        import com.sun.portal.portlet.admin.mbeans.tasks.PortletDeployerException;
0041:        import com.sun.portal.fabric.mbeans.PortalServerInstanceMBean;
0042:        import com.sun.portal.util.ResourceLoader;
0043:        import com.sun.portal.log.common.PortalLogger;
0044:        import com.sun.portal.taskadmin.TaskAdminException;
0045:        import com.sun.portal.taskadmin.PortletTaskAdmin;
0046:
0047:        import com.sun.portal.portlet.admin.mbeans.tasks.DPRegister;
0048:        import com.sun.portal.portlet.admin.mbeans.tasks.DPUNRegister;
0049:
0050:        import javax.management.*;
0051:        import javax.management.remote.JMXConnector;
0052:
0053:        /**
0054:         * $Id: PortletAdmin.java,v 1.22 2006/07/28 02:42:53 portalbld Exp $
0055:         * Copyright 2004 Sun Microsystems, Inc. All
0056:         * rights reserved. Use of this product is subject
0057:         * to license terms. Federal Acquisitions:
0058:         * Commercial Software -- Government Users
0059:         * Subject to Standard License Terms and
0060:         * Conditions.
0061:         *
0062:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0063:         * are trademarks or registered trademarks of Sun Microsystems,
0064:         * Inc. in the United States and other countries.
0065:         */
0066:
0067:        //This class implements PortletAdminMBean interface and implements methods
0068:        //to deploy and undeploy portlets.
0069:        public class PortletAdmin extends PSResource implements 
0070:                PortletAdminMBean {
0071:            //private static final String DEBUG_FILE = "portal.admin.Portlet";
0072:            private static final String MSG_PREFIX = "portlet.";
0073:            private static final String HOST_INSTANCE_SEPARATOR = "_";
0074:            private static final String DD_LOCATION = "DDFileLocation";
0075:            private String psPortalID;
0076:            private String psDomainID;
0077:            private PSConfigContext cc = null;
0078:            private Properties pconfProperties = null;
0079:            private static final String WAR_SUFFIX = ".war";
0080:            private static final String DD_SUFFIX = ".xml";
0081:            private static Logger logger = PortalLogger
0082:                    .getLogger(PortletAdmin.class);
0083:            private ObjectName myName = null;
0084:
0085:            public void init(PSConfigContext cc, PortalDomainContext pdc,
0086:                    List path) {
0087:                super .init(cc, pdc, path);
0088:                try {
0089:                    this .cc = cc;
0090:                    this .psDomainID = (String) path.get(2);
0091:                    this .psPortalID = (String) path.get(1);
0092:                    myName = AdminUtil.getResourceMBeanObjectName(TYPE, path);
0093:                } catch (Exception e) {
0094:                    logger.log(Level.SEVERE, "MBean initialization failed", e);
0095:                    throw new RuntimeException(e);
0096:                }
0097:            }
0098:
0099:            /**
0100:             * Gets the PDConfig.properties file name based on the portal ID
0101:             */
0102:            private Properties getPortletConfigProperties() {
0103:                Properties pConf = null;
0104:                try {
0105:                    // Get the resource loader
0106:                    ResourceLoader rcl = ResourceLoader.getInstance(psPortalID);
0107:                    pConf = rcl
0108:                            .getProperties(PSConfigConstants.PS_PORTLET_CONFIG_FILE);
0109:                } catch (IOException ioe) {
0110:                    pConf = null;
0111:                    logger.log(Level.SEVERE, "PSPL_CSPPAM0005", ioe);
0112:                }
0113:                return pConf;
0114:            }
0115:
0116:            private boolean isWinOS() {
0117:                return System.getProperty("os.name").indexOf("indows") != -1;
0118:            }
0119:
0120:            /**
0121:             * Gets admin dp context
0122:             */
0123:            private AdminDPContext getAdminDPContext() throws PSMBeanException {
0124:                AdminDPContext adpContext = null;
0125:                try {
0126:                    DPHelper dpHelper = DPHelper.getDPHelper(
0127:                            getPSConfigContext(),
0128:                            AdminServerUtil.getSSOToken(), psPortalID);
0129:                    adpContext = (AdminDPContext) dpHelper
0130:                            .getAdminDPContext(psPortalID);
0131:                    adpContext.init(AdminServerUtil.getSSOToken(), null,
0132:                            psPortalID);
0133:                } catch (DesktopDataException de) {
0134:                    logger.log(Level.SEVERE, "PSPL_CSPPAM0001" + de);
0135:                    throw new PSMBeanException(MSG_PREFIX + "errorDesktopData",
0136:                            de);
0137:                }
0138:                return adpContext;
0139:            }
0140:
0141:            /**
0142:             * method to deploy all instances
0143:             */
0144:            public Boolean deployAll(String dn, Boolean global, String warFile,
0145:                    Properties roles, Properties userinfo, Boolean verbose,
0146:                    List instanceList, Boolean toContinue, Boolean nodeploy)
0147:                    throws PSMBeanException {
0148:                List instances = null;
0149:                Boolean deployedAtAllInstances = new Boolean(true);
0150:                boolean isContinue = false;
0151:                if (nodeploy.booleanValue()) {
0152:                    deployedAtAllInstances = deploy(dn, global, warFile, roles,
0153:                            userinfo, verbose, instances, toContinue, nodeploy);
0154:                    return deployedAtAllInstances;
0155:                }
0156:                if (instanceList == null) {
0157:                    //get all instances for this portal
0158:                    try {
0159:                        instances = getInstanceNames();
0160:                    } catch (Exception e) {
0161:                        logMessage("PSPL_CSPPAM0009",
0162:                                new String[] { psPortalID }, e);
0163:                        throw new PSMBeanException(MSG_PREFIX
0164:                                + "errorGettingPortalInstances",
0165:                                new String[] { psPortalID });
0166:                    }
0167:                } else {
0168:                    instances = instanceList; //comma separated instances entered at client
0169:                }
0170:                //if there is only one instance, we want to throw correct message at cli.
0171:                if (instances.size() > 1) {
0172:                    isContinue = toContinue.booleanValue();
0173:                }
0174:                List hostsList = getHostNames(instances); //hosts where these instances are installed
0175:                Iterator iter = hostsList.iterator();
0176:
0177:                //if portal instance is on local host
0178:                while (iter.hasNext()) {
0179:                    String hostName = (String) iter.next();
0180:                    try {
0181:                        if (AdminUtil.isLocal(hostName)) {
0182:                            //modifies dp using this mbean at local host and deploys to all the instances on this and all other hosts .
0183:                            deployedAtAllInstances = deploy(dn, global,
0184:                                    warFile, roles, userinfo, verbose,
0185:                                    instances, new Boolean(isContinue),
0186:                                    nodeploy);
0187:                            return deployedAtAllInstances;
0188:                        }
0189:                    } catch (UnknownHostException uhe) {
0190:                        logger.log(Level.SEVERE, "PSPL_CSPPAM0005", uhe);
0191:                        String[] tokens = { hostName };
0192:                        throw new PSMBeanException(MSG_PREFIX
0193:                                + "errorUnknownHost", tokens);
0194:                    }
0195:                }
0196:                //if portal instance is not on local host
0197:                iter = hostsList.iterator();
0198:                String[] signature = { "java.lang.String", "java.lang.Boolean",
0199:                        "java.lang.String", "java.util.Properties",
0200:                        "java.util.Properties", "java.lang.Boolean",
0201:                        "java.util.List", "java.lang.Boolean",
0202:                        "java.lang.Boolean" };
0203:                JMXConnector connector = null;
0204:                MBeanServerConnection mbsc = null;
0205:
0206:                while (iter.hasNext()) {
0207:                    //host is remote
0208:                    String hostName = (String) iter.next();
0209:                    try {
0210:                        connector = AdminServerUtil.getJMXConnector(hostName);
0211:                        mbsc = connector.getMBeanServerConnection();
0212:                    } catch (IOException ioe) {
0213:                        String[] tokens = { hostName };
0214:                        logMessage("PSPL_CSPPAM0010", tokens, ioe);
0215:                        if (!isContinue) {
0216:                            throw new PSMBeanException(MSG_PREFIX
0217:                                    + "errorConnectingToHost", tokens);
0218:                        }
0219:                        deployedAtAllInstances = new Boolean(false);
0220:                        continue;
0221:                    }
0222:                    String[] nameId = null;
0223:                    try {
0224:                        //upload this file to this host and get the absolute filename of uploaded file.
0225:                        nameId = AdminClientUtil.uploadFile(mbsc, psDomainID,
0226:                                new File(warFile), 0);
0227:                    } catch (UploadDownloadException upde) {
0228:                        String[] tokens = { nameId[1], hostName };
0229:                        logMessage("PSPL_CSPPAM0011", tokens, upde);
0230:                        if (!isContinue) {
0231:                            throw new PSMBeanException(MSG_PREFIX
0232:                                    + "errorUploadingToHost", tokens);
0233:                        }
0234:                        //iterate to next host
0235:                        deployedAtAllInstances = new Boolean(false);
0236:                        continue;
0237:                    }
0238:                    try {
0239:                        Object[] params = { dn, global, nameId[1], roles,
0240:                                userinfo, verbose, instances,
0241:                                new Boolean(isContinue), nodeploy };
0242:                        //modifies dp and deploys to all the instances on all other hosts .
0243:                        deployedAtAllInstances = (Boolean) mbsc.invoke(myName,
0244:                                "deploy", params, signature);
0245:                        return deployedAtAllInstances;
0246:                    } catch (MBeanException me) {
0247:                        String[] tokens = { nameId[1], hostName };
0248:                        logMessage("PSPL_CSPPAM0012", tokens, me);
0249:                        if (!isContinue) {
0250:                            PSMBeanException pme = (PSMBeanException) me
0251:                                    .getTargetException();
0252:                            throw new PSMBeanException(pme.getErrorKey(), pme
0253:                                    .getTokens());
0254:                        }
0255:                        deployedAtAllInstances = new Boolean(false);
0256:                        continue;
0257:                    } catch (Exception e) {
0258:                        String[] tokens = { nameId[1], hostName };
0259:                        logMessage("PSPL_CSPPAM0012", tokens, e);
0260:                        if (!isContinue) {
0261:                            throw new PSMBeanException(MSG_PREFIX
0262:                                    + "errorDeploy", tokens);
0263:                        }
0264:                        deployedAtAllInstances = new Boolean(false);
0265:                        continue;
0266:                    } finally {
0267:                        //do file cleanup
0268:                        try {
0269:                            AdminClientUtil.uploadDownloadCleanUp(mbsc,
0270:                                    psDomainID, nameId[0]);
0271:                        } catch (UploadDownloadException upe) {
0272:                            ;
0273:                        }
0274:                        closeConnector(connector);
0275:                    }
0276:                }
0277:                return deployedAtAllInstances;
0278:            }
0279:
0280:            // START Portlet Registration methods
0281:            public void registerPortletApp(String dn, Boolean global,
0282:                    String earFile, Properties roles, Properties userinfo,
0283:                    Boolean verbose) throws PSMBeanException {
0284:
0285:                Properties pconfProperties = getPortletConfigProperties();
0286:                if (pconfProperties == null) {
0287:                    throw new PSMBeanException(MSG_PREFIX + "errorConfigFile");
0288:                }
0289:
0290:                try {
0291:                    AdminDPContext adc = getAdminDPContext();
0292:                    DPRegister dpRegister = new DPRegister(pconfProperties);
0293:                    dpRegister.process(adc, dn, global.booleanValue(),
0294:                            new File(earFile), roles, userinfo, verbose
0295:                                    .booleanValue(), logger);
0296:
0297:                } catch (PortletDeployerException pde) {
0298:                    logger.log(Level.SEVERE, "PSPL_CSPPAM0004", pde.getCause());
0299:                    throw new PSMBeanException(MSG_PREFIX + pde.getKey(), pde
0300:                            .getCause(), pde.getTokens());
0301:
0302:                }
0303:            }
0304:
0305:            public void unregisterPortletApp(String dn, Boolean global,
0306:                    String earAppName, Boolean verbose) throws PSMBeanException {
0307:
0308:                Properties pconfProperties = getPortletConfigProperties();
0309:                if (pconfProperties == null) {
0310:                    throw new PSMBeanException(MSG_PREFIX + "errorConfigFile");
0311:                }
0312:
0313:                try {
0314:                    AdminDPContext adc = getAdminDPContext();
0315:                    DPUNRegister dpUNRegister = new DPUNRegister(
0316:                            pconfProperties);
0317:                    dpUNRegister.process(adc, dn, global.booleanValue(),
0318:                            earAppName, verbose.booleanValue(), logger);
0319:                } catch (PortletDeployerException pde) {
0320:                    throw new PSMBeanException(MSG_PREFIX + pde.getKey(), pde
0321:                            .getCause(), pde.getTokens());
0322:                }
0323:            }
0324:
0325:            // END Portlet Registration methods
0326:
0327:            /**
0328:             * method to deploy all instances
0329:             */
0330:            public Boolean undeployAll(String dn, Boolean global,
0331:                    String warName, Boolean verbose, List instanceList,
0332:                    Boolean toContinue) throws PSMBeanException {
0333:                List instances = null;
0334:                Boolean undeployedAtAllInstances = new Boolean(true);
0335:                boolean isContinue = false;
0336:                if (instanceList == null) {
0337:                    try {
0338:                        instances = getInstanceNames(); //charlie_80, bullet_80, bullet_81, sprint_82, sprint_83
0339:                    } catch (Exception e) {
0340:                        logMessage("PSPL_CSPPAM0009",
0341:                                new String[] { psPortalID }, e);
0342:                        throw new PSMBeanException(MSG_PREFIX
0343:                                + "errorGettingPortalInstances",
0344:                                new String[] { psPortalID });
0345:                    }
0346:                } else {
0347:                    instances = instanceList; //comma separated instances entered at client
0348:                }
0349:
0350:                //if there is only one instance, we want to throw correct message at cli.
0351:                if (instances.size() > 1) {
0352:                    isContinue = toContinue.booleanValue();
0353:                }
0354:                List hostsList = getHostNames(instances); //hosts where these instances are installed
0355:                Iterator iter = hostsList.iterator();
0356:
0357:                //if portal instance is on local host
0358:                while (iter.hasNext()) {
0359:                    String hostName = (String) iter.next();
0360:                    try {
0361:                        if (AdminUtil.isLocal(hostName)) {
0362:                            //modifies dp and undeploys portal webapp from  all the instances on all the hosts .
0363:                            undeployedAtAllInstances = undeploy(dn, global,
0364:                                    warName, verbose, instances, new Boolean(
0365:                                            isContinue));
0366:                            return undeployedAtAllInstances;
0367:                        }
0368:                    } catch (UnknownHostException uhe) {
0369:                        logger.log(Level.SEVERE, "PSPL_CSPPAM0005", uhe);
0370:                        String[] tokens = { hostName };
0371:                        throw new PSMBeanException(MSG_PREFIX
0372:                                + "errorUnknownHost", tokens);
0373:                    }
0374:                }
0375:                //if portal instance is on remote host
0376:                iter = hostsList.iterator();
0377:                String[] signature = { "java.lang.String", "java.lang.Boolean",
0378:                        "java.lang.String", "java.lang.Boolean",
0379:                        "java.util.List", "java.lang.Boolean" };
0380:                Object[] params = { dn, global, warName, verbose, instances,
0381:                        new Boolean(isContinue) };
0382:                JMXConnector connector = null;
0383:                MBeanServerConnection mbsc = null;
0384:
0385:                while (iter.hasNext()) {
0386:                    //host is remote
0387:                    String hostName = (String) iter.next();
0388:                    try {
0389:                        connector = AdminServerUtil.getJMXConnector(hostName);
0390:                        mbsc = connector.getMBeanServerConnection();
0391:                    } catch (IOException ioe) {
0392:                        String[] tokens = { hostName };
0393:                        logMessage("PSPL_CSPPAM0010", tokens, ioe);
0394:                        if (!isContinue) {
0395:                            throw new PSMBeanException(MSG_PREFIX
0396:                                    + "errorConnectingToHost", tokens);
0397:                        }
0398:                        undeployedAtAllInstances = new Boolean(false);
0399:                        continue;
0400:                    }
0401:
0402:                    try {
0403:                        //modifies dp and undeploys portal webapp from  all the instances on all the hosts .
0404:                        undeployedAtAllInstances = (Boolean) mbsc.invoke(
0405:                                myName, "undeploy", params, signature);
0406:                        return undeployedAtAllInstances;
0407:                    } catch (MBeanException me) {
0408:                        String[] tokens = { warName, hostName };
0409:                        logMessage("PSPL_CSPPAM0014", tokens, me);
0410:                        if (!isContinue) {
0411:                            PSMBeanException pme = (PSMBeanException) me
0412:                                    .getTargetException();
0413:                            throw new PSMBeanException(pme.getErrorKey(), pme
0414:                                    .getTokens());
0415:                        }
0416:                        undeployedAtAllInstances = new Boolean(false);
0417:                        continue;
0418:                    } catch (Exception e) {
0419:                        String[] tokens = { warName, hostName };
0420:                        logMessage("PSPL_CSPPAM0013", tokens, e);
0421:                        if (!isContinue) {
0422:                            throw new PSMBeanException(MSG_PREFIX
0423:                                    + "errorUnDeploy", tokens);
0424:                        }
0425:                        undeployedAtAllInstances = new Boolean(false);
0426:                        continue;
0427:                    } finally {
0428:                        closeConnector(connector);
0429:                    }
0430:                }
0431:                return undeployedAtAllInstances;
0432:            }
0433:
0434:            /**
0435:             * method to deploy portlet
0436:             */
0437:            public Boolean deploy(String dn, Boolean global, String warFile,
0438:                    Properties roles, Properties userinfo, Boolean verbose,
0439:                    List instances, Boolean toContinue, Boolean nodeploy)
0440:                    throws PSMBeanException {
0441:                Boolean deployedAtAllInstances = new Boolean(true);
0442:                pconfProperties = getPortletConfigProperties();
0443:                if (pconfProperties == null) {
0444:                    throw new PSMBeanException(MSG_PREFIX + "errorConfigFile");
0445:                }
0446:                String[] filesModified = null;
0447:                try {
0448:                    AdminDPContext adc = getAdminDPContext();
0449:                    PDDeploy pddeploy = new PDDeploy(pconfProperties);
0450:                    filesModified = pddeploy.process(adc, dn, global
0451:                            .booleanValue(), new File(warFile), roles,
0452:                            userinfo, verbose.booleanValue(), logger);
0453:                    logger.log(Level.INFO, "PSPL_CSPPAM0003", warFile);
0454:
0455:                } catch (PortletDeployerException pde) {
0456:                    logger.log(Level.SEVERE, "PSPL_CSPPAM0004", pde);
0457:                    if (pde.getCause() != null) {
0458:                        throw new PSMBeanException(MSG_PREFIX + pde.getKey(),
0459:                                pde.getCause(), pde.getTokens());
0460:                    } else {
0461:                        throw new PSMBeanException(MSG_PREFIX + pde.getKey(),
0462:                                pde.getTokens());
0463:                    }
0464:                }
0465:                if (!nodeploy.booleanValue()) {
0466:                    deployedAtAllInstances = deployToContainer(filesModified,
0467:                            instances, toContinue.booleanValue());
0468:                }
0469:                return deployedAtAllInstances;
0470:            }
0471:
0472:            /**
0473:             * Method to deploy the war to container
0474:             */
0475:            private Boolean deployToContainer(String[] filesModified,
0476:                    List instances, boolean isContinue) throws PSMBeanException {
0477:
0478:                ObjectName mBeanName = null;
0479:                JMXConnector connector = null;
0480:                MBeanServerConnection mbsc = null;
0481:                Boolean deployedAtAllInstances = new Boolean(true);
0482:
0483:                //path here is domain.portal.PortletAdmin
0484:                //to create the parent path domain.portal
0485:                LinkedList instancePath = new LinkedList();
0486:                instancePath.addFirst(path.get(2)); //add domainId
0487:                instancePath.addFirst(path.get(1)); //portalId
0488:
0489:                List hostsList = getHostNames(instances); //hosts where these instances are installed
0490:                Iterator iter = hostsList.iterator();
0491:                String[] signature = { "java.lang.String" };
0492:                String dd = filesModified[0];
0493:                String warFile = filesModified[1];
0494:                //for each host
0495:                while (iter.hasNext()) {
0496:                    String hostName = (String) iter.next();
0497:                    List instancesOnThisHost = getInstancesOnHost(hostName,
0498:                            instances);
0499:                    try {
0500:                        if (AdminServerUtil.isLocal(hostName)) {
0501:                            mbsc = PASModule.getMBeanServer();
0502:                        } else {
0503:                            closeConnector(connector);
0504:                            connector = AdminServerUtil
0505:                                    .getJMXConnector(hostName);
0506:                            mbsc = connector.getMBeanServerConnection();
0507:                            try {
0508:                                //upload war file to this host and get the absolute filename of uploaded war file.
0509:                                String[] warFileId = AdminClientUtil
0510:                                        .uploadFile(mbsc, psDomainID, new File(
0511:                                                warFile), 0);
0512:                                //upload dd  to this host and get the absolute filename of uploaded dd
0513:                                String[] ddId = AdminClientUtil.uploadFile(
0514:                                        mbsc, psDomainID, new File(dd), 0);
0515:                                dd = ddId[1];
0516:                                warFile = warFileId[1];
0517:
0518:                                //copy the uploaded war  to war location
0519:                                String destFileName = getFullyQualifiedDestinationFileName(
0520:                                        warFile, WAR_SUFFIX);
0521:                                Object params1[] = { warFile, destFileName };
0522:                                String signature1[] = { "java.lang.String",
0523:                                        "java.lang.String" };
0524:                                mbsc.invoke(myName, "copyFile", params1,
0525:                                        signature1);
0526:
0527:                                //copy the uploaded dd  to war location : required in undeploy
0528:                                destFileName = getFullyQualifiedDestinationFileName(
0529:                                        dd, DD_SUFFIX);
0530:                                Object params2[] = { dd, destFileName };
0531:                                String signature2[] = { "java.lang.String",
0532:                                        "java.lang.String" };
0533:                                mbsc.invoke(myName, "copyFile", params2,
0534:                                        signature2);
0535:                                //do temporary files cleanup
0536:                                try {
0537:                                    AdminClientUtil.uploadDownloadCleanUp(mbsc,
0538:                                            psDomainID, warFileId[0]);
0539:                                    AdminClientUtil.uploadDownloadCleanUp(mbsc,
0540:                                            psDomainID, ddId[0]);
0541:                                } catch (UploadDownloadException upe) {
0542:                                    ;
0543:                                }
0544:                            } catch (Exception e) {
0545:                                String[] tokens = { warFile + "," + dd,
0546:                                        hostName };
0547:                                logMessage("PSPL_CSPPAM0012", tokens, e);
0548:                                closeConnector(connector);
0549:                                if (!isContinue) {
0550:                                    throw new PSMBeanException(MSG_PREFIX
0551:                                            + "errorUploadingToHost", tokens);
0552:                                }
0553:                                //iterate for next host
0554:                                deployedAtAllInstances = new Boolean(false);
0555:                                continue;
0556:                            }
0557:                        }
0558:                    } catch (UnknownHostException uhe) {
0559:                        logger.log(Level.SEVERE, "PSPL_CSPPAM0005", uhe);
0560:                        String[] tokens = { warFile + "," + dd, hostName };
0561:                        logger.log(Level.SEVERE, "PSPL_CSPPAM0012", tokens);
0562:                        if (!isContinue) {
0563:                            throw new PSMBeanException(MSG_PREFIX
0564:                                    + "errorUnknownHost");
0565:                        }
0566:                        deployedAtAllInstances = new Boolean(false);
0567:                        continue;
0568:                    } catch (IOException ioe) {
0569:                        String[] tokens = { hostName };
0570:                        logMessage("PSPL_CSPPAM0010", tokens, ioe);
0571:                        tokens[0] = warFile + "," + dd;
0572:                        tokens[1] = hostName;
0573:                        logger.log(Level.SEVERE, "PSPL_CSPPAM0012", tokens);
0574:                        closeConnector(connector);
0575:                        if (!isContinue) {
0576:                            throw new PSMBeanException(MSG_PREFIX
0577:                                    + "errorConnectingToHost", tokens);
0578:                        }
0579:                        //iterate  for next host
0580:                        deployedAtAllInstances = new Boolean(false);
0581:                        continue;
0582:                    }
0583:
0584:                    String warFileURI = warFile.substring(warFile
0585:                            .lastIndexOf(File.separator), warFile.length());
0586:                    warFileURI = warFileURI.substring(0, warFileURI
0587:                            .indexOf(WAR_SUFFIX));
0588:                    if (isWinOS()) {
0589:                        try {
0590:                            warFileURI = warFileURI.replace('\\', '/');
0591:                        } catch (Exception e) {
0592:                        }
0593:                    }
0594:                    Object params[] = { warFileURI };
0595:                    Iterator instIter = instancesOnThisHost.iterator();
0596:                    String instanceName = null;
0597:                    //for each instance on this host
0598:                    while (instIter.hasNext()) {
0599:                        try {
0600:                            instanceName = (String) instIter.next();
0601:                            mBeanName = AdminUtil.getResourceMBeanObjectName(
0602:                                    PortalServerInstanceMBean.TYPE, AdminUtil
0603:                                            .getChildPath(instancePath,
0604:                                                    instanceName));
0605:                            if (!mbsc.isRegistered(mBeanName)) {
0606:                                String[] tokens = { warFile, instanceName,
0607:                                        hostName };
0608:                                logger.log(Level.SEVERE, "PSPL_CSPPAM0013",
0609:                                        tokens);
0610:                                String tokens1[] = { instanceName };
0611:                                if (!isContinue) {
0612:                                    closeConnector(connector);
0613:                                    throw new PSMBeanException(MSG_PREFIX
0614:                                            + "errorIncorrectInstance", tokens1);
0615:                                }
0616:                                deployedAtAllInstances = new Boolean(false);
0617:                                continue;
0618:                            }
0619:                            if (logger.isLoggable(Level.INFO)) {
0620:                                Object tokens[] = new Object[2];
0621:                                tokens[0] = warFile;
0622:                                tokens[1] = instanceName;
0623:                                logger.log(Level.INFO, "PSPL_CSPPAM0006",
0624:                                        tokens);
0625:                            }
0626:                            mbsc.invoke(mBeanName, "deploy", params, signature);
0627:                        } catch (Exception e) {
0628:                            String[] tokens = { warFile, instanceName, hostName };
0629:                            logMessage("PSPL_CSPPAM0013", tokens, e);
0630:                            if (!isContinue) {
0631:                                closeConnector(connector);
0632:                                throw new PSMBeanException(MSG_PREFIX
0633:                                        + "errorDeployOnInstance", tokens);
0634:                            }
0635:                            deployedAtAllInstances = new Boolean(false);
0636:                            continue;
0637:                        }
0638:                    }
0639:                }
0640:                closeConnector(connector);
0641:                return deployedAtAllInstances;
0642:
0643:            }
0644:
0645:            /**
0646:             * method to undeploy portlet
0647:             */
0648:            public Boolean undeploy(String dn, Boolean global, String warName,
0649:                    Boolean verbose, List instances, Boolean toContinue)
0650:                    throws PSMBeanException {
0651:                Boolean undeployedAtAllInstances = new Boolean(true);
0652:                pconfProperties = getPortletConfigProperties();
0653:                if (pconfProperties == null) {
0654:                    throw new PSMBeanException(MSG_PREFIX + "errorConfigFile");
0655:                }
0656:
0657:                try {
0658:                    AdminDPContext adc = getAdminDPContext();
0659:                    //modify dp.
0660:                    PDUNDeploy pdundeploy = new PDUNDeploy(pconfProperties);
0661:                    pdundeploy.process(adc, dn, global.booleanValue(), warName,
0662:                            verbose.booleanValue(), logger);
0663:                } catch (PortletDeployerException pde) {
0664:                    logger.log(Level.SEVERE, "PSPL_CSPPAM0004", pde);
0665:                    if (pde.getCause() != null) {
0666:                        throw new PSMBeanException(MSG_PREFIX + pde.getKey(),
0667:                                pde.getCause(), pde.getTokens());
0668:                    } else {
0669:                        throw new PSMBeanException(MSG_PREFIX + pde.getKey(),
0670:                                pde.getTokens());
0671:                    }
0672:                }
0673:                undeployedAtAllInstances = undeployFromContainer(warName,
0674:                        instances, toContinue.booleanValue());
0675:                return undeployedAtAllInstances;
0676:            }
0677:
0678:            /**
0679:             * Method to deploy the war to container
0680:             */
0681:            private Boolean undeployFromContainer(String warName,
0682:                    List instances, boolean isContinue) throws PSMBeanException {
0683:
0684:                ObjectName mBeanName = null;
0685:                JMXConnector connector = null;
0686:                MBeanServerConnection mbsc = null;
0687:                Boolean undeployedAtAllInstances = new Boolean(true);
0688:
0689:                //path here is domain.portal.PortletAdmin
0690:                //to create the parent path domain.portal
0691:                LinkedList instancePath = new LinkedList();
0692:                instancePath.addFirst(path.get(2)); //add domainId
0693:                instancePath.addFirst(path.get(1)); //portalId
0694:
0695:                List hostsList = getHostNames(instances); //hosts where these instances are installed
0696:                Iterator iter = hostsList.iterator();
0697:                String[] signature = { "java.lang.String" };
0698:                Object[] params = { fs + warName };
0699:
0700:                while (iter.hasNext()) {
0701:                    String hostName = (String) iter.next();
0702:                    List instancesOnThisHost = getInstancesOnHost(hostName,
0703:                            instances);
0704:                    try {
0705:                        if (AdminServerUtil.isLocal(hostName)) {
0706:                            mbsc = PASModule.getMBeanServer();
0707:                        } else {
0708:                            //close existing connector
0709:                            closeConnector(connector);
0710:                            connector = AdminServerUtil
0711:                                    .getJMXConnector(hostName);
0712:                            mbsc = connector.getMBeanServerConnection();
0713:                        }
0714:                    } catch (UnknownHostException uhe) {
0715:                        logger.log(Level.SEVERE, "PSPL_CSPPAM0005", uhe);
0716:                        String[] tokens = { warName, hostName };
0717:                        logger.log(Level.SEVERE, "PSPL_CSPPAM0014", tokens);
0718:                        if (!isContinue) {
0719:                            throw new PSMBeanException(MSG_PREFIX
0720:                                    + "errorUnknownHost");
0721:                        }
0722:                        //iterate  for next host
0723:                        undeployedAtAllInstances = new Boolean(false);
0724:                        continue;
0725:
0726:                    } catch (IOException ioe) {
0727:                        String[] tokens = { hostName };
0728:                        logMessage("PSPL_CSPPAM0010", tokens, ioe);
0729:                        tokens[0] = warName;
0730:                        tokens[1] = hostName;
0731:                        logger.log(Level.SEVERE, "PSPL_CSPPAM0014", tokens);
0732:                        closeConnector(connector);
0733:                        if (!isContinue) {
0734:                            throw new PSMBeanException(MSG_PREFIX
0735:                                    + "errorConnectingToHost", tokens);
0736:                        }
0737:                        //iterate  for next host
0738:                        undeployedAtAllInstances = new Boolean(false);
0739:                        continue;
0740:                    }
0741:                    Iterator instIter = instancesOnThisHost.iterator();
0742:                    String instanceName = null;
0743:                    //for each instance on this host
0744:                    while (instIter.hasNext()) {
0745:                        try {
0746:                            instanceName = (String) instIter.next();
0747:                            mBeanName = AdminUtil.getResourceMBeanObjectName(
0748:                                    PortalServerInstanceMBean.TYPE, AdminUtil
0749:                                            .getChildPath(instancePath,
0750:                                                    instanceName));
0751:                            if (!mbsc.isRegistered(mBeanName)) {
0752:                                String[] tokens = { warName, hostName,
0753:                                        instanceName };
0754:                                logger.log(Level.SEVERE, "PSPL_CSPPAM0015",
0755:                                        tokens);
0756:                                String tokens1[] = { instanceName };
0757:                                if (!isContinue) {
0758:                                    closeConnector(connector);
0759:                                    throw new PSMBeanException(MSG_PREFIX
0760:                                            + "errorIncorrectInstance", tokens1);
0761:                                }
0762:                                undeployedAtAllInstances = new Boolean(false);
0763:                                continue;
0764:                            }
0765:                            if (logger.isLoggable(Level.INFO)) {
0766:                                Object tokens[] = new Object[2];
0767:                                tokens[0] = warName;
0768:                                tokens[1] = instanceName;
0769:                                logger.log(Level.INFO, "PSPL_CSPPAM0008",
0770:                                        tokens);
0771:                            }
0772:                            mbsc.invoke(mBeanName, "undeploy", params,
0773:                                    signature);
0774:                        } catch (Exception e) {
0775:                            String[] tokens = { warName, instanceName, hostName };
0776:                            logMessage("PSPL_CSPPAM0015", tokens, e);
0777:                            if (!isContinue) {
0778:                                closeConnector(connector);
0779:                                throw new PSMBeanException(MSG_PREFIX
0780:                                        + "errorUnDeployFromInstance", tokens);
0781:                            }
0782:                            //iterate for next instance
0783:                            undeployedAtAllInstances = new Boolean(false);
0784:                            continue;
0785:                        }
0786:                    }
0787:                }
0788:                closeConnector(connector);
0789:                return undeployedAtAllInstances;
0790:
0791:            }
0792:
0793:            private void closeConnector(JMXConnector connector) {
0794:                if (connector != null) {
0795:                    try {
0796:                        connector.close();
0797:                    } catch (Exception e) {
0798:                        String message = "Can't close JMX connector";
0799:                        logger.log(Level.WARNING, message, e);
0800:                    }
0801:                }
0802:            }
0803:
0804:            private void logMessage(String msgId, Object[] tokens, Exception e) {
0805:                LogRecord logRecord = new LogRecord(Level.SEVERE, msgId);
0806:                logRecord.setParameters(tokens);
0807:                logRecord.setThrown(e);
0808:                logRecord.setLoggerName(logger.getName());
0809:                logger.log(logRecord);
0810:            }
0811:
0812:            private String getFullyQualifiedDestinationFileName(
0813:                    String filePath, String ext) {
0814:                String fileName = new File(filePath).getName();
0815:                fileName = fileName.substring(0, fileName.indexOf(".")) + ext;
0816:                fileName = pconfProperties.getProperty(DD_LOCATION)
0817:                        + File.separator + fileName;
0818:                return fileName;
0819:
0820:            }
0821:
0822:            /**
0823:             * Method to copy a file from a source to a
0824:             * destination specifying if
0825:             * source files may overwrite newer destination files and the
0826:             * last modified time of <code>destFile</code> file should be made equal
0827:             * to the last modified time of <code>sourceFile</code>.
0828:             *
0829:             * @throws PSMBeanException
0830:             */
0831:            public void copyFile(String sourceFileName, String destFileName)
0832:                    throws PSMBeanException {
0833:                try {
0834:
0835:                    File sourceFile = new File(sourceFileName);
0836:                    File destFile = new File(destFileName);
0837:
0838:                    if (!destFile.exists()
0839:                            || destFile.lastModified() < sourceFile
0840:                                    .lastModified()) {
0841:
0842:                        if (destFile.exists() && destFile.isFile()) {
0843:                            destFile.delete();
0844:                        }
0845:
0846:                        // ensure that parent dir of dest file exists!
0847:                        File parent = new File(destFile.getParent());
0848:                        if (!parent.exists()) {
0849:                            parent.mkdirs();
0850:                        }
0851:
0852:                        FileInputStream in = new FileInputStream(sourceFile);
0853:                        FileOutputStream out = new FileOutputStream(destFile);
0854:
0855:                        byte[] buffer = new byte[8 * 1024];
0856:                        int count = 0;
0857:                        do {
0858:                            out.write(buffer, 0, count);
0859:                            count = in.read(buffer, 0, buffer.length);
0860:                        } while (count != -1);
0861:
0862:                        in.close();
0863:                        out.close();
0864:
0865:                    }
0866:                } catch (IOException ioe) {
0867:                    logger.log(Level.SEVERE, "PSPL_CSPPAM0005", ioe);
0868:                    throw new PSMBeanException(MSG_PREFIX
0869:                            + "errorInCopyingFile");
0870:                }
0871:            }
0872:
0873:            public void copyModifiedPortletWar(String tempLocation) {
0874:                String newLocation = getPortletConfigProperties().getProperty(
0875:                        DD_LOCATION);
0876:            }
0877:
0878:            //below methods are only for accessing portlet specific dp
0879:            public void createPortletChannel(String baseDN, String channelName,
0880:                    String portletName) throws PSMBeanException {
0881:                try {
0882:                    PortletTaskAdmin pta = new PortletTaskAdmin(AdminServerUtil
0883:                            .getSSOToken(), baseDN, psPortalID);
0884:                    pta.createPortletChannel(channelName, portletName);
0885:                    pta.store();
0886:                } catch (TaskAdminException tae) {
0887:                    logger.log(Level.SEVERE, "PSDT_CSPDAMB0008", tae);
0888:                    throw new PSMBeanException("desktop." + tae.getErrorKey(),
0889:                            tae.getMessage(), tae.getTokens());
0890:                }
0891:            }
0892:
0893:            public Set getExistingPortlets(String baseDN)
0894:                    throws PSMBeanException {
0895:                Set portlets = null;
0896:                try {
0897:                    PortletTaskAdmin pta = new PortletTaskAdmin(AdminServerUtil
0898:                            .getSSOToken(), baseDN, psPortalID);
0899:                    portlets = pta.getExistingPortlets();
0900:                } catch (TaskAdminException tae) {
0901:                    logger.log(Level.SEVERE, "PSDT_CSPDAMB0008", tae);
0902:                    throw new PSMBeanException("desktop." + tae.getErrorKey(),
0903:                            tae.getMessage(), tae.getTokens());
0904:                }
0905:                return portlets;
0906:            }
0907:
0908:            public Set getPortletPreferenceNames(String baseDN,
0909:                    String portletName) throws PSMBeanException {
0910:                Set portletPrefs = null;
0911:                try {
0912:                    PortletTaskAdmin pta = new PortletTaskAdmin(AdminServerUtil
0913:                            .getSSOToken(), baseDN, psPortalID);
0914:                    portletPrefs = pta.getPortletPreferenceNames(portletName);
0915:                } catch (TaskAdminException tae) {
0916:                    logger.log(Level.SEVERE, "PSDT_CSPDAMB0008", tae);
0917:                    throw new PSMBeanException(" ");
0918:                }
0919:                return portletPrefs;
0920:            }
0921:
0922:            public String getPortletPreference(String baseDN,
0923:                    String portletName, String prefName)
0924:                    throws PSMBeanException {
0925:                String portletPref = null;
0926:                try {
0927:                    PortletTaskAdmin pta = new PortletTaskAdmin(AdminServerUtil
0928:                            .getSSOToken(), baseDN, psPortalID);
0929:                    portletPref = pta.getPortletPreferenceStringValue(
0930:                            portletName, prefName);
0931:                } catch (TaskAdminException tae) {
0932:                    logger.log(Level.SEVERE, "PSDT_CSPDAMB0008", tae);
0933:                    throw new PSMBeanException(" ");
0934:                }
0935:                return portletPref;
0936:            }
0937:
0938:            public List getPortletPreferenceValues(String baseDN,
0939:                    String portletName, String prefName)
0940:                    throws PSMBeanException {
0941:                List portletPrefs = null;
0942:                try {
0943:                    PortletTaskAdmin pta = new PortletTaskAdmin(AdminServerUtil
0944:                            .getSSOToken(), baseDN, psPortalID);
0945:                    portletPrefs = pta.getPortletPreferenceValues(portletName,
0946:                            prefName);
0947:                } catch (TaskAdminException tae) {
0948:                    logger.log(Level.SEVERE, "PSDT_CSPDAMB0008", tae);
0949:                    throw new PSMBeanException(" ");
0950:                }
0951:                return portletPrefs;
0952:            }
0953:
0954:            public void setPortletPreference(String baseDN, String portletName,
0955:                    String prefName, String value) throws PSMBeanException {
0956:                try {
0957:                    PortletTaskAdmin pta = new PortletTaskAdmin(AdminServerUtil
0958:                            .getSSOToken(), baseDN, psPortalID);
0959:                    pta.setPortletPreferenceStringValue(portletName, prefName,
0960:                            value);
0961:                    pta.store();
0962:                } catch (TaskAdminException tae) {
0963:                    logger.log(Level.SEVERE, "PSDT_CSPDAMB0008", tae);
0964:                    throw new PSMBeanException(" ");
0965:                }
0966:            }
0967:
0968:            public void setPortletPreferenceValues(String baseDN,
0969:                    String portletName, String prefName, String[] values)
0970:                    throws PSMBeanException {
0971:                try {
0972:                    PortletTaskAdmin pta = new PortletTaskAdmin(AdminServerUtil
0973:                            .getSSOToken(), baseDN, psPortalID);
0974:                    pta.setPortletPreferenceValues(portletName, prefName,
0975:                            values);
0976:                    pta.store();
0977:                } catch (TaskAdminException tae) {
0978:                    logger.log(Level.SEVERE, "PSDT_CSPDAMB0008", tae);
0979:                    throw new PSMBeanException(" ");
0980:                }
0981:            }
0982:
0983:            public Boolean isPortletChannel(String baseDN, String channelName)
0984:                    throws PSMBeanException {
0985:                boolean isPortlet = false;
0986:                try {
0987:                    PortletTaskAdmin pta = new PortletTaskAdmin(AdminServerUtil
0988:                            .getSSOToken(), baseDN, psPortalID);
0989:                    isPortlet = pta.isPortletChannel(channelName);
0990:                } catch (TaskAdminException tae) {
0991:                    logger.log(Level.SEVERE, "PSDT_CSPDAMB0008", tae);
0992:                    throw new PSMBeanException("tae");
0993:                }
0994:                return new Boolean(isPortlet);
0995:            }
0996:
0997:            public Map getPortletPreferenceMap(String baseDN, String portletName)
0998:                    throws PSMBeanException {
0999:                Map prefMap = new HashMap();
1000:                try {
1001:                    PortletTaskAdmin pta = new PortletTaskAdmin(AdminServerUtil
1002:                            .getSSOToken(), baseDN, psPortalID);
1003:                    prefMap = pta.getPortletPreferenceMap(portletName);
1004:                } catch (TaskAdminException tae) {
1005:                    logger.log(Level.SEVERE, "PSDT_CSPDAMB0008", tae);
1006:                    throw new PSMBeanException("tae");
1007:                }
1008:                return prefMap;
1009:            }
1010:
1011:            //to get all the instance object names for  a portal
1012:            private Set getInstanceObjectNames(String portalId)
1013:                    throws IOException, Exception {
1014:                ObjectName instancePat = AdminClientUtil
1015:                        .getPortalServerInstancesPattern(
1016:                                AdminClientUtil.DEFAULT_DOMAIN, portalId);
1017:                MBeanServer mbs = PASModule.getMBeanServer();
1018:                Set objNames = mbs.queryNames(instancePat, null);
1019:                return objNames;
1020:            }
1021:
1022:            //to get all instance names for a portal
1023:            private List getInstanceNames() throws Exception {
1024:                List iNames = new ArrayList();
1025:                Set objNames = getInstanceObjectNames(psPortalID);
1026:                Iterator iter = objNames.iterator();
1027:                while (iter.hasNext()) {
1028:                    iNames.add(((ObjectName) iter.next())
1029:                            .getKeyProperty("name"));
1030:                }
1031:                return iNames;
1032:            }
1033:
1034:            //get a list of hosts where these portal instances are installed.
1035:            /*private List getHostNames(List instanceNames){
1036:                List hostNames = new ArrayList();
1037:                Iterator iter = instanceNames.iterator();
1038:                String instanceName = null;
1039:                 int  index = 0;
1040:                while (iter.hasNext()){
1041:                    instanceName =  (String)iter.next();
1042:                    index = instanceName.indexOf(HOST_INSTANCE_SEPARATOR);
1043:                    String host = instanceName.substring(0,index);
1044:                    if (!(hostNames.contains(host))){
1045:                        hostNames.add(host);
1046:                    }
1047:                }
1048:                return hostNames;
1049:            } */
1050:
1051:            private Set getInstanceObjectNamesForInstances(Set instanceObjs,
1052:                    List instanceNames) {
1053:                Set instanceObjects = null;
1054:                if (instanceNames == null) {
1055:                    instanceObjects = instanceObjs;
1056:                } else {
1057:                    instanceObjects = new HashSet();
1058:                    ObjectName objectName = null;
1059:                    String instanceName = null;
1060:                    for (Iterator i = instanceNames.iterator(); i.hasNext();) {
1061:                        instanceName = (String) i.next();
1062:                        for (Iterator j = instanceObjs.iterator(); j.hasNext();) {
1063:                            objectName = (ObjectName) j.next();
1064:                            if (objectName.getKeyProperty("name")
1065:                                    .equalsIgnoreCase(instanceName)) {
1066:                                instanceObjects.add((ObjectName) objectName);
1067:                            }
1068:                        }
1069:                    }
1070:                }
1071:                return instanceObjects;
1072:            };
1073:
1074:            private List getHostNames(List instanceNames)
1075:                    throws PSMBeanException {
1076:                List hostNames = new ArrayList();
1077:                JMXConnector connector = null;
1078:                MBeanServerConnection mbsc = null;
1079:                Set instanceObjs = null;
1080:                try {
1081:                    connector = AdminServerUtil.getJMXConnector("localhost");
1082:                    mbsc = connector.getMBeanServerConnection();
1083:                    instanceObjs = getInstanceObjectNamesForInstances(
1084:                            getInstanceObjectNames(psPortalID), instanceNames);
1085:                    if (instanceObjs.isEmpty()) {
1086:                        throw new Exception("");
1087:                    }
1088:                    //get the hosts for these instances
1089:                    for (Iterator j = instanceObjs.iterator(); j.hasNext();) {
1090:                        ObjectName iObj = (ObjectName) j.next();
1091:                        String host = (String) mbsc.getAttribute(iObj, "Host");
1092:                        if (!(hostNames.contains(host))) {
1093:                            hostNames.add(host);
1094:                        }
1095:                    }
1096:                } catch (IOException ioe) {
1097:                    String[] tokens = { "localhost" };
1098:                    logMessage("PSPL_CSPPAM0010", tokens, ioe);
1099:                } catch (Exception e) {
1100:                    throw new PSMBeanException(MSG_PREFIX
1101:                            + "errorGettingPortalInstances",
1102:                            new String[] { psPortalID });
1103:                }
1104:                return hostNames;
1105:            }
1106:
1107:            //get a list of instances for this host.
1108:            private List getInstancesOnHost(String hostName, List instanceNames)
1109:                    throws PSMBeanException {
1110:                List instances = new ArrayList();
1111:                JMXConnector connector = null;
1112:                MBeanServerConnection mbsc = null;
1113:                try {
1114:                    connector = AdminServerUtil.getJMXConnector("localhost");
1115:                    mbsc = connector.getMBeanServerConnection();
1116:                    Set instanceObjs = getInstanceObjectNamesForInstances(
1117:                            getInstanceObjectNames(psPortalID), instanceNames);
1118:                    Iterator iter = instanceObjs.iterator();
1119:                    while (iter.hasNext()) {
1120:                        ObjectName iObj = (ObjectName) iter.next();
1121:                        String host = (String) mbsc.getAttribute(iObj, "Host");
1122:                        if (host.equals(hostName)) {
1123:                            instances.add(iObj.getKeyProperty("name"));
1124:                        }
1125:                    }
1126:                } catch (IOException ioe) {
1127:                    String[] tokens = { "localhost" };
1128:                    logMessage("PSPL_CSPPAM0010", tokens, ioe);
1129:                } catch (Exception e) {
1130:                    throw new PSMBeanException(MSG_PREFIX
1131:                            + "errorGettingPortalInstances",
1132:                            new String[] { psPortalID });
1133:                }
1134:                return instances;
1135:            }
1136:
1137:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.