0001: /*
0002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
0003: *
0004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
0005: *
0006: * The contents of this file are subject to the terms of either the GNU
0007: * General Public License Version 2 only ("GPL") or the Common Development
0008: * and Distribution License("CDDL") (collectively, the "License"). You
0009: * may not use this file except in compliance with the License. You can obtain
0010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
0011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
0012: * language governing permissions and limitations under the License.
0013: *
0014: * When distributing the software, include this License Header Notice in each
0015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
0016: * Sun designates this particular file as subject to the "Classpath" exception
0017: * as provided by Sun in the GPL Version 2 section of the License file that
0018: * accompanied this code. If applicable, add the following below the License
0019: * Header, with the fields enclosed by brackets [] replaced by your own
0020: * identifying information: "Portions Copyrighted [year]
0021: * [name of copyright owner]"
0022: *
0023: * Contributor(s):
0024: *
0025: * If you wish your version of this file to be governed by only the CDDL or
0026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
0027: * elects to include this software in this distribution under the [CDDL or GPL
0028: * Version 2] license." If you don't indicate a single choice of license, a
0029: * recipient has the option to distribute your version of this file under
0030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
0031: * its licensees as provided above. However, if you add GPL Version 2 code
0032: * and therefore, elected the GPL Version 2 license, then the option applies
0033: * only if the new code is made subject to such option by the copyright
0034: * holder.
0035: */
0036:
0037: package com.sun.jbi.cli.commands;
0038:
0039: import com.sun.jbi.cli.commands.JBICommandConstants;
0040: import com.sun.enterprise.cli.framework.CommandValidationException;
0041: import com.sun.enterprise.cli.framework.CommandException;
0042: import com.sun.enterprise.cli.framework.CLILogger;
0043: import com.sun.jbi.ui.client.JBIAdminCommandsClientFactory;
0044: import com.sun.jbi.ui.common.JBIRemoteException;
0045: import com.sun.jbi.ui.common.JBIAdminCommands;
0046: import com.sun.jbi.ui.common.JBIComponentInfo;
0047: import com.sun.esb.management.common.ManagementRemoteException;
0048: import javax.management.MBeanServerConnection;
0049: import javax.management.openmbean.TabularData;
0050: import javax.management.openmbean.CompositeData;
0051: import javax.management.openmbean.CompositeType;
0052: import java.util.Map;
0053: import java.util.Set;
0054: import java.util.Properties;
0055: import java.util.Enumeration;
0056: import java.util.logging.Level;
0057: import java.io.FileInputStream;
0058: import java.io.IOException;
0059:
0060: import java.util.TreeSet;
0061:
0062: /**
0063: * Will perform command on a component
0064: * (service engine, binding component) or a service assembly.
0065: * @version $Revision: 1.20 $
0066: */
0067: public class JBIExtensionCommands extends JBICommand {
0068: // Sierra Commands
0069:
0070: // Option string values
0071:
0072: // Log Level default value
0073: private static final String LOG_LEVEL_DEFAULT = "default";
0074:
0075: JBIAdminCommands mJBICmds = null;
0076:
0077: /**
0078: * A method that Executes the command
0079: * @throws CommandException
0080: */
0081: public void runCommand() throws CommandException,
0082: CommandValidationException {
0083: String result = "";
0084: String successKey = "";
0085: boolean successMsgFlag = false;
0086: try {
0087: // Retrieve the upload boolean option value
0088: boolean isUpload = getBooleanOption(UPLOAD_OPTION);
0089:
0090: // Perform the pre run initialization
0091: if (preRunInit(isUpload)) {
0092: // Retrieve the mJBICmds object which was created during the preRunInit
0093: mJBICmds = (JBIAdminCommands) getJBIAdminCommands();
0094:
0095: if (name
0096: .equals(JBICommandConstants.UPGRADE_JBI_COMPONENT)) {
0097: upgradeComponent();
0098: }
0099:
0100: else if (name
0101: .equals(JBICommandConstants.SHOW_JBI_SERVICE_ASSEMBLY)) {
0102: showServiceAssembly();
0103: successMsgFlag = true;
0104: }
0105:
0106: else if (name
0107: .equals(JBICommandConstants.SHOW_JBI_SHARED_LIBRARY)) {
0108: showSharedLibrary();
0109: successMsgFlag = true;
0110: }
0111:
0112: else if ((name
0113: .equals(JBICommandConstants.SHOW_JBI_SERVICE_ENGINE))
0114: || (name
0115: .equals(JBICommandConstants.SHOW_JBI_BINDING_COMPONENT))) {
0116: showComponent();
0117: successMsgFlag = true;
0118: }
0119:
0120: else if (name
0121: .equals(JBICommandConstants.SHOW_JBI_RUNTIME_CONFIGURATION)) {
0122: showRuntimeConfiguration();
0123: successMsgFlag = true;
0124: }
0125:
0126: else if (name
0127: .equals(JBICommandConstants.SHOW_JBI_APPLICATION_CONFIGURATION)) {
0128: showApplicationConfiguration();
0129: successMsgFlag = true;
0130: }
0131:
0132: else if (name
0133: .equals(JBICommandConstants.SHOW_JBI_RUNTIME_LOGGERS)) {
0134: showRuntimeLoggers();
0135: successMsgFlag = true;
0136: }
0137:
0138: else if (name
0139: .equals(JBICommandConstants.SHOW_JBI_STATISTICS)) {
0140: showStatistics();
0141: successMsgFlag = true;
0142: }
0143:
0144: else if (name
0145: .equals(JBICommandConstants.SET_JBI_RUNTIME_LOGGER)) {
0146: setRuntimeLoggers();
0147: successMsgFlag = true;
0148: }
0149:
0150: else if (name
0151: .equals(JBICommandConstants.SET_JBI_COMPONENT_LOGGER)) {
0152: setComponentLoggers();
0153: successMsgFlag = true;
0154: }
0155:
0156: else if (name
0157: .equals(JBICommandConstants.SET_JBI_RUNTIME_CONFIGURATION)) {
0158: setRuntimeConfiguration();
0159: successMsgFlag = true;
0160: }
0161:
0162: else if (name
0163: .equals(JBICommandConstants.SET_JBI_COMPONENT_CONFIGURATION)) {
0164: setComponentConfiguration();
0165: successMsgFlag = true;
0166: }
0167:
0168: else if (name
0169: .equals(JBICommandConstants.CREATE_APPLICATION_CONFIGURATION)) {
0170: createApplicationConfiguration();
0171: successMsgFlag = true;
0172: }
0173:
0174: else if (name
0175: .equals(JBICommandConstants.UPDATE_APPLICATION_CONFIGURATION)) {
0176: updateApplicationConfiguration();
0177: successMsgFlag = true;
0178: }
0179:
0180: else if (name
0181: .equals(JBICommandConstants.CREATE_APPLICATION_VARIABLE)) {
0182: createApplicationVariable();
0183: successMsgFlag = true;
0184: }
0185:
0186: else if (name
0187: .equals(JBICommandConstants.UPDATE_APPLICATION_VARIABLE)) {
0188: updateApplicationVariable();
0189: successMsgFlag = true;
0190: }
0191:
0192: else if (name
0193: .equals(JBICommandConstants.DELETE_APPLICATION_CONFIGURATION)) {
0194: deleteApplicationConfiguration();
0195: successMsgFlag = true;
0196: }
0197:
0198: else if (name
0199: .equals(JBICommandConstants.DELETE_APPLICATION_VARIABLE)) {
0200: deleteApplicationVariable();
0201: successMsgFlag = true;
0202: }
0203:
0204: else if ((name
0205: .equals(JBICommandConstants.LIST_SERVICE_ENGINES))
0206: || (name
0207: .equals(JBICommandConstants.LIST_BINDING_COMPONENTS))) {
0208: listComponents();
0209: successMsgFlag = true;
0210: }
0211:
0212: else if (name
0213: .equals(JBICommandConstants.LIST_SHARED_LIBRARIES)) {
0214: listSharedLibraries();
0215: successMsgFlag = true;
0216: }
0217:
0218: else if (name
0219: .equals(JBICommandConstants.LIST_SERVICE_ASSEMBLIES)) {
0220: listServiceAssemblies();
0221: successMsgFlag = true;
0222: }
0223:
0224: else if (name
0225: .equals(JBICommandConstants.LIST_APPLICATION_CONFIGURATIONS)) {
0226: listApplicationConfiguration();
0227: successMsgFlag = true;
0228: }
0229:
0230: else if (name
0231: .equals(JBICommandConstants.LIST_APPLICATION_VARIABLES)) {
0232: listApplicationVariables();
0233: successMsgFlag = true;
0234: }
0235:
0236: else if ((name
0237: .equals(JBICommandConstants.START_COMPONENT))
0238: || (name
0239: .equals(JBICommandConstants.STOP_COMPONENT))
0240: || (name
0241: .equals(JBICommandConstants.SHUT_DOWN_COMPONENT))
0242: || (name
0243: .equals(JBICommandConstants.START_SERVICE_ASSEMBLY))
0244: || (name
0245: .equals(JBICommandConstants.STOP_SERVICE_ASSEMBLY))
0246: || (name
0247: .equals(JBICommandConstants.SHUT_DOWN_SERVICE_ASSEMBLY))) {
0248: lifecycleCommand();
0249: successMsgFlag = false;
0250: }
0251:
0252: else if ((name
0253: .equals(JBICommandConstants.INSTALL_COMPONENT))
0254: || (name
0255: .equals(JBICommandConstants.INSTALL_SHARED_LIBRARY))
0256: || (name
0257: .equals(JBICommandConstants.DEPLOY_SERVICE_ASSEMBLY))) {
0258: installCommands();
0259: successMsgFlag = false;
0260: }
0261:
0262: else if ((name
0263: .equals(JBICommandConstants.UNINSTALL_COMPONENT))
0264: || (name
0265: .equals(JBICommandConstants.UNINSTALL_SHARED_LIBRARY)))
0266:
0267: {
0268: uninstallCommand();
0269: successMsgFlag = false;
0270: }
0271:
0272: else if (name
0273: .equals(JBICommandConstants.UNDEPLOY_SERVICE_ASSEMBLY)) {
0274: undeployJBIServiceAssembly();
0275: successMsgFlag = false;
0276: }
0277:
0278: else if (name
0279: .equals(JBICommandConstants.VERIFY_JBI_APPLICATION_ENVIRONMENT)) {
0280: verifyApplicationEnvironment();
0281: successMsgFlag = true;
0282: }
0283:
0284: else if (name
0285: .equals(JBICommandConstants.EXPORT_JBI_APPLICATION_ENVIRONMENT)) {
0286: exportApplicationEnvironment();
0287: successMsgFlag = true;
0288: }
0289:
0290: // Display the default success message it terse is false
0291: if (successMsgFlag) {
0292: CLILogger.getInstance().printDetailMessage(
0293: getLocalizedString("CommandSuccessful",
0294: new Object[] { name }));
0295: }
0296:
0297: }
0298: }
0299:
0300: catch (Exception e) {
0301: //System.out.println ("------------ Debug Info -----------");
0302: //System.out.println ("Exception: " + e);
0303: //System.out.println ("Message: " + e.getMessage());
0304: //System.out.println ("-----------------------------------");
0305: processTaskException(e);
0306:
0307: // Can't add this because this will kick you out of interactive mode
0308: // Looks like a bat file problem that glassfish does not want to fix.
0309: //System.exit(1);
0310: }
0311: }
0312:
0313: /**
0314: * Will list the application configurations for the specified component.
0315: * @throws JBIRemoteException
0316: */
0317: private void upgradeComponent() throws JBIRemoteException,
0318: CommandException {
0319: // Retrieve the operand "componentName"
0320: String compName = (String) getOperands().get(0);
0321:
0322: // Retrieve the required operand "upgradefile"
0323: String archiveFilePath = (String) getOption(JBICommandConstants.UPGRADE_FILE_OPTION);
0324:
0325: // In addition to validating the archiveFilePath,
0326: // this converts a relative file name to an absolute path based on
0327: // the current working directory when the asadmin command was issued
0328: String errorKey = "JBIUpgradeFileNotFound";
0329: archiveFilePath = validateFilePath(errorKey, archiveFilePath);
0330:
0331: String result = mJBICmds.updateComponent(compName,
0332: archiveFilePath);
0333: String successKey = "JBISuccessUpgradedComponent";
0334: processJBIAdminResult(result, successKey);
0335: }
0336:
0337: /**
0338: * Will list the application variables for the specified component.
0339: * @throws JBIRemoteException
0340: */
0341: private void listApplicationVariables() throws JBIRemoteException {
0342: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0343: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0344: Properties result = mJBICmds.getApplicationVariables(compName,
0345: tgtName);
0346: if (result.size() == 0) {
0347: CLILogger.getInstance().printDetailMessage(
0348: getLocalizedString("NoElementsToList"));
0349: } else {
0350: displayProperties(result, 0);
0351: }
0352: }
0353:
0354: /**
0355: * Will list the application configurations for the specified component.
0356: * @throws JBIRemoteException
0357: */
0358: private void listApplicationConfiguration()
0359: throws JBIRemoteException {
0360: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0361: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0362: String[] list = mJBICmds.listApplicationConfigurationNames(
0363: compName, tgtName);
0364: if (list.length == 0) {
0365: CLILogger.getInstance().printDetailMessage(
0366: getLocalizedString("NoElementsToList"));
0367: } else {
0368: for (int i = 0; i < list.length; i++) {
0369: displayMessage(list[i], 0);
0370: }
0371: }
0372: }
0373:
0374: /**
0375: * Will verify application (service-assembly).
0376: * @throws JBIRemoteException, CommandValidationException
0377: */
0378: private void verifyApplicationEnvironment()
0379: throws JBIRemoteException, CommandException {
0380: String templateDir = (String) getOption(JBICommandConstants.TEMPLATE_DIR_OPTION);
0381: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0382: boolean includeDeploy = getBooleanOption(JBICommandConstants.INCLUDE_DEPLOY_OPTION);
0383: String operand = (String) getOperands().get(0);
0384:
0385: // Set the geterate template flag based on if the use specified
0386: // a template directory.
0387: boolean generateTemplate = false;
0388: if ((templateDir != null) && (templateDir.length() > 0)) {
0389: generateTemplate = true;
0390: }
0391: CompositeData result = mJBICmds.verifyApplication(operand,
0392: tgtName, generateTemplate, templateDir, includeDeploy);
0393: processVerifyResults(result);
0394:
0395: // If template files were created, we need to convert the files from the
0396: // ant syntax to asadmin syntax.
0397: if (generateTemplate) {
0398: convertTemplateFilesToAsadmin(templateDir);
0399: CLILogger.getInstance().printDetailMessage(
0400: getLocalizedString("JBIVerifySuccessMessage",
0401: new Object[] { templateDir }));
0402: }
0403: }
0404:
0405: /**
0406: * Will export application (service-assembly).
0407: * @throws JBIRemoteException, CommandValidationException
0408: */
0409: private void exportApplicationEnvironment()
0410: throws JBIRemoteException, CommandException {
0411: String configDir = (String) getOption(JBICommandConstants.CONFIG_DIR_OPTION);
0412: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0413: String operand = (String) getOperands().get(0);
0414:
0415: String result = mJBICmds.exportApplicationConfiguration(
0416: operand, tgtName, configDir);
0417:
0418: convertTemplateFilesToAsadmin(configDir);
0419: CLILogger.getInstance().printDetailMessage(
0420: getLocalizedString("JBIExportSuccessMessage",
0421: new Object[] { configDir }));
0422: }
0423:
0424: /**
0425: * Will show the jbi statistics.
0426: * @throws JBIRemoteException, CommandValidationException
0427: */
0428: private void showStatistics() throws JBIRemoteException {
0429: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0430: String endpointName = (String) getOption(JBICommandConstants.ENDPOINT_OPTION);
0431: String saName = (String) getOption(JBICommandConstants.SERVICE_ASSEMBLY_OPTION);
0432: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0433: boolean framework = getBooleanOption(JBICommandConstants.FRAMEWORK_OPTION);
0434: boolean nmr = getBooleanOption(JBICommandConstants.NMR_OPTION);
0435:
0436: boolean processFlag = false;
0437:
0438: if (framework) {
0439: processFlag = true;
0440: TabularData result = mJBICmds.getFrameworkStats(tgtName);
0441: processFrameworkResults(result);
0442: }
0443:
0444: if (nmr) {
0445: processFlag = true;
0446: TabularData result = mJBICmds.getNMRStats(tgtName);
0447: processNMRResults(result);
0448: }
0449:
0450: if ((compName != null) && (compName.length() > 0)) {
0451: processFlag = true;
0452: TabularData result = mJBICmds.getComponentStats(compName,
0453: tgtName);
0454: processComponentResults(result, compName);
0455: }
0456:
0457: if ((endpointName != null) && (endpointName.length() > 0)) {
0458: processFlag = true;
0459: TabularData result = mJBICmds.getEndpointStats(
0460: endpointName, tgtName);
0461: processEndpointResults(result, endpointName);
0462: }
0463:
0464: if ((saName != null) && (saName.length() > 0)) {
0465: processFlag = true;
0466: TabularData result = mJBICmds.getServiceAssemblyStats(
0467: saName, tgtName);
0468: processServiceAssemblyResults(result, saName);
0469: }
0470:
0471: // Display the error message if no statistic option was specified
0472: if (!(processFlag)) {
0473: CLILogger.getInstance().printMessage(
0474: getLocalizedString(
0475: "JBINoStatisticsOptionSpecified",
0476: new Object[] { name }));
0477: }
0478: }
0479:
0480: /**
0481: * Will show the configurations for the specified application configuration.
0482: * @throws JBIRemoteException, CommandValidationException
0483: */
0484: private void showApplicationConfiguration()
0485: throws JBIRemoteException {
0486: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0487: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0488: String operand = (String) getOperands().get(0);
0489: Properties result = mJBICmds.getApplicationConfiguration(
0490: compName, tgtName, operand);
0491: displayProperties(result, 0);
0492: }
0493:
0494: /**
0495: * Will delete the Application Configuration that was specified on the command line.
0496: * @throws JBIRemoteException
0497: */
0498: private void deleteApplicationConfiguration()
0499: throws JBIRemoteException {
0500: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0501: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0502: String operand = (String) getOperands().get(0);
0503: mJBICmds.deleteApplicationConfiguration(compName, tgtName,
0504: operand);
0505: }
0506:
0507: /**
0508: * Will delete the Application Variable(s) that was specified on the command line.
0509: * @throws JBIRemoteException
0510: */
0511: private void deleteApplicationVariable() throws JBIRemoteException {
0512: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0513: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0514: String operand = (String) getOperands().get(0);
0515: String variables[] = operand.split(",");
0516:
0517: for (int i = 0; i < variables.length; i++) {
0518: variables[i] = variables[i].trim();
0519: }
0520:
0521: mJBICmds.deleteApplicationVariables(compName, tgtName,
0522: variables);
0523: }
0524:
0525: /**
0526: * Will update Application Variable(s).
0527: * @throws JBIRemoteException,CommandValidationException,CommandException
0528: */
0529: private void updateApplicationVariable() throws JBIRemoteException,
0530: CommandValidationException, CommandException {
0531: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0532: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0533: String operand = (String) getOperands().get(0);
0534: Properties properties = new Properties();
0535: try {
0536: properties.load(new FileInputStream(operand));
0537: } catch (IOException e) {
0538: operand = operand.replace(',', ':');
0539: properties = createPropertiesParam(operand);
0540: }
0541: mJBICmds.setApplicationVariables(compName, tgtName, properties);
0542: }
0543:
0544: /**
0545: * Will create Application Variable(s).
0546: * @throws JBIRemoteException,CommandValidationException,CommandException
0547: */
0548: private void createApplicationVariable() throws JBIRemoteException,
0549: CommandValidationException, CommandException {
0550: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0551: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0552: String operand = (String) getOperands().get(0);
0553: Properties properties = new Properties();
0554: try {
0555: properties.load(new FileInputStream(operand));
0556: } catch (IOException e) {
0557: operand = operand.replace(',', ':');
0558: properties = createPropertiesParam(operand);
0559: }
0560:
0561: properties = insertType(properties);
0562: mJBICmds.addApplicationVariables(compName, tgtName, properties);
0563: }
0564:
0565: /**
0566: * Will update an Application Configuration.
0567: * @throws JBIRemoteException,CommandValidationException,CommandException
0568: */
0569: private void updateApplicationConfiguration()
0570: throws JBIRemoteException, CommandValidationException,
0571: CommandException {
0572: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0573: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0574: String configName = (String) getOption(JBICommandConstants.CONFIG_NAME_OPTION);
0575: String operand = (String) getOperands().get(0);
0576:
0577: Properties properties = new Properties();
0578: try {
0579: properties.load(new FileInputStream(operand));
0580: } catch (IOException e) {
0581: operand = operand.replace(',', ':');
0582: properties = createPropertiesParam(operand);
0583: }
0584:
0585: mJBICmds.setApplicationConfiguration(compName, tgtName,
0586: configName, properties);
0587: }
0588:
0589: /**
0590: * Will create an Application Configuration.
0591: * @throws JBIRemoteException,CommandValidationException,CommandException
0592: */
0593: private void createApplicationConfiguration()
0594: throws JBIRemoteException, CommandValidationException,
0595: CommandException {
0596: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0597: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0598: String configName = (String) getOption(JBICommandConstants.CONFIG_NAME_OPTION);
0599: String operand = (String) getOperands().get(0);
0600: Properties properties = new Properties();
0601: try {
0602: properties.load(new FileInputStream(operand));
0603: } catch (IOException e) {
0604: operand = operand.replace(',', ':');
0605: properties = createPropertiesParam(operand);
0606: }
0607: mJBICmds.addApplicationConfiguration(compName, tgtName,
0608: configName, properties);
0609: }
0610:
0611: /**
0612: * Will set a component logger level value(s).
0613: * @throws JBIRemoteException,CommandValidationException,CommandException
0614: */
0615: private void setComponentLoggers() throws JBIRemoteException,
0616: CommandValidationException, CommandException {
0617: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0618: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0619: String operand = (String) getOperands().get(0);
0620: Properties properties = new Properties();
0621: try {
0622: properties.load(new FileInputStream(operand));
0623: } catch (IOException e) {
0624: operand = operand.replace(',', ':');
0625: properties = createPropertiesParam(operand);
0626: }
0627: Enumeration e = properties.propertyNames();
0628: while (e.hasMoreElements()) {
0629: String loggerName = (String) e.nextElement();
0630: String loggerLevel = (String) properties
0631: .getProperty(loggerName);
0632: Level logLevel = null;
0633: if (!(loggerLevel.equalsIgnoreCase(LOG_LEVEL_DEFAULT))) {
0634: logLevel = Level.parse(loggerLevel);
0635: }
0636: mJBICmds.setComponentLoggerLevel(compName, loggerName,
0637: logLevel, tgtName, tgtName);
0638: }
0639: }
0640:
0641: /**
0642: * Will set the runtime logger level value(s).
0643: * @throws JBIRemoteException,CommandValidationException,CommandException
0644: */
0645: private void setRuntimeLoggers() throws JBIRemoteException,
0646: CommandValidationException, CommandException {
0647: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0648: String operand = (String) getOperands().get(0);
0649: Properties properties = new Properties();
0650: try {
0651: properties.load(new FileInputStream(operand));
0652: } catch (IOException e) {
0653: operand = operand.replace(',', ':');
0654: properties = createPropertiesParam(operand);
0655: }
0656: Enumeration e = properties.propertyNames();
0657: while (e.hasMoreElements()) {
0658: String loggerName = (String) e.nextElement();
0659: String loggerLevel = (String) properties
0660: .getProperty(loggerName);
0661: Level logLevel = null;
0662: if (!(loggerLevel.equalsIgnoreCase(LOG_LEVEL_DEFAULT))) {
0663: logLevel = Level.parse(loggerLevel);
0664: }
0665: mJBICmds.setRuntimeLoggerLevel(loggerName, logLevel,
0666: tgtName);
0667: }
0668: }
0669:
0670: /**
0671: * Will set a component configuration value(s).
0672: * @throws JBIRemoteException,CommandValidationException,CommandException
0673: */
0674: private void setComponentConfiguration() throws JBIRemoteException,
0675: CommandValidationException, CommandException {
0676: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0677: String compName = (String) getOption(JBICommandConstants.COMPONENT_OPTION);
0678: String operand = (String) getOperands().get(0);
0679: Properties properties = new Properties();
0680: try {
0681: properties.load(new FileInputStream(operand));
0682: } catch (IOException e) {
0683: operand = operand.replace(',', ':');
0684: properties = createPropertiesParam(operand);
0685: }
0686: mJBICmds.setComponentConfiguration(tgtName, compName,
0687: properties);
0688: }
0689:
0690: /**
0691: * Will set the runtime configuration value(s).
0692: * @throws JBIRemoteException,CommandValidationException,CommandException
0693: */
0694: private void setRuntimeConfiguration() throws JBIRemoteException,
0695: CommandValidationException, CommandException {
0696: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0697: String operand = (String) getOperands().get(0);
0698: Properties properties = new Properties();
0699: try {
0700: properties.load(new FileInputStream(operand));
0701: } catch (IOException e) {
0702: operand = operand.replace(',', ':');
0703: properties = createPropertiesParam(operand);
0704: }
0705: mJBICmds.setRuntimeConfiguration(properties, tgtName);
0706: }
0707:
0708: /**
0709: * Will display the runtime configuration values.
0710: * @throws JBIRemoteException
0711: */
0712: private void showRuntimeConfiguration() throws JBIRemoteException {
0713: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0714: Properties result = mJBICmds.getRuntimeConfiguration(tgtName);
0715: displayProperties(result, 0);
0716: }
0717:
0718: /**
0719: * Will display the Runtime logger levels.
0720: * @throws JBIRemoteException
0721: */
0722: private void showRuntimeLoggers() throws JBIRemoteException {
0723: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0724: Map result = mJBICmds.getRuntimeLoggerLevels(tgtName);
0725: if (result.containsValue(null)) {
0726: processLogLevelValues(result);
0727: }
0728: displayMap(result, 0);
0729: }
0730:
0731: /**
0732: * If the log level is null then replace it with DEFAULT.
0733: */
0734: private void processLogLevelValues(Map map) {
0735: Set<String> keys = map.keySet();
0736: for (String key : keys) {
0737: if (map.get(key) == null) {
0738: map.put(key, LOG_LEVEL_DEFAULT.toUpperCase());
0739: }
0740: }
0741: }
0742:
0743: /**
0744: * Will display information for the specified service assembly.
0745: * @throws JBIRemoteException,CommandValidationException
0746: */
0747: private void showServiceAssembly() throws JBIRemoteException,
0748: CommandValidationException {
0749: String saName = (String) getOperands().get(0);
0750: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0751: boolean descriptor = getBooleanOption(JBICommandConstants.DESCRIPTOR_OPTION);
0752:
0753: String result = mJBICmds.showServiceAssembly(saName, "", "",
0754: tgtName);
0755: processJBIAdminShowAssemblyResult(result, saName);
0756:
0757: if (descriptor) {
0758: displayOptionHeader("JBIShowComponentDescriptorHeader", 0);
0759: result = mJBICmds
0760: .getServiceAssemblyDeploymentDescriptor(saName);
0761: displayDescriptor(result);
0762: }
0763:
0764: }
0765:
0766: /**
0767: * Will display information for the specified shared library.
0768: * @throws JBIRemoteException,CommandValidationException
0769: */
0770: private void showSharedLibrary() throws JBIRemoteException,
0771: CommandValidationException {
0772: String compName = (String) getOperands().get(0);
0773: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0774: boolean descriptor = getBooleanOption(JBICommandConstants.DESCRIPTOR_OPTION);
0775:
0776: String result = mJBICmds.showSharedLibrary(compName, "",
0777: tgtName);
0778: processJBIAdminShowLibraryResult(result, compName);
0779:
0780: if (descriptor) {
0781: displayOptionHeader("JBIShowComponentDescriptorHeader", 0);
0782: result = mJBICmds
0783: .getSharedLibraryInstallationDescriptor(compName);
0784: displayDescriptor(result);
0785: }
0786: }
0787:
0788: /**
0789: * Will display information for the specified component.
0790: * @throws JBIRemoteException,CommandValidationException
0791: */
0792: private void showComponent() throws JBIRemoteException,
0793: CommandValidationException, CommandException {
0794: String compName = (String) getOperands().get(0);
0795: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0796: boolean loggers = getBooleanOption(JBICommandConstants.LOGGERS_OPTION);
0797: boolean configuration = getBooleanOption(JBICommandConstants.CONFIGURATION_OPTION);
0798: boolean descriptor = getBooleanOption(JBICommandConstants.DESCRIPTOR_OPTION);
0799:
0800: // Retrieve and display the general information
0801: String resultStr = "";
0802: if (name.equals(JBICommandConstants.SHOW_JBI_SERVICE_ENGINE)) {
0803: resultStr = mJBICmds.showServiceEngine(compName, "", "",
0804: "", tgtName);
0805: } else {
0806: resultStr = mJBICmds.showBindingComponent(compName, "", "",
0807: "", tgtName);
0808: }
0809: processJBIAdminShowComponentResult(resultStr, compName);
0810:
0811: if (loggers) {
0812: displayOptionHeader("JBIShowComponentLoggerHeader", 0);
0813: Map result = mJBICmds.getComponentLoggerLevels(compName,
0814: tgtName, tgtName);
0815: displayMap(result, 0);
0816: }
0817:
0818: if (configuration) {
0819: displayOptionHeader("JBIShowComponentConfigurationHeader",
0820: 0);
0821: Properties result = mJBICmds.getComponentConfiguration(
0822: compName, tgtName);
0823: if (result.size() == 0) {
0824: if (mInfo.getState().equals(
0825: JBIComponentInfo.SHUTDOWN_STATE)) {
0826: CLILogger
0827: .getInstance()
0828: .printMessage(
0829: getLocalizedString("JBIShowComponentConfigShutDownWarning"));
0830: }
0831: } else {
0832: displayProperties(result, 0);
0833: }
0834: }
0835:
0836: if (descriptor) {
0837: displayOptionHeader("JBIShowComponentDescriptorHeader", 0);
0838: String result = mJBICmds
0839: .getComponentInstallationDescriptor(compName);
0840: displayDescriptor(result);
0841: }
0842:
0843: displayMessage(" ", 0);
0844: }
0845:
0846: /**
0847: * Will display information for the specified component.
0848: * @throws JBIRemoteException,CommandValidationException
0849: */
0850: private void installCommands() throws JBIRemoteException,
0851: CommandValidationException, CommandException {
0852:
0853: String operand = (String) getOperands().get(0);
0854: String tgtName = (String) getOption(JBICommandConstants.TARGET_OPTION);
0855:
0856: String result = "";
0857: String successKey = "";
0858: String errorKey = "";
0859: boolean installFromDomain = false;
0860:
0861: // Make sure the file specified is valid. If it is not a valid file, then
0862: // we should try to install/deploy the component/assembly from the domain.
0863: // If that should fail, then we will throw the original commandException,
0864: // saying that the filePath specified was not valid.
0865: try {
0866: if (name
0867: .equals(JBICommandConstants.DEPLOY_SERVICE_ASSEMBLY)) {
0868: errorKey = "JBIDeloymentFileNotFound";
0869: } else {
0870: errorKey = "JBIInstallationFileNotFound";
0871: }
0872: operand = validateFilePath(errorKey, operand);
0873: } catch (CommandException ce) {
0874: if (!(tgtName
0875: .equalsIgnoreCase(JBIAdminCommands.DOMAIN_TARGET_KEY))) {
0876: installFromDomain = true;
0877:
0878: if (name.equals(JBICommandConstants.INSTALL_COMPONENT)) {
0879: result = mJBICmds.installComponentFromDomain(
0880: operand, tgtName);
0881: successKey = "JBISuccessInstallDomainComponent";
0882: }
0883:
0884: else if (name
0885: .equals(JBICommandConstants.INSTALL_SHARED_LIBRARY)) {
0886: result = mJBICmds.installSharedLibraryFromDomain(
0887: operand, tgtName);
0888: successKey = "JBISuccessInstallDomainSharedLibrary";
0889: }
0890:
0891: else if (name
0892: .equals(JBICommandConstants.DEPLOY_SERVICE_ASSEMBLY)) {
0893: result = mJBICmds.deployServiceAssemblyFromDomain(
0894: operand, tgtName);
0895: successKey = "JBISuccessDeployServiceAssembly";
0896: }
0897: processJBIAdminResult(result, successKey);
0898: }
0899: }
0900:
0901: if (!(installFromDomain)) {
0902: // Using the command name, we'll determine how to process the command
0903: if (name.equals(JBICommandConstants.INSTALL_COMPONENT)) {
0904:
0905: // When installing a component, two api's exist, one when installing
0906: // a component with no associated properties, and one when installing
0907: // a component with associated properties.
0908: Properties properties = getAnyProperties();
0909: result = mJBICmds.installComponent(operand, properties,
0910: tgtName);
0911: successKey = "JBISuccessInstallComponent";
0912: }
0913:
0914: else if (name
0915: .equals(JBICommandConstants.INSTALL_SHARED_LIBRARY)) {
0916: result = mJBICmds
0917: .installSharedLibrary(operand, tgtName);
0918: successKey = "JBISuccessInstallSharedLibrary";
0919: }
0920:
0921: else if (name
0922: .equals(JBICommandConstants.DEPLOY_SERVICE_ASSEMBLY)) {
0923: result = mJBICmds.deployServiceAssembly(operand,
0924: tgtName);
0925: successKey = "JBISuccessDeployServiceAssembly";
0926: }
0927: processJBIAdminResult(result, successKey);
0928: }
0929: }
0930:
0931: /**
0932: * Will uninstall a component or a shared library.
0933: * @throws JBIRemoteException,CommandValidationException
0934: */
0935: private void uninstallCommand() throws JBIRemoteException,
0936: CommandValidationException {
0937: String result = "";
0938: String successKey = "";
0939:
0940: String compName = (String) getOperands().get(0);
0941: String tgtName = getOption(JBICommandConstants.TARGET_OPTION);
0942: boolean force = getBooleanOption(JBICommandConstants.FORCE_OPTION);
0943: boolean keepArchive = getBooleanOption(JBICommandConstants.KEEP_ARCHIVE_OPTION);
0944:
0945: if (name.equals(JBICommandConstants.UNINSTALL_COMPONENT)) {
0946: result = ((JBIAdminCommands) mJBICmds).uninstallComponent(
0947: compName, force, keepArchive, tgtName);
0948: successKey = "JBISuccessUninstallComponent";
0949: }
0950:
0951: else if (name
0952: .equals(JBICommandConstants.UNINSTALL_SHARED_LIBRARY)) {
0953: result = ((JBIAdminCommands) mJBICmds)
0954: .uninstallSharedLibrary(compName, force,
0955: keepArchive, tgtName);
0956: successKey = "JBISuccessUninstallSharedLibrary";
0957: }
0958:
0959: // Display the success message
0960: CLILogger.getInstance().printDetailMessage(
0961: getLocalizedString(successKey,
0962: new Object[] { compName }));
0963:
0964: }
0965:
0966: /**
0967: * Will undeploy a service assembly.
0968: * @throws JBIRemoteException,CommandValidationException
0969: */
0970: private void undeployJBIServiceAssembly()
0971: throws JBIRemoteException, CommandValidationException {
0972: String compName = (String) getOperands().get(0);
0973: String tgtName = getOption(JBICommandConstants.TARGET_OPTION);
0974: boolean force = getBooleanOption(JBICommandConstants.FORCE_OPTION);
0975: boolean keepArchive = getBooleanOption(JBICommandConstants.KEEP_ARCHIVE_OPTION);
0976:
0977: String result = ((JBIAdminCommands) mJBICmds)
0978: .undeployServiceAssembly(compName, force, keepArchive,
0979: tgtName);
0980: String successKey = "JBISuccessUndeployServiceAssembly";
0981:
0982: // Display the success message
0983: CLILogger.getInstance().printDetailMessage(
0984: getLocalizedString(successKey,
0985: new Object[] { compName }));
0986:
0987: }
0988:
0989: /**
0990: * Will list the jbi components.
0991: * @throws JBIRemoteException,CommandValidationException
0992: */
0993: private void listComponents() throws JBIRemoteException,
0994: CommandValidationException {
0995: // Retrieve the options used for this command
0996: String tgtName = getOption(JBICommandConstants.TARGET_OPTION);
0997: String libraryName = getOption(JBICommandConstants.LIBRARY_NAME_OPTION);
0998: String assemblyName = getOption(JBICommandConstants.ASSEMBLY_NAME_OPTION);
0999: String lifecycleState = getOption(
1000: JBICommandConstants.LIFECYCLE_STATE_OPTION,
1001: mValidStates);
1002:
1003: String result = "";
1004:
1005: if (name.equals(JBICommandConstants.LIST_SERVICE_ENGINES)) {
1006: result = ((JBIAdminCommands) mJBICmds).listServiceEngines(
1007: lifecycleState, libraryName, assemblyName, tgtName);
1008: processJBIAdminComponentListResult(result);
1009: }
1010:
1011: else if (name
1012: .equals(JBICommandConstants.LIST_BINDING_COMPONENTS)) {
1013: result = ((JBIAdminCommands) mJBICmds)
1014: .listBindingComponents(lifecycleState, libraryName,
1015: assemblyName, tgtName);
1016: processJBIAdminComponentListResult(result);
1017: }
1018:
1019: }
1020:
1021: /**
1022: * Will list the shared libraries.
1023: * @throws JBIRemoteException,CommandValidationException
1024: */
1025: private void listSharedLibraries() throws JBIRemoteException,
1026: CommandValidationException {
1027: // Retrieve the options used for this command
1028: String tgtName = getOption(JBICommandConstants.TARGET_OPTION);
1029: String compName = getOption(JBICommandConstants.COMPONENT_NAME_OPTION);
1030:
1031: String result = ((JBIAdminCommands) mJBICmds)
1032: .listSharedLibraries(compName, tgtName);
1033: processJBIAdminComponentListResult(result);
1034:
1035: }
1036:
1037: /**
1038: * Will list the shared libraries.
1039: * @throws JBIRemoteException,CommandValidationException
1040: */
1041: private void listServiceAssemblies() throws JBIRemoteException,
1042: CommandValidationException {
1043: // Retrieve the options used for this command
1044: String tgtName = getOption(JBICommandConstants.TARGET_OPTION);
1045: String compName = getOption(JBICommandConstants.COMPONENT_NAME_OPTION);
1046: String lifecycleState = getOption(
1047: JBICommandConstants.LIFECYCLE_STATE_OPTION,
1048: mValidStates);
1049:
1050: String result = ((JBIAdminCommands) mJBICmds)
1051: .listServiceAssemblies(lifecycleState, compName,
1052: tgtName);
1053: processJBIAdminAsseblyListResult(result);
1054:
1055: }
1056:
1057: /**
1058: * Will list the shared libraries.
1059: * @throws JBIRemoteException,CommandValidationException
1060: */
1061: private void lifecycleCommand() throws JBIRemoteException,
1062: CommandValidationException, CommandException {
1063: String result = "";
1064: String successKey = "";
1065:
1066: String tgtName = getOption(JBICommandConstants.TARGET_OPTION);
1067: boolean force = getBooleanOption(JBICommandConstants.FORCE_OPTION);
1068: String compName = (String) getOperands().get(0);
1069:
1070: if (name.equals(JBICommandConstants.START_COMPONENT)) {
1071: result = ((JBIAdminCommands) mJBICmds).startComponent(
1072: compName, tgtName);
1073: successKey = "JBISuccessStartedComponent";
1074: }
1075:
1076: else if (name.equals(JBICommandConstants.STOP_COMPONENT)) {
1077: result = ((JBIAdminCommands) mJBICmds).stopComponent(
1078: compName, tgtName);
1079: successKey = "JBISuccessStoppedComponent";
1080: }
1081:
1082: else if (name.equals(JBICommandConstants.SHUT_DOWN_COMPONENT)) {
1083: result = ((JBIAdminCommands) mJBICmds).shutdownComponent(
1084: compName, force, tgtName);
1085: successKey = "JBISuccessShutDownComponent";
1086: } else if (name
1087: .equals(JBICommandConstants.START_SERVICE_ASSEMBLY)) {
1088: result = ((JBIAdminCommands) mJBICmds)
1089: .startServiceAssembly(compName, tgtName);
1090: successKey = "JBISuccessStartAssemblyComponent";
1091: }
1092:
1093: else if (name.equals(JBICommandConstants.STOP_SERVICE_ASSEMBLY)) {
1094: result = ((JBIAdminCommands) mJBICmds).stopServiceAssembly(
1095: compName, tgtName);
1096: successKey = "JBISuccessStoppedAssembly";
1097: }
1098:
1099: else if (name
1100: .equals(JBICommandConstants.SHUT_DOWN_SERVICE_ASSEMBLY)) {
1101: result = ((JBIAdminCommands) mJBICmds)
1102: .shutdownServiceAssembly(compName, force, tgtName);
1103: successKey = "JBISuccessShutDownAssembly";
1104: }
1105:
1106: processJBIAdminResult(result, successKey);
1107: }
1108:
1109: }
|