001: /**
002: * $Id: RedeployCommand.java,v 1.10 2006/10/25 21:24:26 cathywu Exp $
003: * Copyright 2004 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.admin.cli.commands;
014:
015: import java.text.MessageFormat;
016: import java.util.logging.Level;
017: import java.util.logging.Logger;
018:
019: //JMX
020: import javax.management.MBeanServerConnection;
021: import javax.management.ObjectName;
022: import javax.management.InstanceNotFoundException;
023: import javax.management.MBeanException;
024: import javax.management.ReflectionException;
025: import javax.management.MalformedObjectNameException;
026:
027: //PS Admin Common
028: import com.sun.portal.admin.common.util.AdminClientUtil;
029: import com.sun.portal.admin.common.PSMBeanException;
030:
031: //CLI framework
032: import com.sun.enterprise.cli.framework.*;
033:
034: /**
035: * This class implements the psadmin create-portal subcommand. The
036: * create-portal subcommand calls the PortalDomainMBean and performs
037: * the following tasks:
038: * <UL>
039: * <LI>loads the display profile basic services
040: * and providers
041: * <LI>creates necessary portal specific file directory
042: * <LI>associates the portal in the portal domain
043: * <LI>creates the portal war file
044: * <UL>
045: */
046:
047: public class RedeployCommand extends AdminBaseCommand {
048: public static final String OPT_ALLWEBAPPS = "allwebapps";
049: public static final String ATTR_PORTALURI = "PortalWebAppUri";
050:
051: /**
052: * Executes the subcommand.
053: *
054: * @exception CommandException If error occurrs during the execution.
055: */
056: public void runCommand() throws CommandException,
057: CommandValidationException {
058: String instanceId = getInstanceId();
059:
060: validateOptions();
061: validatePortalId();
062: if (instanceId != null) {
063: validateInstance();
064: }
065:
066: String operation = "";
067:
068: try {
069:
070: // Get the MBean server connection
071: MBeanServerConnection msc = getMBeanServerConnection(
072: getUserId(), getPassword(), getHost());
073:
074: // Get the MBean object for the portal
075: ObjectName pObjName = AdminClientUtil
076: .getPortalMBeanObjectName(
077: AdminClientUtil.DEFAULT_DOMAIN,
078: getPortalId());
079:
080: // Setting the params and signature
081: Object[] params = new Object[] {};
082: String[] signature = new String[] {};
083:
084: if (getBooleanOption(OPT_ALLWEBAPPS)) {
085: // Setting the params and signature
086: Object[] iparams = { instanceId };
087: String[] isignature = { "java.lang.String" };
088: operation = "undeployAllWebApps";
089:
090: // Invoke the undeployAllInstances method on the instance MBean
091: msc.invoke(pObjName, operation, iparams, isignature);
092:
093: operation = "deployAllWebApps";
094:
095: // Invoke the deployAllInstances method on the instance MBean
096: msc.invoke(pObjName, operation, iparams, isignature);
097: } else if (instanceId != null) {
098: // Invoke the recreateWebApp operation on the newly
099: // created portal. This method returns the URI at
100: // which this created Webapp should be deployed. Use
101: // it as the input to the deploy command
102: operation = "createPortalWebApp";
103: String uri = (String) msc.invoke(pObjName, operation,
104: params, signature);
105:
106: // Get the Instance MBean object
107: ObjectName objName = AdminClientUtil
108: .getInstanceMBeanObjectName(
109: AdminClientUtil.DEFAULT_DOMAIN,
110: getPortalId(), getInstanceId());
111:
112: // Setting the params and signature
113: Object[] iparams = { uri };
114: String[] isignature = { "java.lang.String" };
115: operation = "undeploy";
116:
117: // Invoke the undeploy method on the instance MBean
118: msc.invoke(objName, operation, iparams, isignature);
119:
120: operation = "deploy";
121: // Invoke the deploy method on the instance MBean
122: msc.invoke(objName, operation, iparams, isignature);
123: } else {
124: Object[] iparams = {};
125: String[] isignature = {};
126: operation = "undeployPortalWebApp";
127:
128: // Invoke the undeployPortalAll method on the instance MBean
129: msc.invoke(pObjName, operation, iparams, isignature);
130:
131: operation = "deployPortalWebApp";
132: // Invoke the deployPortalAll method on the instance MBean
133: msc.invoke(pObjName, operation, iparams, isignature);
134: }
135: } catch (InstanceNotFoundException ie) {
136: throw new CommandException(getLocalizedString(
137: ERROR_MBEAN_INSTANCE_NOT_FOUND,
138: new Object[] { operation }), ie);
139: } catch (MBeanException me) {
140: Object tok[] = { operation };
141: logger.log(Level.SEVERE, "PSALI_CSPACC0006", me);
142:
143: boolean pe = me.getCause() instanceof PSMBeanException;
144: if (getBooleanOption(OPT_DEBUG)) {
145: if (pe) {
146: String dbgMsg = me.getCause().getMessage();
147: if (dbgMsg != null) {
148: CLILogger.getInstance().printMessage(dbgMsg);
149: }
150: }
151: }
152: if (pe) {
153: Object tokens[] = ((PSMBeanException) me.getCause())
154: .getTokens();
155: if (tokens != null) {
156: throw new CommandException(getLocalizedString(
157: ((PSMBeanException) me.getCause())
158: .getErrorKey(), tokens), me);
159: } else {
160: throw new CommandException(
161: getLocalizedString(((PSMBeanException) me
162: .getCause()).getErrorKey()), me);
163: }
164: } else {
165: throw new CommandException(getLocalizedString(
166: ERROR_JMX_INVOKE, tok), me);
167: }
168: } catch (ReflectionException re) {
169: throw new CommandException(getLocalizedString(
170: ERROR_MBEAN_REFLECTION_ERROR,
171: new Object[] { operation }), re);
172: } catch (MalformedObjectNameException mle) {
173: throw new CommandException(
174: getLocalizedString(ERROR_OBJECT_NAME), mle);
175: } catch (CommandException ce) {
176: throw ce;
177: } catch (Exception ex) {
178: throw new CommandException(
179: getLocalizedString(COMMAND_FAILED), ex);
180: } finally {
181: closeMBeanServerConnection();
182: }
183: }
184:
185: }
|