01: /**
02: * Copyright 2004 Sun Microsystems, Inc. All
03: * rights reserved. Use of this product is subject
04: * to license terms. Federal Acquisitions:
05: * Commercial Software -- Government Users
06: * Subject to Standard License Terms and
07: * Conditions.
08: *
09: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
10: * are trademarks or registered trademarks of Sun Microsystems,
11: * Inc. in the United States and other countries.
12: */package com.sun.portal.admin.cli.commands.search;
13:
14: import java.util.*;
15:
16: // JMX
17: import javax.management.MBeanServerConnection;
18: import javax.management.ObjectName;
19: import javax.management.InstanceNotFoundException;
20: import javax.management.MBeanException;
21: import javax.management.ReflectionException;
22: import javax.management.MalformedObjectNameException;
23: import javax.management.RuntimeOperationsException;
24:
25: // PS Admin Common
26: import com.sun.portal.admin.common.util.AdminClientUtil;
27:
28: // CLI framework
29: import com.sun.enterprise.cli.framework.*;
30:
31: // Base Class
32: import com.sun.portal.admin.cli.commands.GenericCommand;
33:
34: /**
35: * This class implements the psadmin get-search-importagent-status subcommand.
36: * The get-search-importagent-status subcommand calls the SearchServerMBean
37: * and shows whether an import agent is enabled or disabled.
38: */
39: public class GetImportAgentStatusCommand extends GenericCommand {
40:
41: /**
42: * An abstract method that executes the command
43: * @throws CommandException
44: * @throws CommandValidationException
45: */
46: public void runCommand() throws CommandException,
47: CommandValidationException {
48: validateOptions();
49: validateSearchServerID();
50:
51: StringBuffer sb = new StringBuffer();
52: try {
53: LinkedList path = new LinkedList();
54: path.addFirst(AdminClientUtil.DEFAULT_DOMAIN);
55: path.addFirst(getSearchServerId());
56: ObjectName on = AdminClientUtil.getResourceMBeanObjectName(
57: AdminClientUtil.SEARCHSERVER_MBEAN_TYPE, path);
58:
59: MBeanServerConnection msc = getMBeanServerConnection(
60: getUserId(), getPassword(), getHost());
61:
62: ArrayList al = new ArrayList();
63: al.add("enabled");
64: Object[] params = { getOption("importagent"), al };
65: String[] signatures = { "java.lang.String",
66: "java.util.List" };
67: Properties p = (Properties) msc.invoke(on,
68: "getImportAgent", params, signatures);
69:
70: if (p.getProperty("enabled").equals("true")) {
71: sb.append("enabled\n");
72: } else {
73: sb.append("disabled\n");
74: }
75: } catch (InstanceNotFoundException ie) {
76: throw new CommandException(getLocalizedString(
77: ERROR_MBEAN_INSTANCE_NOT_FOUND,
78: new Object[] { "getImportAgent" }), ie);
79: } catch (MBeanException me) {
80: throw new CommandException(
81: getLocalizedString(ERROR_JMX_INVOKE,
82: new Object[] { "getImportAgent" }), me);
83: } catch (ReflectionException re) {
84: throw new CommandException(getLocalizedString(
85: ERROR_MBEAN_REFLECTION_ERROR,
86: new Object[] { "getImportAgent" }), re);
87: } catch (CommandException ce) {
88: throw ce;
89: } catch (Exception e) {
90: throw new CommandException(
91: getLocalizedString(COMMAND_FAILED), e);
92: } finally {
93: closeMBeanServerConnection();
94: }
95:
96: CLILogger.getInstance().printMessage(sb.toString());
97: }
98:
99: }
|