001: /**
002: * Copyright 2004 Sun Microsystems, Inc. All
003: * rights reserved. Use of this product is subject
004: * to license terms. Federal Acquisitions:
005: * Commercial Software -- Government Users
006: * Subject to Standard License Terms and
007: * Conditions.
008: *
009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
010: * are trademarks or registered trademarks of Sun Microsystems,
011: * Inc. in the United States and other countries.
012: */package com.sun.portal.admin.cli.commands.subscriptions;
013:
014: import java.util.*;
015: import java.util.logging.Logger;
016: import java.util.logging.Level;
017:
018: // JMX
019: import javax.management.MBeanServerConnection;
020: import javax.management.ObjectName;
021: import javax.management.InstanceNotFoundException;
022: import javax.management.MBeanException;
023: import javax.management.ReflectionException;
024:
025: // CLI framework
026: import com.sun.enterprise.cli.framework.*;
027: import com.sun.portal.admin.cli.commands.GenericCommand;
028:
029: // PS Admin Common
030: import com.sun.portal.admin.common.util.AdminUtil;
031: import com.sun.portal.admin.common.util.AdminClientUtil;
032:
033: /**
034: * This class implements the psadmin start-profiler subcommand.
035: * <UL>
036: * <LI>Run Profiler
037: * <UL>
038: */
039:
040: public class StartProfilerCommand extends GenericCommand {
041:
042: public Logger logger = super .getLogger();
043: public static final String cmdName = "StartProfilerCommand";
044:
045: //command options
046: String organization = null;
047: String username = null;
048:
049: public void runCommand() throws CommandException,
050: CommandValidationException {
051: validateOptions();
052: validatePortalId();
053:
054: organization = getOption("organization");
055: username = getOption("username");
056:
057: try {
058: LinkedList path = new LinkedList();
059: // setting the CACAO path
060: path.addFirst(getDomainId());
061: path.addFirst(getPortalId());
062: path.addFirst("Profiler");
063: MBeanServerConnection msc = getMBeanServerConnection(
064: getUserId(), getPassword(), getHost());
065:
066: ObjectName objName = AdminClientUtil
067: .getResourceMBeanObjectName(
068: AdminUtil.PROFILER_MBEAN_TYPE, path);
069:
070: Object[] params = { getPortalId(), organization, username,
071: getUserId(), getPassword() };
072: String[] signature = { "java.lang.String",
073: "java.lang.String", "java.lang.String",
074: "java.lang.String", "java.lang.String" };
075:
076: msc.invoke(objName, "startProfiler", params, signature);
077: } catch (InstanceNotFoundException ie) {
078: logger
079: .logp(Level.SEVERE, cmdName, cmdName, ie
080: .getMessage());
081: throw new CommandException(getLocalizedString(
082: ERROR_MBEAN_INSTANCE_NOT_FOUND,
083: new Object[] { "startProfiler" }), ie);
084: } catch (MBeanException me) {
085: logger
086: .logp(Level.SEVERE, cmdName, cmdName, me
087: .getMessage());
088: throw new CommandException(
089: getLocalizedString(ERROR_JMX_INVOKE,
090: new Object[] { "startProfiler" }), me);
091: } catch (ReflectionException re) {
092: logger
093: .logp(Level.SEVERE, cmdName, cmdName, re
094: .getMessage());
095: throw new CommandException(getLocalizedString(
096: ERROR_MBEAN_REFLECTION_ERROR,
097: new Object[] { "startProfiler" }), re);
098: } catch (CommandException ce) {
099: logger
100: .logp(Level.SEVERE, cmdName, cmdName, ce
101: .getMessage());
102: throw ce;
103: } catch (Exception ex) {
104: logger
105: .logp(Level.SEVERE, cmdName, cmdName, ex
106: .getMessage());
107: throw new CommandException(
108: getLocalizedString(COMMAND_FAILED));
109: } finally {
110: closeMBeanServerConnection();
111: }
112: }
113: }
|