Source Code Cross Referenced for JBIApplicationVerifier.java in  » ESB » open-esb » com » sun » jbi » ui » runtime » verifier » 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 » ESB » open esb » com.sun.jbi.ui.runtime.verifier 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * BEGIN_HEADER - DO NOT EDIT
0003:         *
0004:         * The contents of this file are subject to the terms
0005:         * of the Common Development and Distribution License
0006:         * (the "License").  You may not use this file except
0007:         * in compliance with the License.
0008:         *
0009:         * You can obtain a copy of the license at
0010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0011:         * See the License for the specific language governing
0012:         * permissions and limitations under the License.
0013:         *
0014:         * When distributing Covered Code, include this CDDL
0015:         * HEADER in each file and include the License file at
0016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
0017:         * If applicable add the following below this CDDL HEADER,
0018:         * with the fields enclosed by brackets "[]" replaced with
0019:         * your own identifying information: Portions Copyright
0020:         * [year] [name of copyright owner]
0021:         */
0022:
0023:        /*
0024:         * @(#)JBIApplicationVerifier.java
0025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
0026:         *
0027:         * END_HEADER - DO NOT EDIT
0028:         */
0029:        package com.sun.jbi.ui.runtime.verifier;
0030:
0031:        import java.io.File;
0032:        import java.io.IOException;
0033:        import java.util.List;
0034:        import java.util.logging.Level;
0035:        import java.util.Map;
0036:        import java.util.ArrayList;
0037:        import java.util.HashMap;
0038:        import java.util.Iterator;
0039:        import java.util.Properties;
0040:        import java.util.Set;
0041:        import javax.management.InstanceNotFoundException;
0042:        import javax.management.MBeanException;
0043:        import javax.management.MBeanServer;
0044:        import javax.management.AttributeNotFoundException;
0045:        import javax.management.MalformedObjectNameException;
0046:        import javax.management.ObjectName;
0047:        import javax.management.ReflectionException;
0048:        import javax.management.RuntimeMBeanException;
0049:        import javax.management.RuntimeOperationsException;
0050:        import javax.management.openmbean.TabularData;
0051:        import javax.management.openmbean.ArrayType;
0052:        import javax.management.openmbean.CompositeData;
0053:        import javax.management.openmbean.CompositeDataSupport;
0054:        import javax.management.openmbean.CompositeType;
0055:        import javax.management.openmbean.OpenType;
0056:        import javax.management.openmbean.OpenDataException;
0057:        import javax.management.openmbean.SimpleType;
0058:        import javax.management.openmbean.TabularType;
0059:        import javax.management.openmbean.TabularDataSupport;
0060:
0061:        import com.sun.jbi.ui.common.JBIJMXObjectNames;
0062:        import com.sun.jbi.ComponentType;
0063:        import com.sun.jbi.ComponentQuery;
0064:        import com.sun.jbi.ComponentState;
0065:        import com.sun.jbi.EnvironmentContext;
0066:        import com.sun.jbi.ComponentInfo;
0067:        import com.sun.jbi.ServiceAssemblyQuery;
0068:        import com.sun.jbi.ServiceAssemblyInfo;
0069:        import com.sun.jbi.ServiceUnitInfo;
0070:        import com.sun.jbi.management.MBeanNames.ComponentServiceType;
0071:        import com.sun.jbi.management.MBeanNames;
0072:        import com.sun.jbi.management.MBeanNames.ServiceName;
0073:        import com.sun.jbi.management.MBeanNames.ServiceType;
0074:        import com.sun.jbi.ui.common.JBIArchive;
0075:        import com.sun.jbi.ui.common.JBIRemoteException;
0076:        import com.sun.jbi.ui.common.ServiceAssemblyDD;
0077:        import com.sun.jbi.ui.common.ToolsLogManager;
0078:        import com.sun.jbi.ui.common.I18NBundle;
0079:        import com.sun.jbi.ui.runtime.verifier.util.TemplateGenerator;
0080:        import com.sun.jbi.ui.runtime.verifier.util.VerifierUtils;
0081:        import com.sun.jbi.util.ComponentConfigurationHelper;
0082:
0083:        /**
0084:         * This class implements JBI Application Verification functionality.
0085:         */
0086:        public class JBIApplicationVerifier {
0087:
0088:            /**
0089:             * Environment Context
0090:             */
0091:            private EnvironmentContext mEnvCtx;
0092:
0093:            /**
0094:             * ResourceBundle Context
0095:             */
0096:            private I18NBundle mResourceBundle;
0097:
0098:            /**
0099:             * tmp dir
0100:             */
0101:            private String mTmpDir;
0102:
0103:            /**
0104:             * target
0105:             */
0106:            private String mTarget;
0107:
0108:            /**
0109:             * list of components that were started
0110:             */
0111:            private List<String> mStartedComponents = new ArrayList();
0112:
0113:            /**
0114:             * list of components that are not installed
0115:             */
0116:            private List<String> mMissingComponents = new ArrayList();
0117:
0118:            /**
0119:             * Utility class
0120:             */
0121:            private VerifierUtils mVerifierUtil;
0122:
0123:            /**equal */
0124:            private static final String EQUAL = "=";
0125:
0126:            /** colon */
0127:            private static final String COLON = ":";
0128:
0129:            /** comma */
0130:            private static final String COMMA = ",";
0131:
0132:            /** JavaEEServiceEngine component name */
0133:            private static final String JAVAEE_SERVICE_ENGINE = "sun-javaee-engine";
0134:
0135:            /** Service Name for JavaEE Verifier MBean */
0136:            private static final String JAVAEE_VERIFIER = "JavaEEVerifier";
0137:
0138:            /**
0139:             * indicates if templates have to be generated
0140:             */
0141:            private boolean mGenerateTemplates = false;
0142:
0143:            /**
0144:             * indiacates if deploy command has to be included
0145:             */
0146:            private boolean mIncludeDeployCommand = false;
0147:
0148:            /**
0149:             * map of component name and list of unresolved app. vars
0150:             */
0151:            private Map<String, List<String>> mAppVarTemplatesMap = new HashMap<String, List<String>>();
0152:
0153:            /**
0154:             * map of component name and composite type of unresolved app. config
0155:             */
0156:            private Map<String, List<String>> mAppConfigTemplatesMap = new HashMap<String, List<String>>();
0157:
0158:            /**
0159:             * this map is used to store the composite type of the application configuration of 
0160:             * a component
0161:             */
0162:            private Map<String, CompositeType> mAppConfigTypeMap = new HashMap<String, CompositeType>();
0163:
0164:            /** 
0165:             * this map is used to store component names mapped to a map of app. var names and
0166:             *  and app. var values.
0167:             */
0168:            private Map<String, Map<String, Object>> mAppVarValuesMap;
0169:
0170:            /** 
0171:             * this map is used to store component names mapped to a map of app. config names and
0172:             *  and app. config values.
0173:             */
0174:
0175:            private Map<String, Map<String, Properties>> mAppConfigValuesMap;
0176:
0177:            /**
0178:             * location of the sa store in DAS repository
0179:             */
0180:            private String REPOSITORY_SA_STORE = "jbi" + File.separator
0181:                    + "service-assemblies";
0182:
0183:            /**
0184:             * MBeanNames
0185:             */
0186:            private MBeanNames mBeanNames = null;
0187:
0188:            /**
0189:             * template dir suffix
0190:             */
0191:            private static String TEMPLATE_DIR_SUFFIX = "-templates";
0192:
0193:            /**
0194:             * EndpointInfo CompositeType items
0195:             */
0196:
0197:            static String[] ENDPOINT_DATA_ITEM_NAMES = { "EndpointName",
0198:                    "ServiceUnitName", "ComponentName", "Status",
0199:                    "MissingApplicationVariables",
0200:                    "MissingApplicationConfigurations" };
0201:
0202:            /**
0203:             * EndpointInfo CompositeType descriptions
0204:             */
0205:            static String[] ENDPOINT_DATA_ITEM_DESCRIPTIONS = {
0206:                    "Endpoint Name", "Service Unit Name", "Component Name",
0207:                    "Status of the endpoint",
0208:                    "List of missing application variables",
0209:                    "List of missing application configurations"
0210:
0211:            };
0212:
0213:            /**
0214:             * JavaEE Verifier report item names
0215:             */
0216:            static String[] JAVAEE_VERIFIER_ITEM_NAMES = new String[] {
0217:                    "ServiceUnitName", "JavaEEVerifierReport" };
0218:
0219:            static String[] JAVAEE_VERIFIER_ITEM_DESCRIPTIONS = new String[] {
0220:                    "Service Unit Name", "JavaEE Verification Report" };
0221:
0222:            /** status string for unresolved SAs */
0223:            static String STATUS_UNRESOLVED = "UNRESOLVED";
0224:
0225:            /** status string for resolved SAs */
0226:            static String STATUS_RESOLVED = "RESOLVED";
0227:
0228:            /** status unknown for endpoint corresponding to components that are not installed / could not be started*/
0229:            static String STATUS_UNKNOWN = "UNKNOWN";
0230:
0231:            /**
0232:             * Constructs an instance of JBIApplicationVerifier
0233:             * @param envCtx EnvironmentContext
0234:             */
0235:            public JBIApplicationVerifier(EnvironmentContext envCtx) {
0236:                mEnvCtx = envCtx;
0237:                mResourceBundle = new I18NBundle(
0238:                        "com.sun.jbi.ui.runtime.verifier");
0239:                mTmpDir = envCtx.getJbiInstanceRoot() + File.separator + "tmp"
0240:                        + File.separator + "verifier";
0241:                mVerifierUtil = new VerifierUtils(mResourceBundle);
0242:                mBeanNames = envCtx.getMBeanNames();
0243:
0244:            }
0245:
0246:            /**
0247:             * This method is used to verify if the application variables and 
0248:             * application configuration objects used in the given 
0249:             * application are available in JBI runtime in the specified target. 
0250:             * Also this method verifies if all necessary  components are installed.
0251:             * If generateTemplates is true templates for missing application variables 
0252:             * and application configurations are generated. A command script that uses
0253:             * the template files to set configuration objects is generated.
0254:             *
0255:             * @param applicationURL the URL for the application zip file
0256:             * @param targetName the target on which the application has to be verified
0257:             * @param generateTemplates true if templates have to be generated
0258:             * @param templateDir the dir to store the generated templates
0259:             * @param includeDeployCommand true if the generated script should include
0260:             * deploy command 
0261:             *
0262:             * @returns CompositeData the verification report
0263:             * 
0264:             * CompositeType of verification report
0265:             *  String          - "ServiceAssemblyName",
0266:             *  String          - "ServiceAssemblyDescription",
0267:             *  Integer         - "NumServiceUnits",
0268:             *  Boolean         - "AllComponentsInstalled",
0269:             *  String[]        - "MissingComponentsList",
0270:             *  CompositeData[] - "EndpointInfo",
0271:             *  CompositeData[] - "JavaEEVerifierReport"
0272:             *  String          - "TemplateZIPID"
0273:             * 
0274:             * CompositeType of each EndpointInfo
0275:             *  String    - "EndpointName",
0276:             *  String    - "ServiceUnitName",
0277:             *  String    - "ComponentName",
0278:             *  String    - "Status"
0279:             *  String[]  - "MissingApplicationVariables"
0280:             *  String[]  - "MissingApplicationConfigurations"
0281:             * 
0282:             * CompositeType of each JavaEEVerifierReport
0283:             *  String        - "ServiceUnitName"
0284:             *  TabularData   - "JavaEEVerifierReport"
0285:             *
0286:             * TabularType of each JavaEEVerifierReport
0287:             * 
0288:             * SimpleType.STRING  - "Ear Filename"
0289:             * SimpleType.STRING  - "Referrence By"
0290:             * SimpleType.STRING  - "Referrence Class"
0291:             * SimpleType.STRING  - "JNDI Name"
0292:             * SimpleType.STRING  - "JNDI Class Type"
0293:             * SimpleType.STRING  - "Message"
0294:             * SimpleType.INTEGER - "Status"
0295:             * 
0296:             * @throws JBIRemoteException if the application could not be verified
0297:             * 
0298:             * Note: param templateDir is used between ant/cli and common client client
0299:             * TemplateZIPID is used between common client server and common client client
0300:             */
0301:            public CompositeData verifyApplication(String applicationURL,
0302:                    String targetName, boolean generateTemplates,
0303:                    String templateDir, boolean includeDeployCommand)
0304:                    throws JBIRemoteException {
0305:
0306:                ToolsLogManager.getRuntimeLogger().finer(
0307:                        "Verifier entered with SA " + applicationURL);
0308:
0309:                if (applicationURL == null || applicationURL.length() == 0) {
0310:                    String message = mResourceBundle
0311:                            .getMessage(LocalStringKeys.VERIFIER_INVALID_INPUT);
0312:                    ToolsLogManager.getRuntimeLogger().info(message);
0313:                    throw new JBIRemoteException(message);
0314:                }
0315:
0316:                mTarget = targetName;
0317:                mGenerateTemplates = generateTemplates;
0318:                mIncludeDeployCommand = includeDeployCommand;
0319:                JBIArchive archive;
0320:                try {
0321:                    archive = new JBIArchive(applicationURL);
0322:                } catch (IOException ioEx) {
0323:                    ToolsLogManager.getRuntimeLogger().info(ioEx.getMessage());
0324:                    throw new JBIRemoteException(ioEx.getMessage());
0325:                }
0326:                if (!archive.isServiceAssemblyArchive()) {
0327:                    String message = mResourceBundle
0328:                            .getMessage(LocalStringKeys.VERIFIER_INVALID_SA);
0329:                    ToolsLogManager.getRuntimeLogger().info(message);
0330:                    throw new JBIRemoteException(message);
0331:                }
0332:
0333:                try {
0334:                    String[] saInfo = getSAInfo(archive);
0335:                    String[] missingComponents = validateComponentList(archive,
0336:                            targetName);
0337:                    for (int i = 0; i < missingComponents.length; i++) {
0338:                        mMissingComponents.add(missingComponents[i]);
0339:                    }
0340:
0341:                    String saDir = extractSAForVerification(archive);
0342:                    CompositeData[] javaEEVerifierReports = null;
0343:
0344:                    if (isJavaEEVerifierAvailable()) {
0345:                        javaEEVerifierReports = verifyJavaEEServiceUnits(
0346:                                applicationURL, archive, targetName);
0347:                    } else {
0348:                        ToolsLogManager.getRuntimeLogger().warning(
0349:                                "JavaEE Verifier MBean is not available");
0350:                    }
0351:
0352:                    CompositeData endpointData[] = getEndpointsInfo(archive,
0353:                            saDir);
0354:                    String zipFile = null;
0355:                    String saName = saInfo[0];
0356:                    if (mGenerateTemplates) {
0357:                        boolean isAnt = true;
0358:
0359:                        TemplateGenerator generator = new TemplateGenerator(
0360:                                mEnvCtx, mResourceBundle);
0361:                        zipFile = generator.generateTemplates(
0362:                                mAppVarTemplatesMap, mAppConfigTemplatesMap,
0363:                                mAppConfigTypeMap, mIncludeDeployCommand,
0364:                                mTarget, isAnt, saName, applicationURL);
0365:                    }
0366:
0367:                    CompositeData response = composeResponse(saInfo,
0368:                            missingComponents, endpointData,
0369:                            javaEEVerifierReports, zipFile);
0370:                    try {
0371:                        //keep the template zip archive delete everything else
0372:                        mVerifierUtil
0373:                                .cleanup(mTmpDir + File.separator + saName);
0374:                        mVerifierUtil.cleanup(mTmpDir + File.separator + saName
0375:                                + TEMPLATE_DIR_SUFFIX);
0376:
0377:                    } catch (Exception ex) {
0378:                        //only best effort to clean up
0379:                        ToolsLogManager.getRuntimeLogger().warning(
0380:                                ex.getMessage());
0381:                    }
0382:                    return response;
0383:                } catch (Exception ex) {
0384:                    ToolsLogManager.getRuntimeLogger().warning(ex.getMessage());
0385:                    throw new JBIRemoteException(ex);
0386:                }
0387:
0388:            }
0389:
0390:            //private methods     
0391:
0392:            /**
0393:             * This method is used to verify if the components needed by a given SA 
0394:             * are installed
0395:             *
0396:             * @param archive the service assembly archive
0397:             * @returns String[] the list of missing components
0398:             * @throws JBIRemoteException
0399:             */
0400:            public String[] validateComponentList(JBIArchive archive,
0401:                    String targetName) throws JBIRemoteException {
0402:                ToolsLogManager.getRuntimeLogger().finer(
0403:                        "Validating component list");
0404:                try {
0405:                    List<String> components = getComponentListForSA(archive);
0406:                    List<String> missingComponents = new java.util.ArrayList();
0407:
0408:                    ComponentQuery componentQuery = mEnvCtx
0409:                            .getComponentQuery(targetName);
0410:                    List existingComponents = componentQuery
0411:                            .getComponentIds(ComponentType.BINDINGS_AND_ENGINES);
0412:
0413:                    for (String component : components) {
0414:                        if (!existingComponents.contains(component)) {
0415:                            missingComponents.add(component);
0416:                            ToolsLogManager.getRuntimeLogger().finer(
0417:                                    "Component " + component
0418:                                            + " is not installed");
0419:                        }
0420:                    }
0421:                    return missingComponents
0422:                            .toArray(new String[missingComponents.size()]);
0423:
0424:                } catch (Exception ex) {
0425:                    throw new JBIRemoteException(ex.getMessage());
0426:                }
0427:            }
0428:
0429:            /**
0430:             * This method is used to retrieve information about the SA from 
0431:             * the archive
0432:             * @param archive the SA archive
0433:             * @returns String[] with saName, saDesc, numSUs.
0434:             * @throws JBIRemoteException
0435:             */
0436:            private String[] getSAInfo(JBIArchive archive)
0437:                    throws JBIRemoteException {
0438:                ToolsLogManager.getRuntimeLogger().finer(
0439:                        "Getting info from the SA ");
0440:                try {
0441:                    ServiceAssemblyDD saDesc = (ServiceAssemblyDD) archive
0442:                            .getJbiDescriptor();
0443:                    return new String[] {
0444:                            saDesc.getName(),
0445:                            saDesc.getDescription(),
0446:                            Integer.toString(saDesc.getServiceUnitDDList()
0447:                                    .size())
0448:
0449:                    };
0450:                } catch (Exception ex) {
0451:                    throw new JBIRemoteException(ex.getMessage());
0452:                }
0453:            }
0454:
0455:            /**
0456:             * This method is used to compose the verification report
0457:             * @param saInfo information about the SA, saName, saDesc, numSUs
0458:             * @param missingComponents list of components neede by SA not in target
0459:             * @param endpointData information about each endpoint in SA
0460:             * @param javaEEVerifierReports verifier reports from Java EE Service Assembly
0461:             * @param zipID the id for the zip file that has the generated templates
0462:             */
0463:            private CompositeData composeResponse(String[] saInfo,
0464:                    String[] missingComponents, CompositeData[] endpointData,
0465:                    CompositeData[] javaEEVerifierReports, String zipID)
0466:                    throws JBIRemoteException {
0467:                ToolsLogManager.getRuntimeLogger().finer(
0468:                        "Composing verifier response ");
0469:
0470:                try {
0471:                    OpenType[] ENDPOINT_DATA_ITEM_TYPES = { SimpleType.STRING,
0472:                            SimpleType.STRING, SimpleType.STRING,
0473:                            SimpleType.STRING,
0474:                            new ArrayType(1, SimpleType.STRING),
0475:                            new ArrayType(1, SimpleType.STRING) };
0476:
0477:                    CompositeType endpointInfoType = new CompositeType(
0478:                            "EndpointInfoType",
0479:                            "Provides information about an endpoint",
0480:                            ENDPOINT_DATA_ITEM_NAMES,
0481:                            ENDPOINT_DATA_ITEM_DESCRIPTIONS,
0482:                            ENDPOINT_DATA_ITEM_TYPES);
0483:                    ToolsLogManager.getRuntimeLogger().finer(
0484:                            "Composed endpoint info type");
0485:
0486:                    //deduce the type for JavaEE Verifier reports
0487:                    CompositeType javaEEVerifierReportType = null;
0488:                    if (javaEEVerifierReports != null
0489:                            && javaEEVerifierReports.length > 0
0490:                            && javaEEVerifierReports[0] != null) {
0491:                        javaEEVerifierReportType = javaEEVerifierReports[0]
0492:                                .getCompositeType();
0493:                        ToolsLogManager.getRuntimeLogger().finer(
0494:                                "Composed javaee verifier report type");
0495:                    }
0496:
0497:                    ArrayList<String> verifierReportItemNames = new ArrayList<String>();
0498:                    verifierReportItemNames.add("ServiceAssemblyName");
0499:                    verifierReportItemNames.add("ServiceAssemblyDescription");
0500:                    verifierReportItemNames.add("NumServiceUnits");
0501:                    verifierReportItemNames.add("AllComponentsInstalled");
0502:                    verifierReportItemNames.add("MissingComponentsList");
0503:                    verifierReportItemNames.add("EndpointInfo");
0504:                    verifierReportItemNames.add("TemplateZIPID");
0505:                    if (javaEEVerifierReportType != null) {
0506:                        verifierReportItemNames.add("JavaEEVerifierReport");
0507:                    }
0508:
0509:                    ArrayList<String> verifierReportItemDescriptions = new ArrayList<String>();
0510:                    verifierReportItemDescriptions
0511:                            .add("Name of the Service Assembly");
0512:                    verifierReportItemDescriptions
0513:                            .add("Description of the Service Assembly");
0514:                    verifierReportItemDescriptions
0515:                            .add("Number of Service Units");
0516:                    verifierReportItemDescriptions
0517:                            .add("Are all necessary components installed");
0518:                    verifierReportItemDescriptions
0519:                            .add("List of missing components");
0520:                    verifierReportItemDescriptions
0521:                            .add("Information about the endpoints");
0522:                    verifierReportItemDescriptions
0523:                            .add("Id for the zip file with configuration templates");
0524:                    if (javaEEVerifierReportType != null) {
0525:                        verifierReportItemDescriptions
0526:                                .add("Java EE Verifier Reports");
0527:                    }
0528:
0529:                    ArrayList<OpenType> verifierReportItemTypes = new ArrayList<OpenType>();
0530:                    verifierReportItemTypes.add(SimpleType.STRING);
0531:                    verifierReportItemTypes.add(SimpleType.STRING);
0532:                    verifierReportItemTypes.add(SimpleType.INTEGER);
0533:                    verifierReportItemTypes.add(SimpleType.BOOLEAN);
0534:                    verifierReportItemTypes.add(new ArrayType(1,
0535:                            SimpleType.STRING));
0536:                    verifierReportItemTypes.add(new ArrayType(1,
0537:                            endpointInfoType));
0538:                    verifierReportItemTypes.add(SimpleType.STRING);
0539:                    if (javaEEVerifierReportType != null) {
0540:                        verifierReportItemTypes.add(new ArrayType(1,
0541:                                javaEEVerifierReportType));
0542:                    }
0543:
0544:                    CompositeType verifierReportType = new CompositeType(
0545:                            "VerifierReportType",
0546:                            "Type of the verification report",
0547:                            (String[]) verifierReportItemNames
0548:                                    .toArray(new String[] {}),
0549:                            (String[]) verifierReportItemDescriptions
0550:                                    .toArray(new String[] {}),
0551:                            (OpenType[]) verifierReportItemTypes
0552:                                    .toArray(new OpenType[] {}));
0553:
0554:                    ArrayList<Object> verifierReportValues = new ArrayList<Object>();
0555:                    verifierReportValues.add(saInfo[0]);
0556:                    verifierReportValues.add(saInfo[1]);
0557:                    verifierReportValues.add(Integer.valueOf(saInfo[2]));
0558:                    verifierReportValues.add(new Boolean(
0559:                            missingComponents.length == 0));
0560:                    verifierReportValues.add(missingComponents);
0561:                    verifierReportValues.add(endpointData);
0562:                    verifierReportValues.add(zipID);
0563:                    if (javaEEVerifierReportType != null) {
0564:                        verifierReportValues.add(javaEEVerifierReports);
0565:                    }
0566:
0567:                    CompositeData cData = new CompositeDataSupport(
0568:                            verifierReportType,
0569:                            (String[]) verifierReportItemNames
0570:                                    .toArray(new String[] {}),
0571:                            (Object[]) verifierReportValues
0572:                                    .toArray(new Object[] {}));
0573:
0574:                    ToolsLogManager.getRuntimeLogger().finer(
0575:                            "Verifier Report: " + cData);
0576:                    return cData;
0577:                } catch (OpenDataException ode) {
0578:                    ToolsLogManager.getRuntimeLogger()
0579:                            .warning(ode.getMessage());
0580:                    throw new JBIRemoteException(ode.getMessage());
0581:                }
0582:
0583:            }
0584:
0585:            /**
0586:             * This method is used to get information about the status of 
0587:             * the endpoint
0588:             * @param archive the JBIArchive
0589:             * @param saDir the dir where the SA was extracted.
0590:             * @returns the endpointinfo 
0591:             * @throws JBIRemoteException if the endpoint info type could not be obtained
0592:             */
0593:            private CompositeData[] getEndpointsInfo(JBIArchive archive,
0594:                    String saDir) throws JBIRemoteException {
0595:                try {
0596:                    OpenType[] ENDPOINT_DATA_ITEM_TYPES = { SimpleType.STRING,
0597:                            SimpleType.STRING, SimpleType.STRING,
0598:                            SimpleType.STRING,
0599:                            new ArrayType(1, SimpleType.STRING),
0600:                            new ArrayType(1, SimpleType.STRING) };
0601:                    CompositeType endpointInfoType = new CompositeType(
0602:                            "EndpointInfoType",
0603:                            "Provides information about an endpoint",
0604:                            ENDPOINT_DATA_ITEM_NAMES,
0605:                            ENDPOINT_DATA_ITEM_DESCRIPTIONS,
0606:                            ENDPOINT_DATA_ITEM_TYPES);
0607:
0608:                    Map<String, EndpointInfo> endpointInfo = getEndpointDetails(
0609:                            archive, saDir);
0610:                    CompositeData[] endpointArray = new CompositeData[endpointInfo
0611:                            .keySet().size()];
0612:
0613:                    Iterator endpointsIter = endpointInfo.keySet().iterator();
0614:                    int counter = 0;
0615:                    EndpointInfo endpoint = null;
0616:                    while (endpointsIter.hasNext()) {
0617:
0618:                        try {
0619:                            endpoint = endpointInfo.get(endpointsIter.next());
0620:                            String status = null;
0621:                            String[] missingVars = new String[] {};
0622:                            String[] missingConfigs = new String[] {};
0623:
0624:                            if (!isComponentRunning(
0625:                                    endpoint.getComponentName(), mTarget)) {
0626:                                status = STATUS_UNKNOWN;
0627:                            } else {
0628:                                missingVars = getMissingApplicationVariables(endpoint);
0629:                                missingConfigs = getMissingApplicationConfigurations(endpoint);
0630:                                status = getEndpointStatus(endpoint,
0631:                                        missingVars, missingConfigs);
0632:                            }
0633:
0634:                            Object[] endpointValues = new Object[6];
0635:                            endpointValues[0] = endpoint.getEndpointName();
0636:                            endpointValues[1] = endpoint.getServiceUnitName();
0637:                            endpointValues[2] = endpoint.getComponentName();
0638:                            endpointValues[3] = status;
0639:                            endpointValues[4] = missingVars;
0640:                            endpointValues[5] = missingConfigs;
0641:
0642:                            CompositeData endpointData = new CompositeDataSupport(
0643:                                    endpointInfoType, ENDPOINT_DATA_ITEM_NAMES,
0644:                                    endpointValues);
0645:                            endpointArray[counter] = endpointData;
0646:                            counter++;
0647:
0648:                        } catch (VerifierException ve) {
0649:                            //continue with next endpoint
0650:                            ToolsLogManager
0651:                                    .getRuntimeLogger()
0652:                                    .warning(
0653:                                            mResourceBundle
0654:                                                    .getMessage(
0655:                                                            LocalStringKeys.VERIFIER_ENDPOINT_STATUS_NOT_DETERMINED,
0656:                                                            new Object[] { endpoint
0657:                                                                    .getEndpointName() }));
0658:                            ToolsLogManager.getRuntimeLogger().warning(
0659:                                    ve.getMessage());
0660:                        } catch (Throwable jRE) {
0661:                            //continue with next endpoint
0662:                            ToolsLogManager
0663:                                    .getRuntimeLogger()
0664:                                    .warning(
0665:                                            mResourceBundle
0666:                                                    .getMessage(
0667:                                                            LocalStringKeys.VERIFIER_ENDPOINT_STATUS_NOT_DETERMINED,
0668:                                                            new Object[] { endpoint
0669:                                                                    .getEndpointName() }));
0670:                            ToolsLogManager.getRuntimeLogger().warning(
0671:                                    jRE.getMessage());
0672:                        }
0673:                    }
0674:                    for (String component : mStartedComponents) {
0675:                        stopComponent(component, mTarget);
0676:                    }
0677:                    return endpointArray;
0678:
0679:                } catch (OpenDataException ode) {
0680:                    throw new JBIRemoteException(ode.getMessage());
0681:                } catch (VerifierException ve) {
0682:                    throw new JBIRemoteException(ve.getMessage());
0683:                }
0684:            }
0685:
0686:            /**
0687:             * This method is used to get a list of components needed by 
0688:             * the given SA
0689:             * @param archive the JBIArchive
0690:             * @returns List<String> component list
0691:             */
0692:            private List getComponentListForSA(JBIArchive archive)
0693:                    throws JBIRemoteException {
0694:                try {
0695:                    ServiceAssemblyDD saDesc = (ServiceAssemblyDD) archive
0696:                            .getJbiDescriptor();
0697:                    List<ServiceAssemblyDD.ServiceUnitDD> suDescs = saDesc
0698:                            .getServiceUnitDDList();
0699:                    List<String> components = new java.util.ArrayList();
0700:
0701:                    for (ServiceAssemblyDD.ServiceUnitDD suDesc : suDescs) {
0702:                        components.add(suDesc.getTargetName());
0703:                    }
0704:                    return components;
0705:                } catch (Exception ex) {
0706:                    throw new JBIRemoteException(ex.getMessage());
0707:                }
0708:            }
0709:
0710:            /**
0711:             * This method is used to get the target component name for the given SU
0712:             * @param archive the JBIArchive
0713:             * @param suName the su Name
0714:             * @returns String the component name
0715:             * @returns List<String> component list
0716:             */
0717:            private String getTargetComponentForSU(JBIArchive archive,
0718:                    String suName) throws VerifierException {
0719:                try {
0720:                    ServiceAssemblyDD saDesc = (ServiceAssemblyDD) archive
0721:                            .getJbiDescriptor();
0722:                    List<ServiceAssemblyDD.ServiceUnitDD> suDescs = saDesc
0723:                            .getServiceUnitDDList();
0724:                    List<String> components = new java.util.ArrayList();
0725:
0726:                    for (ServiceAssemblyDD.ServiceUnitDD suDesc : suDescs) {
0727:                        if (suDesc.getName().equals(suName)) {
0728:                            return suDesc.getTargetName();
0729:                        }
0730:                    }
0731:                    return null;
0732:                } catch (Exception ex) {
0733:                    throw new VerifierException(ex);
0734:                }
0735:            }
0736:
0737:            /**
0738:             * This method is used to extract the given SA in a temporary location for
0739:             * verification.
0740:             * @param archive JBIArchive
0741:             * @returns the dir where the SA was extracted.
0742:             */
0743:            private String extractSAForVerification(JBIArchive archive)
0744:                    throws JBIRemoteException {
0745:                String saDir = mVerifierUtil.extractSA(mTmpDir, archive);
0746:                ToolsLogManager.getRuntimeLogger().finer(
0747:                        "Successfully extracted SA in " + saDir);
0748:                return saDir;
0749:            }
0750:
0751:            /**
0752:             * This method is used to get the information about all the endpoints in 
0753:             * an archive
0754:             * @param archive JBIArchive
0755:             * @param saDir the dir where the SA was extracted.
0756:             * @return Map<String, EndpointInfo> a map of endpoint names to endpoint details
0757:             * @throws JBIRemoteException if the information could not be extracted
0758:             */
0759:            private Map<String, EndpointInfo> getEndpointDetails(
0760:                    JBIArchive archive, String saDir) throws VerifierException,
0761:                    JBIRemoteException {
0762:
0763:                try {
0764:                    Map<String, EndpointInfo> endpointDetails = new HashMap();
0765:                    ToolsLogManager.getRuntimeLogger().finer(
0766:                            "Entered getEndpointDetails");
0767:                    Map<String, File[]> wsdlMap = mVerifierUtil.getWSDLs(saDir);
0768:                    Iterator iterSuNames = wsdlMap.keySet().iterator();
0769:                    while (iterSuNames.hasNext()) {
0770:                        try {
0771:                            String suName = (String) iterSuNames.next();
0772:                            String targetComponent = getTargetComponentForSU(
0773:                                    archive, suName);
0774:                            if (targetComponent != null
0775:                                    && targetComponent
0776:                                            .equals(JAVAEE_SERVICE_ENGINE)) {
0777:                                //javaee SUs will not have application variables or configurations
0778:                                continue;
0779:                            }
0780:
0781:                            ToolsLogManager.getRuntimeLogger().finer(
0782:                                    "Collecting Info for su " + suName);
0783:                            File[] wsdls = wsdlMap.get(suName);
0784:                            String suDir = saDir + File.separator + suName
0785:                                    + File.separator + targetComponent;
0786:                            Map<String, List<String>> appConfigMap = mVerifierUtil
0787:                                    .getEndpointConfigMap(suDir);
0788:
0789:                            for (int j = 0; j < wsdls.length; j++) {
0790:                                try {
0791:                                    String[] endpointNames = mVerifierUtil
0792:                                            .getEndpointName(wsdls[j]);
0793:                                    for (int i = 0; i < endpointNames.length; i++) {
0794:                                        List appVarList = mVerifierUtil
0795:                                                .getApplicationVariables(
0796:                                                        wsdls[j],
0797:                                                        endpointNames[i]);
0798:                                        String componentName = getTargetComponentForSU(
0799:                                                archive, suName);
0800:                                        ToolsLogManager
0801:                                                .getRuntimeLogger()
0802:                                                .finer(
0803:                                                        "Adding endpointInfo for endpoint "
0804:                                                                + endpointNames[i]);
0805:                                        EndpointInfo endpointInfo = new EndpointInfo();
0806:                                        endpointInfo
0807:                                                .setEndpointName(endpointNames[i]);
0808:                                        endpointInfo.setServiceUnitName(suName);
0809:                                        endpointInfo
0810:                                                .setComponentName(componentName);
0811:                                        endpointInfo
0812:                                                .setApplicationVariables(appVarList);
0813:                                        endpointInfo
0814:                                                .setApplicationConfigurations(appConfigMap
0815:                                                        .get(endpointNames[i]));
0816:
0817:                                        //if this endpoint is already available, give preference to the one that came from a BC
0818:                                        if (endpointDetails
0819:                                                .containsKey(endpointNames[i])) {
0820:                                            ComponentType newComponentType = getComponentType(componentName);
0821:                                            ComponentType oldComponentType = getComponentType(endpointDetails
0822:                                                    .get(endpointNames[i])
0823:                                                    .getComponentName());
0824:                                            if (oldComponentType
0825:                                                    .equals(ComponentType.ENGINE)
0826:                                                    && newComponentType
0827:                                                            .equals(ComponentType.BINDING)) {
0828:                                                endpointDetails.put(
0829:                                                        endpointNames[i],
0830:                                                        endpointInfo);
0831:                                                ToolsLogManager
0832:                                                        .getRuntimeLogger()
0833:                                                        .finer(
0834:                                                                "Endpoint found in more than 1 wsdl, adding endpoint for component "
0835:                                                                        + componentName);
0836:                                            }
0837:                                        } else {
0838:                                            endpointDetails.put(
0839:                                                    endpointNames[i],
0840:                                                    endpointInfo);
0841:                                        }
0842:                                        ToolsLogManager.getRuntimeLogger()
0843:                                                .finer(
0844:                                                        "Endpoint info"
0845:                                                                + endpointInfo);
0846:                                    }
0847:                                } catch (Exception ex) {
0848:                                    //continue with next endpoint
0849:                                    ToolsLogManager.getRuntimeLogger().warning(
0850:                                            ex.getMessage());
0851:                                }
0852:                            }
0853:                        } catch (Exception ex) {
0854:                            //continue with next wsdl
0855:                            ToolsLogManager.getRuntimeLogger().warning(
0856:                                    ex.getMessage());
0857:                        }
0858:                    }
0859:                    return endpointDetails;
0860:                } catch (VerifierException ex) {
0861:                    ToolsLogManager.getRuntimeLogger().warning(ex.getMessage());
0862:                    throw ex;
0863:                }
0864:
0865:            }
0866:
0867:            /**
0868:             * This method is used to find out the type of the given component.
0869:             * @param componentName the component name
0870:             * @return ComponentType the componentType
0871:             * @throws VerifierException if the type could not be determined
0872:             */
0873:            private ComponentType getComponentType(String componentName)
0874:                    throws VerifierException {
0875:                try {
0876:                    ComponentQuery componentQuery = mEnvCtx
0877:                            .getComponentQuery(mTarget);
0878:                    ComponentInfo compInfo = componentQuery
0879:                            .getComponentInfo(componentName);
0880:                    return compInfo.getComponentType();
0881:                } catch (Exception ex) {
0882:                    throw new VerifierException(ex.getMessage());
0883:                }
0884:            }
0885:
0886:            /**
0887:             * This method is used to return the status of an endpoint by determining if
0888:             * the application variables and application configurations used could be resolved.
0889:             * @param endpointInfo endpointinfo
0890:             * @param missingAppVars list of unresolved app vars
0891:             * @param missingAppConfigs list of unresolved app configs
0892:             * @return String status
0893:             * @throws JBIRemoteException
0894:             * @throws VerifierException
0895:             */
0896:            private String getEndpointStatus(EndpointInfo endpointInfo,
0897:                    String[] missingAppVars, String[] missingAppConfigs)
0898:                    throws VerifierException, JBIRemoteException {
0899:
0900:                if (mMissingComponents
0901:                        .contains(endpointInfo.getComponentName())) {
0902:                    return STATUS_UNKNOWN;
0903:                }
0904:
0905:                if ((missingAppVars == null || missingAppVars.length == 0)
0906:                        && (missingAppConfigs == null || missingAppConfigs.length == 0)) {
0907:                    return STATUS_RESOLVED;
0908:                } else {
0909:                    return STATUS_UNRESOLVED;
0910:                }
0911:
0912:            }
0913:
0914:            /**
0915:             * This method is used to verify if a set of application variables 
0916:             * are set in the given target for a given component
0917:             * This methods returns the list of missing application variables 
0918:             * from the given list. 
0919:             * @param endpoint EndpointInfo
0920:             * @return String[] the list of missing application variables
0921:             */
0922:            private String[] getMissingApplicationVariables(
0923:                    EndpointInfo endpoint) throws VerifierException,
0924:                    JBIRemoteException {
0925:                List<String> unresolvedVars = new ArrayList();
0926:                String componentName = endpoint.getComponentName();
0927:                List<String> appVarList = endpoint.getApplicationVariables();
0928:
0929:                //if the component is not available, then return empty list
0930:                if (mMissingComponents.contains(componentName)) {
0931:                    return new String[] {};
0932:                }
0933:                Properties applicationVariables = getApplicationVariables(
0934:                        componentName, mTarget);
0935:                Set keySet = applicationVariables.keySet();
0936:                ToolsLogManager.getRuntimeLogger().finer(
0937:                        "List of application vars for component" + keySet);
0938:
0939:                for (String variable : appVarList) {
0940:                    if (!keySet.contains(variable)) {
0941:                        unresolvedVars.add(variable);
0942:                    }
0943:                }
0944:                if (mGenerateTemplates) {
0945:                    List currentVars;
0946:                    if (mAppVarTemplatesMap.containsKey(componentName)) {
0947:                        currentVars = mAppVarTemplatesMap.get(componentName);
0948:                    } else {
0949:                        currentVars = new ArrayList<String>();
0950:                    }
0951:                    currentVars.addAll(unresolvedVars);
0952:                    mAppVarTemplatesMap.put(componentName, currentVars);
0953:                }
0954:                return (String[]) unresolvedVars.toArray(new String[] {});
0955:
0956:            }
0957:
0958:            /**
0959:             * This method is used to verify if a set of application configurations 
0960:             * are set in the given target for a given component
0961:             * @param endpoint EndpointInfo
0962:             * @return String[] the list of missing application configurations
0963:             */
0964:            private String[] getMissingApplicationConfigurations(
0965:                    EndpointInfo endpoint) throws VerifierException,
0966:                    JBIRemoteException {
0967:                List<String> unresolvedConfigs = new ArrayList();
0968:                String componentName = endpoint.getComponentName();
0969:                List<String> appConfigList = endpoint
0970:                        .getApplicationConfigurations();
0971:
0972:                //if the component is not available, then return empty list
0973:                if (mMissingComponents.contains(componentName)) {
0974:                    return new String[] {};
0975:                }
0976:
0977:                Set applicationConfigurations = getApplicationConfigurations(
0978:                        componentName, mTarget);
0979:                ToolsLogManager.getRuntimeLogger().finer(
0980:                        "List of application configs for component"
0981:                                + applicationConfigurations);
0982:
0983:                if (appConfigList != null) {
0984:                    for (String config : appConfigList) {
0985:                        if (!applicationConfigurations.contains(config)) {
0986:                            unresolvedConfigs.add(config);
0987:                        }
0988:                    }
0989:                }
0990:
0991:                if (mGenerateTemplates) {
0992:                    List currentConfigs;
0993:                    if (mAppConfigTemplatesMap.containsKey(componentName)) {
0994:                        currentConfigs = mAppConfigTemplatesMap
0995:                                .get(componentName);
0996:                    } else {
0997:                        currentConfigs = new ArrayList<String>();
0998:                    }
0999:                    currentConfigs.addAll(unresolvedConfigs);
1000:                    mAppConfigTemplatesMap.put(componentName, currentConfigs);
1001:                    mAppConfigTypeMap.put(componentName, getAppConfigType(
1002:                            componentName, mTarget));
1003:                }
1004:                return (String[]) unresolvedConfigs.toArray(new String[] {});
1005:
1006:            }
1007:
1008:            /**
1009:             * This method is used to get a list of application variables 
1010:             * set for a component in the given target
1011:             * @param componentName component Name
1012:             * @param targetName target Name
1013:             * @returns Properties application variables 
1014:             */
1015:            private Properties getApplicationVariables(String componentName,
1016:                    String targetName) throws VerifierException,
1017:                    JBIRemoteException {
1018:
1019:                Properties appVarProps = new Properties();
1020:                ObjectName configFacadeMBean = this 
1021:                        .getComponentConfigurationFacadeMBeanName(
1022:                                componentName, targetName);
1023:                ToolsLogManager.getRuntimeLogger().finer(
1024:                        "getApplicationVariables(" + componentName + ","
1025:                                + targetName + "): configMBean = "
1026:                                + configFacadeMBean);
1027:
1028:                if ((configFacadeMBean != null)
1029:                        && (true == this .isValidTarget(configFacadeMBean))) {
1030:                    try {
1031:                        TabularData appVarTable = (TabularData) this 
1032:                                .getAttributeValue(configFacadeMBean,
1033:                                        "ApplicationVariables");
1034:
1035:                        appVarProps = new ComponentConfigurationHelper()
1036:                                .convertToApplicationVariablesProperties(appVarTable);
1037:                        ToolsLogManager.getRuntimeLogger().finer(
1038:                                "getApplicationVariables(): result = "
1039:                                        + appVarProps);
1040:                    } catch (JBIRemoteException jbiRE) {
1041:                        throw new VerifierException(jbiRE);
1042:                    } catch (Exception ex) {
1043:                        throw new VerifierException(ex);
1044:                    }
1045:                }
1046:                return appVarProps;
1047:            }
1048:
1049:            /**
1050:             * This method is used to get a list of application configurations 
1051:             * available for a component in the given target
1052:             * @pram componentName component name
1053:             * @param target target name
1054:             * @returns Set list of application configurations available
1055:             */
1056:            private Set getApplicationConfigurations(String componentName,
1057:                    String target) throws VerifierException, JBIRemoteException {
1058:                Map<String, Properties> appConfigMap = new HashMap();
1059:                ObjectName configFacadeMBean = this 
1060:                        .getComponentConfigurationFacadeMBeanName(
1061:                                componentName, target);
1062:                ToolsLogManager.getRuntimeLogger().finer(
1063:                        "getApplicationConfigurations" + componentName + ","
1064:                                + target + "): configMBean = "
1065:                                + configFacadeMBean);
1066:
1067:                if ((configFacadeMBean != null)
1068:                        && (true == this .isValidTarget(configFacadeMBean))) {
1069:                    try {
1070:                        TabularData appConfigTable = (TabularData) this 
1071:                                .getAttributeValue(configFacadeMBean,
1072:                                        "ApplicationConfigurations");
1073:
1074:                        if (appConfigTable != null) {
1075:                            // Convert the application configuration Tabular Data to a Map
1076:                            appConfigMap = getApplicationConfigurationsMap(appConfigTable);
1077:                        }
1078:
1079:                    } catch (JBIRemoteException jbiRE) {
1080:                        ToolsLogManager.getRuntimeLogger().warning(
1081:                                jbiRE.getMessage());
1082:                    } catch (Throwable ex) {
1083:                        ToolsLogManager.getRuntimeLogger().warning(
1084:                                ex.getMessage());
1085:                    }
1086:                }
1087:                return appConfigMap.keySet();
1088:            }
1089:
1090:            /**
1091:             * This method is used to get the composite type for the application
1092:             * configuration for a component 
1093:             * @pram componentName component name
1094:             * @param target target name
1095:             * @returns CompositeType type of application configuration
1096:             */
1097:            private CompositeType getAppConfigType(String componentName,
1098:                    String target) throws VerifierException, JBIRemoteException {
1099:                CompositeType appConfigType = null;
1100:                ObjectName configFacadeMBean = this 
1101:                        .getComponentConfigurationFacadeMBeanName(
1102:                                componentName, target);
1103:                ToolsLogManager.getRuntimeLogger().finer(
1104:                        "getAppConfigType" + componentName + "," + target
1105:                                + "): configMBean = " + configFacadeMBean);
1106:
1107:                if ((configFacadeMBean != null)
1108:                        && (true == this .isValidTarget(configFacadeMBean))) {
1109:                    try {
1110:
1111:                        appConfigType = (CompositeType) invokeMBeanOperation(
1112:                                configFacadeMBean,
1113:                                "queryApplicationConfigurationType",
1114:                                new Object[0], new String[0]);
1115:                    } catch (JBIRemoteException jbiRE) {
1116:                        ToolsLogManager.getRuntimeLogger().warning(
1117:                                jbiRE.getMessage());
1118:                    } catch (Exception ex) {
1119:                        ToolsLogManager.getRuntimeLogger().warning(
1120:                                ex.getMessage());
1121:                    }
1122:                }
1123:                return appConfigType;
1124:            }
1125:
1126:            /**
1127:             * This method is used to find out if a component is started in 
1128:             * the target. If not, the runtime configuration property is checked to 
1129:             * see if the component could be started. If so, the component is started.
1130:             * If not this method retunrs false as the status of the endpoint in this
1131:             * target could not be obtained
1132:             * @param componentName componentName
1133:             * @param target target
1134:             * @returns boolean true if the component is started false otherwise
1135:             */
1136:            public boolean isComponentRunning(String componentName,
1137:                    String target) {
1138:
1139:                ComponentQuery compQuery = mEnvCtx.getComponentQuery(target);
1140:                ComponentInfo compInfo = compQuery
1141:                        .getComponentInfo(componentName);
1142:                if (compInfo == null) {
1143:                    //component not installed
1144:                    return false;
1145:                }
1146:
1147:                if (compInfo.getStatus().equals(ComponentState.STARTED)) {
1148:                    return true;
1149:                }
1150:                if (mEnvCtx.isStartOnVerifyEnabled()) {
1151:                    if (startComponent(componentName, target)) {
1152:                        mStartedComponents.add(componentName);
1153:                        return true;
1154:                    }
1155:                }
1156:                return false;
1157:
1158:            }
1159:
1160:            /**
1161:             * This method is used to start a component in the given target
1162:             * @param componentName component Name
1163:             * @param targetName target name
1164:             * @returns boolean if the component is started successfully false otherwise
1165:             */
1166:            private boolean startComponent(String componentName,
1167:                    String targetName) {
1168:                try {
1169:                    ObjectName lifecycleObjectName = getComponentLifeCycleMBeanObjectName(
1170:                            componentName, targetName);
1171:
1172:                    Object result = null;
1173:                    ToolsLogManager.getRuntimeLogger().finer(
1174:                            "Calling start on Component LifecycleMBean "
1175:                                    + lifecycleObjectName);
1176:                    result = invokeMBeanOperation(lifecycleObjectName, "start",
1177:                            new Object[0], new String[0]);
1178:                    return true;
1179:                } catch (Exception ex) {
1180:                    ToolsLogManager
1181:                            .getRuntimeLogger()
1182:                            .warning(
1183:                                    mResourceBundle
1184:                                            .getMessage(
1185:                                                    LocalStringKeys.VERIFIER_COMPONENT_NOT_STARTED,
1186:                                                    new Object[] { componentName }));
1187:                    ToolsLogManager.getRuntimeLogger().warning(ex.getMessage());
1188:                    return false;
1189:                }
1190:            }
1191:
1192:            /**
1193:             * This method is used to shutdown a component in the given target
1194:             * @param componentName component Name
1195:             * @param targetName target name
1196:             * @returns boolean if the component is shutdown successfully false otherwise
1197:             */
1198:            private boolean stopComponent(String componentName,
1199:                    String targetName) {
1200:                try {
1201:                    ObjectName lifecycleObjectName = getComponentLifeCycleMBeanObjectName(
1202:                            componentName, targetName);
1203:
1204:                    Object result = null;
1205:                    ToolsLogManager.getRuntimeLogger().finer(
1206:                            "Calling shutdown on Component LifecycleMBean "
1207:                                    + lifecycleObjectName);
1208:                    result = invokeMBeanOperation(lifecycleObjectName,
1209:                            "shutDown", new Object[0], new String[0]);
1210:                    return true;
1211:                } catch (Exception ex) {
1212:                    ToolsLogManager
1213:                            .getRuntimeLogger()
1214:                            .warning(
1215:                                    mResourceBundle
1216:                                            .getMessage(
1217:                                                    LocalStringKeys.VERIFIER_COMPONENT_NOT_SHUTDOWN,
1218:                                                    new Object[] { componentName }));
1219:                    ToolsLogManager.getRuntimeLogger().warning(ex.getMessage());
1220:                    return false;
1221:                }
1222:            }
1223:
1224:            /**
1225:             * returns the ObjectName for the lifecycle Mbean of this component.
1226:             * 
1227:             * @return the ObjectName for the lifecycle Mbean.
1228:             * @param componentName
1229:             *            of a binding or engine component.
1230:             * @param targetName
1231:             * @throws JBIRemoteException
1232:             *             on error
1233:             */
1234:            private ObjectName getComponentLifeCycleMBeanObjectName(
1235:                    String componentName, String targetName)
1236:                    throws VerifierException {
1237:                ObjectName lifecycleObjectNamePattern = null;
1238:                try {
1239:                    lifecycleObjectNamePattern = JBIJMXObjectNames
1240:                            .getComponentLifeCycleMBeanObjectNamePattern(
1241:                                    componentName, targetName);
1242:                } catch (MalformedObjectNameException ex) {
1243:                    throw new VerifierException(ex);
1244:                }
1245:
1246:                MBeanServer mbeanServer = mEnvCtx.getMBeanServer();
1247:
1248:                Set objectNames = mbeanServer.queryNames(
1249:                        lifecycleObjectNamePattern, null);
1250:
1251:                if (objectNames.isEmpty()) {
1252:                    throw new VerifierException(
1253:                            mResourceBundle
1254:                                    .getMessage(
1255:                                            LocalStringKeys.VERIFIER_NO_COMPONENT_LIFECYCLE_OBJECT,
1256:                                            new Object[] { componentName,
1257:                                                    targetName }));
1258:                }
1259:
1260:                if (objectNames.size() > 1) {
1261:                    throw new VerifierException(
1262:                            mResourceBundle
1263:                                    .getMessage(
1264:                                            LocalStringKeys.VERIFIER_MANY_COMPONENT_LIFECYCLE_OBJECT,
1265:                                            new Object[] { componentName,
1266:                                                    targetName }));
1267:                }
1268:
1269:                ObjectName lifecyleObjectName = (ObjectName) objectNames
1270:                        .iterator().next();
1271:                return lifecyleObjectName;
1272:
1273:            }
1274:
1275:            /**
1276:             * invokes the operation on mbean
1277:             * 
1278:             * @return result object
1279:             * @param objectName
1280:             *            object name
1281:             * @param operationName
1282:             *            operation name
1283:             * @param params
1284:             *            parameters
1285:             * @param signature
1286:             *            signature of the parameters
1287:             * @throws JBIRemoteException
1288:             *             on user error
1289:             */
1290:            protected Object invokeMBeanOperation(ObjectName objectName,
1291:                    String operationName, Object[] params, String[] signature)
1292:                    throws JBIRemoteException {
1293:                MBeanServer mbeanServer = mEnvCtx.getMBeanServer();
1294:                Object result = null;
1295:
1296:                try {
1297:
1298:                    result = mbeanServer.invoke(objectName, operationName,
1299:                            params, signature);
1300:
1301:                } catch (InstanceNotFoundException notFoundEx) {
1302:                    throw new JBIRemoteException(notFoundEx);
1303:                } catch (ReflectionException rEx) {
1304:                    throw new JBIRemoteException(rEx);
1305:                } catch (MBeanException mbeanEx) {
1306:                    throw JBIRemoteException.filterJmxExceptions(mbeanEx);
1307:                } catch (RuntimeMBeanException rtEx) {
1308:                    throw JBIRemoteException.filterJmxExceptions(rtEx);
1309:                } catch (RuntimeOperationsException rtOpEx) {
1310:                    throw JBIRemoteException.filterJmxExceptions(rtOpEx);
1311:                } catch (Exception ex) {
1312:                    throw JBIRemoteException.filterJmxExceptions(ex);
1313:                }
1314:
1315:                return result;
1316:
1317:            }
1318:
1319:            /**
1320:             * Get the component configuration facade MBean name for the target. If the component
1321:             * is not installed on the target, this returns a null. 
1322:             * @param componentName - component id
1323:             * @param targetName - target name
1324:             * @return the ObjectName of the components facade Configuration MBean for a target.
1325:             */
1326:            private ObjectName getComponentConfigurationFacadeMBeanName(
1327:                    String componentName, String targetName)
1328:                    throws JBIRemoteException, VerifierException {
1329:                ObjectName objName = null;
1330:
1331:                ToolsLogManager.getRuntimeLogger().finer(
1332:                        "Get Component Configuration MBean Name for component "
1333:                                + componentName);
1334:
1335:                ObjectName extensionMBeanObjectName = null;
1336:                try {
1337:                    extensionMBeanObjectName = this 
1338:                            .getExtensionMBeanObjectName(componentName,
1339:                                    targetName);
1340:                } catch (VerifierException exception) {
1341:                    ToolsLogManager.getRuntimeLogger().warning(
1342:                            exception.getMessage());
1343:                }
1344:
1345:                if (extensionMBeanObjectName == null) {
1346:                    return objName;
1347:                }
1348:
1349:                this .checkForValidTarget(extensionMBeanObjectName, targetName);
1350:
1351:                ToolsLogManager
1352:                        .getRuntimeLogger()
1353:                        .finer(
1354:                                "Calling getComponentConfigurationFacadeMBeanName on extensionMBeanObjectName = "
1355:                                        + extensionMBeanObjectName);
1356:
1357:                Object[] params = new Object[1];
1358:                params[0] = targetName;
1359:
1360:                String[] signature = new String[1];
1361:                signature[0] = "java.lang.String";
1362:
1363:                objName = (ObjectName) this .invokeMBeanOperation(
1364:                        extensionMBeanObjectName,
1365:                        "getComponentConfigurationFacadeMBeanName", params,
1366:                        signature);
1367:
1368:                return objName;
1369:            }
1370:
1371:            /**
1372:             * returns the ObjectName for the Extension Mbean of this component.
1373:             * 
1374:             * @param componentName
1375:             * @param targetName
1376:             * 
1377:             * @return the ObjectName of the Extension MBean or null.
1378:             */
1379:            public ObjectName getExtensionMBeanObjectName(String componentName,
1380:                    String targetName) throws VerifierException {
1381:                ObjectName extensionMBeanObjectNamePattern = null;
1382:                MBeanNames mbeanNames = mEnvCtx.getMBeanNames();
1383:
1384:                String objectNamePatternString = JBIJMXObjectNames.JMX_JBI_DOMAIN
1385:                        + COLON
1386:                        + JBIJMXObjectNames.TARGET_KEY
1387:                        + EQUAL
1388:                        + targetName
1389:                        + COMMA
1390:                        + JBIJMXObjectNames.COMPONENT_ID_KEY
1391:                        + EQUAL
1392:                        + componentName
1393:                        + COMMA
1394:                        + JBIJMXObjectNames.SERVICE_TYPE_KEY
1395:                        + EQUAL
1396:                        + ComponentServiceType.Extension;
1397:
1398:                try {
1399:                    extensionMBeanObjectNamePattern = new ObjectName(
1400:                            objectNamePatternString);
1401:                } catch (MalformedObjectNameException exception) {
1402:                    return null;
1403:                } catch (NullPointerException exception) {
1404:                    return null;
1405:                }
1406:
1407:                MBeanServer mbeanServer = mEnvCtx.getMBeanServer();
1408:
1409:                Set objectNames = mbeanServer.queryNames(
1410:                        extensionMBeanObjectNamePattern, null);
1411:
1412:                if (objectNames.isEmpty()) {
1413:                    throw new VerifierException(
1414:                            mResourceBundle
1415:                                    .getMessage(
1416:                                            LocalStringKeys.VERIFIER_NO_COMPONENT_EXTENSION_OBJECT,
1417:                                            new Object[] {
1418:                                                    componentName,
1419:                                                    extensionMBeanObjectNamePattern
1420:                                                            .toString() }));
1421:
1422:                }
1423:
1424:                if (objectNames.size() > 1) {
1425:                    throw new VerifierException(
1426:                            mResourceBundle
1427:                                    .getMessage(
1428:                                            LocalStringKeys.VERIFIER_MANY_COMPONENT_EXTENSION_OBJECT,
1429:                                            new Object[] {
1430:                                                    componentName,
1431:                                                    extensionMBeanObjectNamePattern
1432:                                                            .toString() }));
1433:
1434:                }
1435:
1436:                ObjectName extensionMBeanObjectName = null;
1437:                extensionMBeanObjectName = (ObjectName) objectNames.iterator()
1438:                        .next();
1439:                ToolsLogManager.getRuntimeLogger().finer(
1440:                        "extensionMBeanObjectName Found : "
1441:                                + extensionMBeanObjectName);
1442:
1443:                return extensionMBeanObjectName;
1444:            }
1445:
1446:            /**
1447:             * Test whether it is a valid target.
1448:             * 
1449:             * @param objectName
1450:             * @return true when the mbean is registered, false otherwise
1451:             * @throws JBIRemoteException
1452:             */
1453:            boolean isValidTarget(ObjectName objectName)
1454:                    throws JBIRemoteException {
1455:                boolean result = false;
1456:                MBeanServer mbeanServer = mEnvCtx.getMBeanServer();
1457:                try {
1458:                    result = mbeanServer.isRegistered(objectName);
1459:                } catch (RuntimeException exception) {
1460:                }
1461:
1462:                return result;
1463:            }
1464:
1465:            /**
1466:             * Invokes the mbean and retrieves the attribute value
1467:             * 
1468:             * @param objectName
1469:             *            object name
1470:             * @param attributeName
1471:             *            attribute name
1472:             * @return the value of the attribute
1473:             * @throws JBIRemoteException
1474:             *             on error
1475:             */
1476:            protected Object getAttributeValue(ObjectName objectName,
1477:                    String attributeName) throws JBIRemoteException {
1478:
1479:                MBeanServer mbeanServer = mEnvCtx.getMBeanServer();
1480:                Object result = null;
1481:                try {
1482:                    result = mbeanServer
1483:                            .getAttribute(objectName, attributeName);
1484:                } catch (AttributeNotFoundException e) {
1485:                    throw new JBIRemoteException(e);
1486:                } catch (InstanceNotFoundException e) {
1487:                    throw new JBIRemoteException(e);
1488:                } catch (MBeanException e) {
1489:                    throw new JBIRemoteException(e);
1490:                } catch (ReflectionException e) {
1491:                    throw new JBIRemoteException(e);
1492:                }
1493:                return result;
1494:            }
1495:
1496:            /**
1497:             * Check if a target is valid or not
1498:             * 
1499:             * @param objectName
1500:             * @throws JBIRemoteException
1501:             */
1502:            void checkForValidTarget(ObjectName objectName, String targetName)
1503:                    throws JBIRemoteException {
1504:                boolean isRegistered = this .isValidTarget(objectName);
1505:                if (isRegistered == false) {
1506:                    String[] args = { targetName };
1507:                    throw new JBIRemoteException(mResourceBundle.getMessage(
1508:                            LocalStringKeys.VERIFIER_INVALID_MBEAN,
1509:                            new Object[] { objectName, targetName }));
1510:
1511:                }
1512:            }
1513:
1514:            /**
1515:             * Convert a application configuration TabularData to a Map keyed by the 
1516:             * "configurationName". The value is the application configuration represented as 
1517:             * properties.
1518:             *
1519:             * @return a Map of application configuration properties
1520:             */
1521:            private Map<String, Properties> getApplicationConfigurationsMap(
1522:                    TabularData td) {
1523:                Map<String, Properties> configMap = new HashMap();
1524:                Set configKeys = td.keySet();
1525:
1526:                for (Object configKey : configKeys) {
1527:                    List keyList = (List) configKey;
1528:
1529:                    String[] index = new String[keyList.size()];
1530:                    index = (String[]) keyList.toArray(index);
1531:                    CompositeData cd = td.get(index);
1532:
1533:                    Properties configProps = new ComponentConfigurationHelper()
1534:                            .convertCompositeDataToProperties(cd);
1535:                    configMap.put(index[0], configProps);
1536:                }
1537:                return configMap;
1538:            }
1539:
1540:            /**
1541:             * This method is used to find out if JavaEEVerifierMBean is available.
1542:             * This method queries the MBean server to see if the MBean with a particular
1543:             * object name is available.
1544:             * @return true if present and false otherwise
1545:             */
1546:            private boolean isJavaEEVerifierAvailable() {
1547:                try {
1548:                    if (isValidTarget(getJavaEEVerifierMBeanName())) {
1549:                        return true;
1550:                    } else {
1551:                        return false;
1552:                    }
1553:                } catch (MalformedObjectNameException malformedObjEx) {
1554:                    return false;
1555:                } catch (JBIRemoteException jbiRe) {
1556:                    return false;
1557:                } catch (Throwable th) {
1558:                    return false;
1559:                }
1560:            }
1561:
1562:            /**
1563:             * This method is used to get the object name for JavaEEVerifier
1564:             * @return ObjectName JavaEEVerifier MBean object name
1565:             */
1566:            private ObjectName getJavaEEVerifierMBeanName()
1567:                    throws MalformedObjectNameException {
1568:                return new ObjectName(JBIJMXObjectNames.JMX_JBI_DOMAIN + COLON
1569:                        + mBeanNames.SERVICE_NAME_KEY + EQUAL + JAVAEE_VERIFIER
1570:                        + COMMA + mBeanNames.COMPONENT_TYPE_KEY + EQUAL
1571:                        + mBeanNames.COMPONENT_TYPE_SYSTEM);
1572:            }
1573:
1574:            /**
1575:             * This method is used to verify all the JavaEEServiceUnits in the given SA.
1576:             * This method calls the JavaEEVerifier for each of the service units and
1577:             * returns the reponse.
1578:             * @param saPath the path to the zip file
1579:             * @param archive JBIArchive
1580:             * @param target the target 
1581:             * @return TabularData[] array with all responses for all JavaEE serviceunits
1582:             */
1583:            private CompositeData[] verifyJavaEEServiceUnits(String saPath,
1584:                    JBIArchive archive, String target) {
1585:                try {
1586:                    ServiceAssemblyDD saDesc = (ServiceAssemblyDD) archive
1587:                            .getJbiDescriptor();
1588:                    List<ServiceAssemblyDD.ServiceUnitDD> suDescs = saDesc
1589:                            .getServiceUnitDDList();
1590:                    ArrayList<CompositeData> verifierReports = new ArrayList<CompositeData>();
1591:
1592:                    for (ServiceAssemblyDD.ServiceUnitDD suDesc : suDescs) {
1593:                        String targetComponent = suDesc.getTargetName();
1594:                        String suName = suDesc.getName();
1595:                        if (targetComponent != null
1596:                                && targetComponent
1597:                                        .equals(JAVAEE_SERVICE_ENGINE)) {
1598:                            TabularData verifierReport = verifyJavaEEServiceUnit(
1599:                                    saPath, suDesc.getArtifactZipName(), target);
1600:                            CompositeData formattedReport = formatJavaEEVerifierReport(
1601:                                    suName, verifierReport);
1602:                            verifierReports.add(formattedReport);
1603:                        }
1604:                    }
1605:                    return (CompositeData[]) verifierReports
1606:                            .toArray(new CompositeData[] {});
1607:                } catch (Throwable ex) {
1608:                    //issues in JavaEEVerification do not affect the entire verifier report
1609:                    ToolsLogManager.getRuntimeLogger().warning(ex.getMessage());
1610:                    return null;
1611:                }
1612:
1613:            }
1614:
1615:            /**
1616:             * This method is used to call the JavaEEVerifier MBean for a given service unit
1617:             * and return the response from JavaEEVerifier.
1618:             * @param saPath sa path
1619:             * @param suZipName su zip Name
1620:             * @param target the target
1621:             * @return TabularData response from JavaEEVerifier
1622:             */
1623:            private TabularData verifyJavaEEServiceUnit(String saPath,
1624:                    String suZipName, String target) throws Exception {
1625:                try {
1626:                    if (saPath == null || suZipName == null) {
1627:                        ToolsLogManager
1628:                                .getRuntimeLogger()
1629:                                .warning(
1630:                                        mResourceBundle
1631:                                                .getMessage(LocalStringKeys.VERIFIER_JAVAEE_EAR_FILE_NOT_FOUND));
1632:                        return null;
1633:                    }
1634:
1635:                    ToolsLogManager.getRuntimeLogger().finer(
1636:                            "Invoking JavaEEVerifier with : " + saPath
1637:                                    + suZipName);
1638:                    TabularData verifierReport = (TabularData) invokeMBeanOperation(
1639:                            getJavaEEVerifierMBeanName(), "verifyServiceUnit",
1640:                            new Object[] { saPath, suZipName, target },
1641:                            new String[] { "java.lang.String",
1642:                                    "java.lang.String", "java.lang.String" });
1643:                    return verifierReport;
1644:                } catch (Throwable t) {
1645:                    ToolsLogManager.getRuntimeLogger().warning(t.getMessage());
1646:                    return null;
1647:                }
1648:            }
1649:
1650:            /**
1651:             * This method is used to format the verifier report for JavaEE service units
1652:             * @param suName service unit name
1653:             * @param verifierReport verifier report returned by JavaEE verifier mbean
1654:             * @return CompositeData that includes suName and the verification report
1655:             */
1656:            private CompositeData formatJavaEEVerifierReport(String suName,
1657:                    TabularData verifierReport) {
1658:                try {
1659:                    CompositeData formattedReport = null;
1660:                    if (verifierReport != null) {
1661:                        OpenType[] itemTypes = new OpenType[] {
1662:                                SimpleType.STRING,
1663:                                verifierReport.getTabularType() };
1664:
1665:                        Object[] values = new Object[] { suName, verifierReport };
1666:
1667:                        CompositeType cType = new CompositeType(
1668:                                "JavaEEVerifier Report",
1669:                                "Java EE Verifier Report",
1670:                                JAVAEE_VERIFIER_ITEM_NAMES,
1671:                                JAVAEE_VERIFIER_ITEM_DESCRIPTIONS, itemTypes);
1672:
1673:                        formattedReport = new CompositeDataSupport(cType,
1674:                                JAVAEE_VERIFIER_ITEM_NAMES, values);
1675:                    }
1676:                    return formattedReport;
1677:                } catch (OpenDataException oe) {
1678:                    ToolsLogManager.getRuntimeLogger().warning(oe.getMessage());
1679:                    return null;
1680:                }
1681:            }
1682:
1683:            /**
1684:             * This method is used to export the application variables and application
1685:             * configuration objects used by the given application in the specified
1686:             * target.
1687:             * 
1688:             * @param applicationName the name of the application
1689:             * @param targetName the target whose configuration has to be exported
1690:             * @param configDir the dir to store the configurations
1691:             * @returns String the id for the zip file with exported configurations
1692:             * 
1693:             * @throws ManagementRemoteException
1694:             *             if the application configuration could not be exported
1695:             * 
1696:             * Note: param configDir is used between ant/cli and common client client.
1697:             * The return value is used between common client server and common client
1698:             * client.
1699:             * 
1700:             */
1701:            public String exportApplicationConfiguration(
1702:                    String applicationName, String targetName, String configDir)
1703:                    throws JBIRemoteException {
1704:                ToolsLogManager.getRuntimeLogger().finer(
1705:                        "Entered exportApplicationConfiguration");
1706:
1707:                mTarget = targetName;
1708:                if (!isApplicationDeployedOnTarget(applicationName, targetName)) {
1709:                    String message = mResourceBundle
1710:                            .getMessage(
1711:                                    LocalStringKeys.VERIFIER_EXPORT_CONFIG_APP_NOT_DEPLOYED,
1712:                                    new Object[] { applicationName, targetName });
1713:                    ToolsLogManager.getRuntimeLogger().warning(message);
1714:                    throw new JBIRemoteException(message);
1715:                }
1716:
1717:                String zipFile = null;
1718:                try {
1719:                    String saDir = locateInRepository(applicationName);
1720:                    ToolsLogManager.getRuntimeLogger().finer(
1721:                            "SA location: " + saDir);
1722:
1723:                    mAppVarTemplatesMap = getApplicationVariablesMap(
1724:                            applicationName, saDir);
1725:                    ToolsLogManager.getRuntimeLogger().finer(
1726:                            "Created list of application variables "
1727:                                    + mAppVarTemplatesMap);
1728:
1729:                    mAppConfigTemplatesMap = getApplicationConfigsMap(
1730:                            applicationName, saDir);
1731:                    ToolsLogManager.getRuntimeLogger().finer(
1732:                            "Created list of application configs "
1733:                                    + mAppConfigTemplatesMap);
1734:
1735:                    mAppConfigTypeMap = getAppConfigTypeMap(mAppConfigTemplatesMap
1736:                            .keySet());
1737:                    ToolsLogManager.getRuntimeLogger().finer(
1738:                            "Created list of application config types ");
1739:
1740:                    mAppVarValuesMap = getAppVarsValueMap(mAppVarTemplatesMap,
1741:                            targetName);
1742:                    mAppConfigValuesMap = getAppConfigValuesMap(
1743:                            mAppConfigTemplatesMap, targetName);
1744:
1745:                    TemplateGenerator generator = new TemplateGenerator(
1746:                            mEnvCtx, mResourceBundle);
1747:                    zipFile = generator.generateTemplates(mAppVarTemplatesMap,
1748:                            mAppConfigTemplatesMap, mAppConfigTypeMap, false, // do not include deploy command
1749:                            mTarget, //target
1750:                            true, // isAnt
1751:                            applicationName, //SA name
1752:                            null, // SA path used only for include deploy
1753:                            true, // fillInValues        
1754:                            mAppVarValuesMap, //app var values
1755:                            mAppConfigValuesMap); //app config values
1756:
1757:                    ToolsLogManager.getRuntimeLogger().finer(
1758:                            "Generated templates in " + zipFile);
1759:                } catch (Throwable th) {
1760:                    String message = mResourceBundle
1761:                            .getMessage(LocalStringKeys.VERIFIER_ERROR_EXPORTING_APP_CONFIG);
1762:                    ToolsLogManager.getRuntimeLogger().log(Level.WARNING,
1763:                            message, th);
1764:                    throw new JBIRemoteException(message);
1765:                }
1766:                return zipFile;
1767:            }
1768:
1769:            /**
1770:             * This method is used to get a list of application variables
1771:             * used in the given service assembly
1772:             * @param applicationName application name     
1773:             * @param saDir sa dir
1774:             * @return Map map of component name to list of app vars
1775:             */
1776:            private Map<String, List<String>> getApplicationVariablesMap(
1777:                    String applicationName, String saDir) {
1778:
1779:                Map<String, List<String>> appVarMap = new HashMap<String, List<String>>();
1780:                try {
1781:                    //this is a map of SU Names to all WSDLs in that SU
1782:                    Map<String, File[]> susWsdlMap = mVerifierUtil
1783:                            .getWSDLs(saDir);
1784:
1785:                    Map<String, String> suCompMap = getServiceUnitComponentMap(
1786:                            applicationName, mTarget);
1787:                    for (String serviceUnit : susWsdlMap.keySet()) {
1788:                        String component = suCompMap.get(serviceUnit);
1789:                        if (component != null
1790:                                && !component.equals(JAVAEE_SERVICE_ENGINE)) {
1791:                            List<String> appVarListForComponent = new ArrayList<String>();
1792:                            File[] wsdls = susWsdlMap.get(serviceUnit);
1793:                            for (int j = 0; j < wsdls.length; j++) {
1794:                                try {
1795:                                    String[] endpointNames = mVerifierUtil
1796:                                            .getEndpointName(wsdls[j]);
1797:                                    for (int iter = 0; iter < endpointNames.length; iter++) {
1798:                                        appVarListForComponent
1799:                                                .addAll(mVerifierUtil
1800:                                                        .getApplicationVariables(
1801:                                                                wsdls[j],
1802:                                                                endpointNames[iter]));
1803:                                    }
1804:                                } catch (VerifierException ex) {
1805:                                    //the wsdl is not proper, on exception move to next wsdl
1806:                                    continue;
1807:                                }
1808:                            }
1809:                            appVarMap.put(component, appVarListForComponent);
1810:                            ToolsLogManager.getRuntimeLogger().finer(
1811:                                    "Application Variables List for Component "
1812:                                            + component + " is "
1813:                                            + appVarListForComponent);
1814:                        }
1815:                    }
1816:                } catch (Exception ex) {
1817:                    //continue with app config processing  
1818:                    String message = mResourceBundle
1819:                            .getMessage(
1820:                                    LocalStringKeys.VERIFIER_ISSUE_COLLECTING_LIST_OF_APP_VARS,
1821:                                    new Object[] { applicationName });
1822:                    ToolsLogManager.getRuntimeLogger().log(Level.WARNING,
1823:                            message, ex);
1824:                }
1825:                return appVarMap;
1826:            }
1827:
1828:            /**
1829:             * This method is used to get a list of application configurations used 
1830:             * in the given SA
1831:             * @param applicationName app name
1832:             * @param saDir sa dir
1833:             * @return Map map of component name to configurations 
1834:             */
1835:            private Map<String, List<String>> getApplicationConfigsMap(
1836:                    String applicationName, String saDir) {
1837:                Map<String, List<String>> appConfigMap = new HashMap<String, List<String>>();
1838:                try {
1839:                    Map<String, String> suCompNameMap = getServiceUnitComponentMap(
1840:                            applicationName, mTarget);
1841:                    for (String serviceUnitName : suCompNameMap.keySet()) {
1842:                        try {
1843:                            String component = suCompNameMap
1844:                                    .get(serviceUnitName);
1845:                            if (component != null
1846:                                    && !component.equals(JAVAEE_SERVICE_ENGINE)) {
1847:                                String suDir = saDir + File.separator
1848:                                        + serviceUnitName + File.separator
1849:                                        + component;
1850:                                Map<String, List<String>> endpointConfigMap = mVerifierUtil
1851:                                        .getEndpointConfigMap(suDir);
1852:                                List<String> appConfigListForComponent = new ArrayList<String>();
1853:                                for (String endpointName : endpointConfigMap
1854:                                        .keySet()) {
1855:                                    List<String> configs = endpointConfigMap
1856:                                            .get(endpointName);
1857:                                    if (configs != null) {
1858:                                        appConfigListForComponent
1859:                                                .addAll(endpointConfigMap
1860:                                                        .get(endpointName));
1861:                                    }
1862:                                }
1863:                                appConfigMap.put(component,
1864:                                        appConfigListForComponent);
1865:                            }
1866:                        } catch (VerifierException vEx) {
1867:                            //move to the next su
1868:                            ToolsLogManager.getRuntimeLogger().warning(
1869:                                    vEx.getMessage());
1870:                            continue;
1871:                        }
1872:                    }
1873:
1874:                } catch (Exception vEx) {
1875:                    //report error and return the current list
1876:                    String message = mResourceBundle
1877:                            .getMessage(
1878:                                    LocalStringKeys.VERIFIER_ISSUE_COLLECTING_LIST_OF_APP_CONFIGS,
1879:                                    new Object[] { applicationName });
1880:                    ToolsLogManager.getRuntimeLogger().log(Level.WARNING,
1881:                            message, vEx);
1882:                }
1883:                return appConfigMap;
1884:            }
1885:
1886:            /**
1887:             * This method is used to find out if the given application is deployed in 
1888:             * the given target 
1889:             * @param applicationName application name
1890:             * @param target target
1891:             * @return true if the application is deployed
1892:             */
1893:            private boolean isApplicationDeployedOnTarget(
1894:                    String applicationName, String target) {
1895:
1896:                try {
1897:                    String[] saList = (String[]) this .getAttributeValue(
1898:                            getDeploymentServiceFacadeMBeanName(target),
1899:                            "DeployedServiceAssemblies");
1900:
1901:                    if (saList != null) {
1902:                        for (int i = 0; i < saList.length; i++) {
1903:                            if (applicationName.equals(saList[i])) {
1904:                                return true;
1905:                            }
1906:                        }
1907:
1908:                    }
1909:                    return false;
1910:                } catch (Throwable ex) {
1911:                    //if SA query fails for any reason do not proceed further with export
1912:                    if (ex.getMessage() != null) {
1913:                        ToolsLogManager.getRuntimeLogger().warning(
1914:                                ex.getMessage());
1915:                    }
1916:                    return false;
1917:                }
1918:
1919:            }
1920:
1921:            /**
1922:             * This method is used to find out the path to the SA in the repository
1923:             * @param saName application name
1924:             * @return String the location
1925:             * @throws VerifierException if there are issues in locating the sa
1926:             */
1927:            private String locateInRepository(String saName)
1928:                    throws VerifierException {
1929:                try {
1930:                    //Note: This method relies upon the SA store dir layout
1931:                    //to access the SU files
1932:                    File saStore = new File(mEnvCtx.getAppServerInstanceRoot(),
1933:                            REPOSITORY_SA_STORE);
1934:                    File saDir = new File(saStore, saName);
1935:                    if (saDir.exists()) {
1936:                        return saDir.getAbsolutePath();
1937:                    } else {
1938:                        throw new VerifierException(
1939:                                mResourceBundle
1940:                                        .getMessage(
1941:                                                LocalStringKeys.VERIFIER_APPLICATION_NOT_LOCATED,
1942:                                                new Object[] { saName }));
1943:                    }
1944:                } catch (Throwable ex) {
1945:                    throw new VerifierException(ex);
1946:                }
1947:            }
1948:
1949:            /**
1950:             * This method is used to create a map of service unit names and 
1951:             * target component in the given application.
1952:             * @param applicationName application name
1953:             * @param targetName target name
1954:             * @return Map<String, String> map of suNames to component names 
1955:             */
1956:            private Map<String, String> getServiceUnitComponentMap(
1957:                    String applicationName, String targetName)
1958:                    throws VerifierException {
1959:                Map<String, String> suCompMap = new HashMap<String, String>();
1960:                try {
1961:                    ComponentQuery compQuery = mEnvCtx
1962:                            .getComponentQuery(targetName);
1963:                    String[] componentList = (String[]) this 
1964:                            .invokeMBeanOperation(
1965:                                    getDeploymentServiceFacadeMBeanName(targetName),
1966:                                    "getComponentsForDeployedServiceAssembly",
1967:                                    new Object[] { applicationName },
1968:                                    new String[] { "java.lang.String" });
1969:
1970:                    for (int i = 0; i < componentList.length; i++) {
1971:                        ComponentInfo compInfo = compQuery
1972:                                .getComponentInfo(componentList[i]);
1973:                        List<ServiceUnitInfo> suInfoList = compInfo
1974:                                .getServiceUnitList();
1975:                        for (ServiceUnitInfo suInfo : suInfoList) {
1976:                            if (suInfo.getServiceAssemblyName().equals(
1977:                                    applicationName)) {
1978:                                suCompMap.put(suInfo.getName(),
1979:                                        componentList[i]);
1980:                            }
1981:                        }
1982:                    }
1983:
1984:                } catch (Throwable ex) {
1985:                    throw new VerifierException(ex);
1986:                }
1987:                return suCompMap;
1988:            }
1989:
1990:            /**
1991:             * This mtehod is used to get the name of the DeploymentService Facade MBean name
1992:             * for this target
1993:             * @param targetName - target name
1994:             * @return the ObjectName of the DeploymentService facade MBean for a target.
1995:             */
1996:            private ObjectName getDeploymentServiceFacadeMBeanName(
1997:                    String targetName) throws VerifierException {
1998:                return mBeanNames.getSystemServiceMBeanName(
1999:                        ServiceName.DeploymentService, ServiceType.Deployment,
2000:                        targetName);
2001:            }
2002:
2003:            /**
2004:             * This method is used to create a map of component names to their
2005:             * app config type
2006:             * @param componentList the list of components
2007:             * @return Map<String, CompositeType> map of component names to Config type
2008:             */
2009:            private Map<String, CompositeType> getAppConfigTypeMap(
2010:                    Set<String> componentList) {
2011:                Map<String, CompositeType> configTypeMap = new HashMap<String, CompositeType>();
2012:                for (String component : componentList) {
2013:                    try {
2014:                        configTypeMap.put(component, getAppConfigType(
2015:                                component, mTarget));
2016:                    } catch (VerifierException verEx) {
2017:                        //move on to next component
2018:                        ToolsLogManager.getRuntimeLogger().warning(
2019:                                verEx.getMessage());
2020:                        continue;
2021:                    } catch (JBIRemoteException jbiRe) {
2022:                        //move on to next component
2023:                        String message = mResourceBundle
2024:                                .getMessage(LocalStringKeys.VERIFIER_ISSUE_COLLECTING_LIST_OF_APP_CONFIG_TYPE);
2025:                        ToolsLogManager.getRuntimeLogger().log(Level.WARNING,
2026:                                message, jbiRe);
2027:                    }
2028:                }
2029:                return configTypeMap;
2030:            }
2031:
2032:            /**
2033:             * This method is used to create a map of component names mapped to
2034:             * a map of app. var names and corresponding values.
2035:             * @param mAppVarTemplatesMap map of component names and list of app. variables
2036:             * @param targetName target name
2037:             * @return Map<String, Map<String, Properties>> map of component names to map
2038:             * of app. vars and corresponding values.
2039:             *
2040:             */
2041:            private Map<String, Map<String, Object>> getAppVarsValueMap(
2042:                    Map<String, List<String>> appVarTemplatesMap,
2043:                    String targetName) {
2044:                Map<String, Map<String, Object>> appVarValuesMap = new HashMap<String, Map<String, Object>>();
2045:                try {
2046:                    for (String component : appVarTemplatesMap.keySet()) {
2047:                        Map<String, Object> valuesNeededForComponent = new HashMap<String, Object>();
2048:                        try {
2049:                            Properties appVarProps = new Properties();
2050:
2051:                            ObjectName configFacadeMBean = this 
2052:                                    .getComponentConfigurationFacadeMBeanName(
2053:                                            component, targetName);
2054:
2055:                            if ((configFacadeMBean != null)
2056:                                    && (true == this 
2057:                                            .isValidTarget(configFacadeMBean))) {
2058:                                TabularData appVarTable = (TabularData) this 
2059:                                        .getAttributeValue(configFacadeMBean,
2060:                                                "ApplicationVariables");
2061:
2062:                                appVarProps = new ComponentConfigurationHelper()
2063:                                        .convertToApplicationVariablesProperties(appVarTable);
2064:
2065:                                for (Object varName : appVarProps.keySet()) {
2066:                                    if (appVarTemplatesMap.get(component)
2067:                                            .contains(varName)) {
2068:                                        valuesNeededForComponent.put(
2069:                                                (String) varName, appVarProps
2070:                                                        .get(varName));
2071:                                    }
2072:                                }
2073:                            }
2074:                            appVarValuesMap.put(component,
2075:                                    valuesNeededForComponent);
2076:                        } catch (Throwable th) {
2077:                            String message = mResourceBundle
2078:                                    .getMessage(
2079:                                            LocalStringKeys.VERIFIER_ISSUE_GETTING_APP_VAR_VALUE,
2080:                                            new Object[] { component });
2081:                            ToolsLogManager.getRuntimeLogger().log(
2082:                                    Level.WARNING, message, th);
2083:                        }
2084:                    }
2085:                } catch (Throwable th) {
2086:                    //return the empty map
2087:                    String message = mResourceBundle
2088:                            .getMessage(LocalStringKeys.VERIFIER_ISSUE_GETTING_APP_VAR_VALUE);
2089:                    ToolsLogManager.getRuntimeLogger().log(Level.WARNING,
2090:                            message, th);
2091:                }
2092:                return appVarValuesMap;
2093:
2094:            }
2095:
2096:            /**
2097:             * This method is used to create a map of component names mapped to
2098:             * a map of app. config names and corresponding values.
2099:             * @param appConfigTemplatesMap map of component names and list of app. variables
2100:             * @param targetName target name
2101:             * @return Map<String, Map<String, Properties>> map of component names to map
2102:             * of app. vars and corresponding values.
2103:             *
2104:             */
2105:            private Map<String, Map<String, Properties>> getAppConfigValuesMap(
2106:                    Map<String, List<String>> appConfigTemplatesMap,
2107:                    String targetName) {
2108:                Map<String, Map<String, Properties>> appConfigValuesMap = new HashMap<String, Map<String, Properties>>();
2109:                try {
2110:                    for (String component : appConfigTemplatesMap.keySet()) {
2111:                        Map<String, Properties> valuesNeededForComponent = new HashMap<String, Properties>();
2112:                        try {
2113:
2114:                            ObjectName configFacadeMBean = this 
2115:                                    .getComponentConfigurationFacadeMBeanName(
2116:                                            component, targetName);
2117:
2118:                            if ((configFacadeMBean != null)
2119:                                    && (true == this 
2120:                                            .isValidTarget(configFacadeMBean))) {
2121:
2122:                                Map<String, Properties> appConfigMap = new HashMap<String, Properties>();
2123:                                TabularData appConfigTable = (TabularData) this 
2124:                                        .getAttributeValue(configFacadeMBean,
2125:                                                "ApplicationConfigurations");
2126:                                appConfigMap = getApplicationConfigurationsMap(appConfigTable);
2127:
2128:                                for (String configName : appConfigMap.keySet()) {
2129:                                    if (appConfigTemplatesMap.get(component)
2130:                                            .contains(configName)) {
2131:                                        valuesNeededForComponent.put(
2132:                                                configName, appConfigMap
2133:                                                        .get(configName));
2134:                                    }
2135:                                }
2136:                            }
2137:                            appConfigValuesMap.put(component,
2138:                                    valuesNeededForComponent);
2139:                        } catch (Throwable th) {
2140:                            String message = mResourceBundle
2141:                                    .getMessage(
2142:                                            LocalStringKeys.VERIFIER_ISSUE_GETTING_APP_CONFIG_VALUE,
2143:                                            new Object[] { component });
2144:                            ToolsLogManager.getRuntimeLogger().warning(message);
2145:                            ToolsLogManager.getRuntimeLogger().log(
2146:                                    Level.WARNING, message, th);
2147:                        }
2148:                    }
2149:                } catch (Throwable th) {
2150:                    //return the empty map
2151:                    String message = mResourceBundle
2152:                            .getMessage(LocalStringKeys.VERIFIER_ISSUE_GETTING_APP_CONFIG_VALUE);
2153:                    ToolsLogManager.getRuntimeLogger().log(Level.WARNING,
2154:                            message, th);
2155:                }
2156:                return appConfigValuesMap;
2157:
2158:            }
2159:
2160:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.