You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by va...@apache.org on 2011/01/06 13:11:39 UTC
svn commit: r1055843 - in /geronimo/server/branches/2.1/framework/modules:
geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/
geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/
Author: vamsic007
Date: Thu Jan 6 12:11:39 2011
New Revision: 1055843
URL: http://svn.apache.org/viewvc?rev=1055843&view=rev
Log:
GERONIMO-5749 Command Line utility to enable/disable Monitoring server and Stat query Snapshot thread for DefaultServer
o Added a deployer command to enable/disable stats query snapshot thread for Default Server
Added:
geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/StatsQueryCommandMetaData.java (with props)
geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandStatsQuery.java (with props)
Modified:
geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java
geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployTool.java
Modified: geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java?rev=1055843&r1=1055842&r2=1055843&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/DeployerCLParser.java Thu Jan 6 12:11:39 2011
@@ -1,376 +1,377 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.geronimo.cli.deployer;
-
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.geronimo.cli.BaseCLParser;
-import org.apache.geronimo.cli.CLParserException;
-import org.apache.geronimo.cli.PrintHelper;
-
-
-/**
- * @version $Rev: 476049 $ $Date: 2006-11-17 15:35:17 +1100 (Fri, 17 Nov 2006) $
- */
-public class DeployerCLParser extends BaseCLParser implements ConnectionParams {
- private final static String ARGUMENT_URI_SHORTFORM = "U";
- private final static String ARGUMENT_URI = "uri";
-
- private final static String ARGUMENT_HOST_SHORTFORM = "host";
-
- private final static String ARGUMENT_PORT_SHORTFORM = "port";
- private final static String ARGUMENT_PORT = "port";
-
- private final static String ARGUMENT_DRIVER_SHORTFORM = "d";
- private final static String ARGUMENT_DRIVER = "driver";
-
- private final static String ARGUMENT_USER_SHORTFORM = "u";
- private final static String ARGUMENT_USER = "user";
-
- private final static String ARGUMENT_PASSWORD_SHORTFORM = "p";
- private final static String ARGUMENT_PASSWORD = "password";
-
- private final static String ARGUMENT_SYSERR_SHORTFORM = "s";
- private final static String ARGUMENT_SYSERR = "syserr";
-
- private final static String ARGUMENT_VERBOSE_SHORTFORM = "v";
- private final static String ARGUMENT_VERBOSE = "verbose";
-
- private final static String ARGUMENT_OFFLINE_SHORTFORM = "o";
- private final static String ARGUMENT_OFFLINE = "offline";
-
- private final static String ARGUMENT_SECURE_SHORTFORM = "secure";
- private final static String ARGUMENT_SECURE = "secure";
-
- private final Collection<CommandMetaData> commandMetaData;
-
- private CommandArgs commandArgs;
- private CommandMetaData metaData;
-
- public DeployerCLParser(OutputStream out) {
- super(out);
-
- commandMetaData = new ArrayList<CommandMetaData>();
- commandMetaData.add(LoginCommandMetaData.META_DATA);
- commandMetaData.add(DeployCommandMetaData.META_DATA);
- commandMetaData.add(DistributeCommandMetaData.META_DATA);
- commandMetaData.add(ListModulesCommandMetaData.META_DATA);
- commandMetaData.add(ListTargetsCommandMetaData.META_DATA);
- commandMetaData.add(RedeployCommandMetaData.META_DATA);
- commandMetaData.add(StartCommandMetaData.META_DATA);
- commandMetaData.add(StopCommandMetaData.META_DATA);
- commandMetaData.add(RestartCommandMetaData.META_DATA);
- commandMetaData.add(UndeployCommandMetaData.META_DATA);
- commandMetaData.add(SearchPluginsCommandMetaData.META_DATA);
- commandMetaData.add(InstallPluginCommandMetaData.META_DATA);
- commandMetaData.add(HelpCommandMetaData.META_DATA);
- commandMetaData.add(InstallLibraryCommandMetaData.META_DATA);
- commandMetaData.add(EncryptCommandMetaData.META_DATA);
- commandMetaData.add(UnlockKeystoreCommandMetaData.META_DATA);
-
- addURI();
- addHost();
- addPort();
- addDriver();
- addUser();
- addPassword();
- addSyserr();
- addVerbose();
- addOffline();
- addSecure();
- }
-
- public CommandMetaData getCommandMetaData() {
- return metaData;
- }
-
- public CommandArgs getCommandArgs() {
- return commandArgs;
- }
-
- public String getURI() {
- return commandLine.getOptionValue(ARGUMENT_URI_SHORTFORM);
- }
-
- public String getHost() {
- return commandLine.getOptionValue(ARGUMENT_HOST_SHORTFORM);
- }
-
- public Integer getPort() {
- String port = commandLine.getOptionValue(ARGUMENT_PORT_SHORTFORM);
- if (null == port) {
- return null;
- }
- return new Integer(port);
- }
-
- public String getDriver() {
- return commandLine.getOptionValue(ARGUMENT_DRIVER_SHORTFORM);
- }
-
- public String getUser() {
- return commandLine.getOptionValue(ARGUMENT_USER_SHORTFORM);
- }
-
- public String getPassword() {
- return commandLine.getOptionValue(ARGUMENT_PASSWORD_SHORTFORM);
- }
-
- public boolean isSyserr() {
- return commandLine.hasOption(ARGUMENT_SYSERR_SHORTFORM);
- }
-
- public boolean isVerbose() {
- return commandLine.hasOption(ARGUMENT_VERBOSE_SHORTFORM);
- }
-
- public boolean isOffline() {
- return commandLine.hasOption(ARGUMENT_OFFLINE_SHORTFORM);
- }
-
- public boolean isSecure() {
- return commandLine.hasOption(ARGUMENT_SECURE_SHORTFORM);
- }
-
- @Override
- public void displayHelp() {
- String[] args = new String[0];
- if (null != commandArgs) {
- args = commandArgs.getArgs();
- } else if (null != metaData) {
- args = new String[] {metaData.getCommandName()};
- }
- displayHelp(args);
- }
-
- @Override
- protected void displayHelp(String[] args) {
- PrintHelper printHelper = new PrintHelper(System.out);
- PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true);
-
- out.println();
- if(args.length > 0) {
- CommandMetaData commandLine = getCommandMetaData(args[0]);
- if(commandLine != null) {
- out.println("Help for command: "+commandLine.getCommandName());
- out.println(" "+hangingIndent(commandLine.getCommandName()+" "+commandLine.getHelpArgumentList(), 4));
- out.println();
- out.print(PrintHelper.reformat(commandLine.getHelpText(), 8, 72));
- out.println();
- return;
- } else if(args[0].equals("options")) {
- out.println("Help on general options:");
- printHelper.printOptions(out, options);
- out.println();
- return;
- } else if(args[0].equals("all")) {
- out.println();
- out.println("All commands");
- out.println();
- for (CommandMetaData commandLine2 : commandMetaData) {
- out.println(" "+hangingIndent(commandLine2.getCommandName()+" "+commandLine2.getHelpArgumentList(), 4));
- out.print(PrintHelper.reformat(commandLine2.getHelpText(), 8, 72));
- out.println();
- }
- out.println();
- return;
- }
- }
-
- out.println("usage: java -jar bin/deployer.jar [general options] command [command options]");
- out.println();
- out.println("The general options are:");
- printHelper.printOptionsNoDesc(out, options);
- out.println();
- out.println("The available commands are:");
- renderCommandList(out);
- out.println();
- out.println("For more information about a specific command, run");
- out.println(" java -jar bin/deployer.jar help [command name]");
- out.println();
- out.println("For more information about all commands, run");
- out.println(" java -jar bin/deployer.jar help all");
- out.println();
- out.println("For more information about general options, run");
- out.println(" java -jar bin/deployer.jar help options");
- out.println();
- }
-
- private void renderCommandList(PrintWriter out) {
- Map temp = new HashMap();
- for (CommandMetaData commandLine : commandMetaData) {
- List list = (List) temp.get(commandLine.getCommandGroup());
- if(list == null) {
- list = new ArrayList();
- temp.put(commandLine.getCommandGroup(), list);
- }
- list.add(commandLine.getCommandName());
- }
- List groups = new ArrayList(temp.keySet());
- Collections.sort(groups);
- for (int i = 0; i < groups.size(); i++) {
- String name = (String) groups.get(i);
- out.println(" "+name);
- List list = (List) temp.get(name);
- Collections.sort(list);
- for (int j = 0; j < list.size(); j++) {
- String cmd = (String) list.get(j);
- out.println(" "+cmd);
- }
- }
- }
-
- protected CommandMetaData getCommandMetaData(String commandName) {
- for (CommandMetaData commandLine : commandMetaData) {
- if (commandLine.getCommandName().equals(commandName)) {
- return commandLine;
- }
- }
- return null;
- }
-
- protected String hangingIndent(String source, int cols) {
- String s = PrintHelper.reformat(source, cols, 72);
- return s.substring(cols);
- }
-
- @Override
- protected void validateOptions() throws CLParserException {
- try {
- getPort();
- } catch (NumberFormatException e) {
- throw new CLParserException("Port [" + commandLine.getOptionValue(ARGUMENT_PORT_SHORTFORM) + "] is not an integer.", e);
- }
- }
-
- @Override
- protected void validateRemainingArgs() throws CLParserException {
- String[] args = commandLine.getArgs();
- if (0 == args.length) {
- throw new CLParserException("No command has been provided.");
- }
-
- String command = args[0];
- metaData = getCommandMetaData(command);
- if (null == metaData) {
- throw new CLParserException("Command [" + command + "] is undefined.");
- }
-
- String[] newArgs = new String[args.length - 1];
- System.arraycopy(args, 1, newArgs, 0, newArgs.length);
- commandArgs = metaData.parse(newArgs);
- }
-
- protected void addOffline() {
- options.addOption(ARGUMENT_OFFLINE_SHORTFORM,
- ARGUMENT_OFFLINE,
- false,
- "Deploy offline to a local server, using whatever deployers are available in the local server");
- }
-
- protected void addSecure() {
- options.addOption(ARGUMENT_SECURE_SHORTFORM,
- ARGUMENT_SECURE,
- false,
- "Use secure channel to communicate with the server. Unsecured channel is used by default.");
- }
-
- protected void addVerbose() {
- options.addOption(ARGUMENT_VERBOSE_SHORTFORM,
- ARGUMENT_VERBOSE,
- false,
- "Enables verbose execution mode. Disabled by default.");
- }
-
- protected void addSyserr() {
- options.addOption(ARGUMENT_SYSERR_SHORTFORM,
- ARGUMENT_SYSERR,
- false,
- "Enables error logging to syserr. Disabled by default.");
- }
-
- protected void addPassword() {
- addOptionWithParam(ARGUMENT_PASSWORD,
- ARGUMENT_PASSWORD_SHORTFORM,
- "password",
- "Specifies a password to use to authenticate to the server.");
- }
-
- protected void addUser() {
- addOptionWithParam(ARGUMENT_USER,
- ARGUMENT_USER_SHORTFORM,
- "username",
- "If the deployment operation requires authentication, then you can "
- + "specify the username to use to connect. If no password is specified, the "
- + "deployer will attempt to connect to the server with no password, and if "
- + "that fails, will prompt you for a password.");
- }
-
- protected void addDriver() {
- addOptionWithParam(ARGUMENT_DRIVER,
- ARGUMENT_DRIVER_SHORTFORM,
- "driver.jar",
- "If you want to use this tool with a server other than Geronimo, "
- + "then you must provide the path to its driver JAR. Currently, manifest "
- + "Class-Path entries in that JAR are ignored.");
- }
-
- protected void addPort() {
- addOptionWithParam(ARGUMENT_PORT,
- ARGUMENT_PORT_SHORTFORM,
- "port",
- "The RMI listen port of a Geronimo server to deploy to. This option is "
- + "not compatible with --uri, but is often used with --host. The default port is 1099.");
- }
-
- protected void addHost() {
- addOptionWithParam(ARGUMENT_HOST_SHORTFORM,
- ARGUMENT_HOST_SHORTFORM,
- "hostname",
- "The host name of a Geronimo server to deploy to. This option is "
- + "not compatible with --uri, but is often used with --port.");
- }
-
- protected void addURI() {
- addOptionWithParam(ARGUMENT_URI,
- ARGUMENT_URI_SHORTFORM,
- "uri",
- "A URI to contact the server. If not specified, the deployer defaults to "
- + "operating on a Geronimo server running on the standard port on localhost.\n"
- + "A URI to connect to Geronimo (including optional host and port parameters) has the form: "
- + "deployer:geronimo:jmx[://host[:port]] (though you could also just use --host and --port instead).");
- }
-
- protected void addOptionWithParam(String longOption, String shortOption, String argName, String desc) {
- OptionBuilder optionBuilder = OptionBuilder.hasArg().withArgName(argName);
- optionBuilder = optionBuilder.withLongOpt(longOption);
- optionBuilder = optionBuilder.withDescription(desc);
- Option option = optionBuilder.create(shortOption);
- options.addOption(option);
- }
-
-}
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.geronimo.cli.deployer;
+
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.geronimo.cli.BaseCLParser;
+import org.apache.geronimo.cli.CLParserException;
+import org.apache.geronimo.cli.PrintHelper;
+
+
+/**
+ * @version $Rev: 476049 $ $Date: 2006-11-17 15:35:17 +1100 (Fri, 17 Nov 2006) $
+ */
+public class DeployerCLParser extends BaseCLParser implements ConnectionParams {
+ private final static String ARGUMENT_URI_SHORTFORM = "U";
+ private final static String ARGUMENT_URI = "uri";
+
+ private final static String ARGUMENT_HOST_SHORTFORM = "host";
+
+ private final static String ARGUMENT_PORT_SHORTFORM = "port";
+ private final static String ARGUMENT_PORT = "port";
+
+ private final static String ARGUMENT_DRIVER_SHORTFORM = "d";
+ private final static String ARGUMENT_DRIVER = "driver";
+
+ private final static String ARGUMENT_USER_SHORTFORM = "u";
+ private final static String ARGUMENT_USER = "user";
+
+ private final static String ARGUMENT_PASSWORD_SHORTFORM = "p";
+ private final static String ARGUMENT_PASSWORD = "password";
+
+ private final static String ARGUMENT_SYSERR_SHORTFORM = "s";
+ private final static String ARGUMENT_SYSERR = "syserr";
+
+ private final static String ARGUMENT_VERBOSE_SHORTFORM = "v";
+ private final static String ARGUMENT_VERBOSE = "verbose";
+
+ private final static String ARGUMENT_OFFLINE_SHORTFORM = "o";
+ private final static String ARGUMENT_OFFLINE = "offline";
+
+ private final static String ARGUMENT_SECURE_SHORTFORM = "secure";
+ private final static String ARGUMENT_SECURE = "secure";
+
+ private final Collection<CommandMetaData> commandMetaData;
+
+ private CommandArgs commandArgs;
+ private CommandMetaData metaData;
+
+ public DeployerCLParser(OutputStream out) {
+ super(out);
+
+ commandMetaData = new ArrayList<CommandMetaData>();
+ commandMetaData.add(LoginCommandMetaData.META_DATA);
+ commandMetaData.add(DeployCommandMetaData.META_DATA);
+ commandMetaData.add(DistributeCommandMetaData.META_DATA);
+ commandMetaData.add(ListModulesCommandMetaData.META_DATA);
+ commandMetaData.add(ListTargetsCommandMetaData.META_DATA);
+ commandMetaData.add(RedeployCommandMetaData.META_DATA);
+ commandMetaData.add(StartCommandMetaData.META_DATA);
+ commandMetaData.add(StopCommandMetaData.META_DATA);
+ commandMetaData.add(RestartCommandMetaData.META_DATA);
+ commandMetaData.add(UndeployCommandMetaData.META_DATA);
+ commandMetaData.add(SearchPluginsCommandMetaData.META_DATA);
+ commandMetaData.add(InstallPluginCommandMetaData.META_DATA);
+ commandMetaData.add(HelpCommandMetaData.META_DATA);
+ commandMetaData.add(InstallLibraryCommandMetaData.META_DATA);
+ commandMetaData.add(EncryptCommandMetaData.META_DATA);
+ commandMetaData.add(UnlockKeystoreCommandMetaData.META_DATA);
+ commandMetaData.add(StatsQueryCommandMetaData.META_DATA);
+
+ addURI();
+ addHost();
+ addPort();
+ addDriver();
+ addUser();
+ addPassword();
+ addSyserr();
+ addVerbose();
+ addOffline();
+ addSecure();
+ }
+
+ public CommandMetaData getCommandMetaData() {
+ return metaData;
+ }
+
+ public CommandArgs getCommandArgs() {
+ return commandArgs;
+ }
+
+ public String getURI() {
+ return commandLine.getOptionValue(ARGUMENT_URI_SHORTFORM);
+ }
+
+ public String getHost() {
+ return commandLine.getOptionValue(ARGUMENT_HOST_SHORTFORM);
+ }
+
+ public Integer getPort() {
+ String port = commandLine.getOptionValue(ARGUMENT_PORT_SHORTFORM);
+ if (null == port) {
+ return null;
+ }
+ return new Integer(port);
+ }
+
+ public String getDriver() {
+ return commandLine.getOptionValue(ARGUMENT_DRIVER_SHORTFORM);
+ }
+
+ public String getUser() {
+ return commandLine.getOptionValue(ARGUMENT_USER_SHORTFORM);
+ }
+
+ public String getPassword() {
+ return commandLine.getOptionValue(ARGUMENT_PASSWORD_SHORTFORM);
+ }
+
+ public boolean isSyserr() {
+ return commandLine.hasOption(ARGUMENT_SYSERR_SHORTFORM);
+ }
+
+ public boolean isVerbose() {
+ return commandLine.hasOption(ARGUMENT_VERBOSE_SHORTFORM);
+ }
+
+ public boolean isOffline() {
+ return commandLine.hasOption(ARGUMENT_OFFLINE_SHORTFORM);
+ }
+
+ public boolean isSecure() {
+ return commandLine.hasOption(ARGUMENT_SECURE_SHORTFORM);
+ }
+
+ @Override
+ public void displayHelp() {
+ String[] args = new String[0];
+ if (null != commandArgs) {
+ args = commandArgs.getArgs();
+ } else if (null != metaData) {
+ args = new String[] {metaData.getCommandName()};
+ }
+ displayHelp(args);
+ }
+
+ @Override
+ protected void displayHelp(String[] args) {
+ PrintHelper printHelper = new PrintHelper(System.out);
+ PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out), true);
+
+ out.println();
+ if(args.length > 0) {
+ CommandMetaData commandLine = getCommandMetaData(args[0]);
+ if(commandLine != null) {
+ out.println("Help for command: "+commandLine.getCommandName());
+ out.println(" "+hangingIndent(commandLine.getCommandName()+" "+commandLine.getHelpArgumentList(), 4));
+ out.println();
+ out.print(PrintHelper.reformat(commandLine.getHelpText(), 8, 72));
+ out.println();
+ return;
+ } else if(args[0].equals("options")) {
+ out.println("Help on general options:");
+ printHelper.printOptions(out, options);
+ out.println();
+ return;
+ } else if(args[0].equals("all")) {
+ out.println();
+ out.println("All commands");
+ out.println();
+ for (CommandMetaData commandLine2 : commandMetaData) {
+ out.println(" "+hangingIndent(commandLine2.getCommandName()+" "+commandLine2.getHelpArgumentList(), 4));
+ out.print(PrintHelper.reformat(commandLine2.getHelpText(), 8, 72));
+ out.println();
+ }
+ out.println();
+ return;
+ }
+ }
+
+ out.println("usage: java -jar bin/deployer.jar [general options] command [command options]");
+ out.println();
+ out.println("The general options are:");
+ printHelper.printOptionsNoDesc(out, options);
+ out.println();
+ out.println("The available commands are:");
+ renderCommandList(out);
+ out.println();
+ out.println("For more information about a specific command, run");
+ out.println(" java -jar bin/deployer.jar help [command name]");
+ out.println();
+ out.println("For more information about all commands, run");
+ out.println(" java -jar bin/deployer.jar help all");
+ out.println();
+ out.println("For more information about general options, run");
+ out.println(" java -jar bin/deployer.jar help options");
+ out.println();
+ }
+
+ private void renderCommandList(PrintWriter out) {
+ Map temp = new HashMap();
+ for (CommandMetaData commandLine : commandMetaData) {
+ List list = (List) temp.get(commandLine.getCommandGroup());
+ if(list == null) {
+ list = new ArrayList();
+ temp.put(commandLine.getCommandGroup(), list);
+ }
+ list.add(commandLine.getCommandName());
+ }
+ List groups = new ArrayList(temp.keySet());
+ Collections.sort(groups);
+ for (int i = 0; i < groups.size(); i++) {
+ String name = (String) groups.get(i);
+ out.println(" "+name);
+ List list = (List) temp.get(name);
+ Collections.sort(list);
+ for (int j = 0; j < list.size(); j++) {
+ String cmd = (String) list.get(j);
+ out.println(" "+cmd);
+ }
+ }
+ }
+
+ protected CommandMetaData getCommandMetaData(String commandName) {
+ for (CommandMetaData commandLine : commandMetaData) {
+ if (commandLine.getCommandName().equals(commandName)) {
+ return commandLine;
+ }
+ }
+ return null;
+ }
+
+ protected String hangingIndent(String source, int cols) {
+ String s = PrintHelper.reformat(source, cols, 72);
+ return s.substring(cols);
+ }
+
+ @Override
+ protected void validateOptions() throws CLParserException {
+ try {
+ getPort();
+ } catch (NumberFormatException e) {
+ throw new CLParserException("Port [" + commandLine.getOptionValue(ARGUMENT_PORT_SHORTFORM) + "] is not an integer.", e);
+ }
+ }
+
+ @Override
+ protected void validateRemainingArgs() throws CLParserException {
+ String[] args = commandLine.getArgs();
+ if (0 == args.length) {
+ throw new CLParserException("No command has been provided.");
+ }
+
+ String command = args[0];
+ metaData = getCommandMetaData(command);
+ if (null == metaData) {
+ throw new CLParserException("Command [" + command + "] is undefined.");
+ }
+
+ String[] newArgs = new String[args.length - 1];
+ System.arraycopy(args, 1, newArgs, 0, newArgs.length);
+ commandArgs = metaData.parse(newArgs);
+ }
+
+ protected void addOffline() {
+ options.addOption(ARGUMENT_OFFLINE_SHORTFORM,
+ ARGUMENT_OFFLINE,
+ false,
+ "Deploy offline to a local server, using whatever deployers are available in the local server");
+ }
+
+ protected void addSecure() {
+ options.addOption(ARGUMENT_SECURE_SHORTFORM,
+ ARGUMENT_SECURE,
+ false,
+ "Use secure channel to communicate with the server. Unsecured channel is used by default.");
+ }
+
+ protected void addVerbose() {
+ options.addOption(ARGUMENT_VERBOSE_SHORTFORM,
+ ARGUMENT_VERBOSE,
+ false,
+ "Enables verbose execution mode. Disabled by default.");
+ }
+
+ protected void addSyserr() {
+ options.addOption(ARGUMENT_SYSERR_SHORTFORM,
+ ARGUMENT_SYSERR,
+ false,
+ "Enables error logging to syserr. Disabled by default.");
+ }
+
+ protected void addPassword() {
+ addOptionWithParam(ARGUMENT_PASSWORD,
+ ARGUMENT_PASSWORD_SHORTFORM,
+ "password",
+ "Specifies a password to use to authenticate to the server.");
+ }
+
+ protected void addUser() {
+ addOptionWithParam(ARGUMENT_USER,
+ ARGUMENT_USER_SHORTFORM,
+ "username",
+ "If the deployment operation requires authentication, then you can "
+ + "specify the username to use to connect. If no password is specified, the "
+ + "deployer will attempt to connect to the server with no password, and if "
+ + "that fails, will prompt you for a password.");
+ }
+
+ protected void addDriver() {
+ addOptionWithParam(ARGUMENT_DRIVER,
+ ARGUMENT_DRIVER_SHORTFORM,
+ "driver.jar",
+ "If you want to use this tool with a server other than Geronimo, "
+ + "then you must provide the path to its driver JAR. Currently, manifest "
+ + "Class-Path entries in that JAR are ignored.");
+ }
+
+ protected void addPort() {
+ addOptionWithParam(ARGUMENT_PORT,
+ ARGUMENT_PORT_SHORTFORM,
+ "port",
+ "The RMI listen port of a Geronimo server to deploy to. This option is "
+ + "not compatible with --uri, but is often used with --host. The default port is 1099.");
+ }
+
+ protected void addHost() {
+ addOptionWithParam(ARGUMENT_HOST_SHORTFORM,
+ ARGUMENT_HOST_SHORTFORM,
+ "hostname",
+ "The host name of a Geronimo server to deploy to. This option is "
+ + "not compatible with --uri, but is often used with --port.");
+ }
+
+ protected void addURI() {
+ addOptionWithParam(ARGUMENT_URI,
+ ARGUMENT_URI_SHORTFORM,
+ "uri",
+ "A URI to contact the server. If not specified, the deployer defaults to "
+ + "operating on a Geronimo server running on the standard port on localhost.\n"
+ + "A URI to connect to Geronimo (including optional host and port parameters) has the form: "
+ + "deployer:geronimo:jmx[://host[:port]] (though you could also just use --host and --port instead).");
+ }
+
+ protected void addOptionWithParam(String longOption, String shortOption, String argName, String desc) {
+ OptionBuilder optionBuilder = OptionBuilder.hasArg().withArgName(argName);
+ optionBuilder = optionBuilder.withLongOpt(longOption);
+ optionBuilder = optionBuilder.withDescription(desc);
+ Option option = optionBuilder.create(shortOption);
+ options.addOption(option);
+ }
+
+}
Added: geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/StatsQueryCommandMetaData.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/StatsQueryCommandMetaData.java?rev=1055843&view=auto
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/StatsQueryCommandMetaData.java (added)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/StatsQueryCommandMetaData.java Thu Jan 6 12:11:39 2011
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.cli.deployer;
+
+import org.apache.geronimo.cli.CLParserException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StatsQueryCommandMetaData extends BaseCommandMetaData {
+ public static final CommandMetaData META_DATA = new StatsQueryCommandMetaData();
+
+ private StatsQueryCommandMetaData() {
+ super("stats-query", "2. Other Commands", "[enable/disable] [snapshot-duration-minutes]",
+ "Command to enable or disable stats query on Default Server.\n" +
+ "Use 'enable' to start stats query and 'disable' to stop stats query.\n" +
+ "Specify snapshot-duration-minutes with 'enable'."
+ );
+ }
+
+ public CommandArgs parse(String[] newArgs) throws CLParserException {
+ if (newArgs.length == 0) {
+ throw new CLParserException("Must specify either enable or disable.");
+ }
+ return new BaseCommandArgs(newArgs);
+ }
+}
Propchange: geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/StatsQueryCommandMetaData.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/StatsQueryCommandMetaData.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/branches/2.1/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/deployer/StatsQueryCommandMetaData.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandStatsQuery.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandStatsQuery.java?rev=1055843&view=auto
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandStatsQuery.java (added)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandStatsQuery.java Thu Jan 6 12:11:39 2011
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.deployment.cli;
+
+import java.util.Set;
+
+import javax.enterprise.deploy.spi.DeploymentManager;
+
+import jline.ConsoleReader;
+
+import org.apache.geronimo.cli.deployer.CommandArgs;
+import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager;
+import org.apache.geronimo.gbean.AbstractName;
+import org.apache.geronimo.gbean.AbstractNameQuery;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.InternalKernelException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.NoSuchOperationException;
+
+/**
+ * Utility to enable/disable stats query on Default Server
+ * @version $Rev$ $Date$
+ */
+public class CommandStatsQuery extends AbstractCommand {
+
+ public void execute(ConsoleReader consoleReader, ServerConnection connection, CommandArgs commandArgs) throws DeploymentException {
+ String args[] = commandArgs.getArgs();
+ if (args.length == 0) {
+ throw new DeploymentException("Specify either to 'enable' or 'disable' stats query on Default Server.");
+ }
+ DeploymentManager dm = connection.getDeploymentManager();
+ Kernel kernel = null;
+ if (dm instanceof RemoteDeploymentManager) {
+ kernel = ((RemoteDeploymentManager) dm).getKernel();
+ }
+ AbstractNameQuery nameQuery = new AbstractNameQuery("org.apache.geronimo.monitoring.MasterRemoteControlJMX");
+ Set<AbstractName> it = kernel.listGBeans(nameQuery);
+ AbstractName gbeanName = (AbstractName) it.iterator().next();
+ Integer running = 0;
+ try {
+ running = (Integer) kernel.invoke(gbeanName, "SnapshotStatus");
+ if("disable".equals(args[0])) {
+ if(running == 1) {
+ Boolean status = (Boolean) kernel.invoke(gbeanName, "stopSnapshot");
+ consoleReader.printString(DeployUtils.reformat(status ? "Stats query snapshot is now disabled." : "Disabling Stats query snapashot failed.", 4, 72));
+ } else {
+ consoleReader.printString(DeployUtils.reformat("Stats query snapshot is not running.", 4, 72));
+ }
+ } else if("enable".equals(args[0])) {
+ if(args.length == 1) {
+ consoleReader.printString(DeployUtils.reformat("Please specify snapshotDuration in minutes.", 4, 72));
+ return;
+ }
+ Long snapshotDuration = Integer.parseInt(args[1]) * 60000L;
+ Long prevSnapshotDuration;
+ if(running == 1) {
+ prevSnapshotDuration = (Long) kernel.invoke(gbeanName, "getSnapshotDuration");
+ if(prevSnapshotDuration.equals(snapshotDuration)) {
+ consoleReader.printString(DeployUtils.reformat("Stats query snapshot is already running with duration of " + snapshotDuration/60000 + " min.", 4, 72));
+ } else {
+ kernel.invoke(gbeanName, "setSnapshotDuration", new Object[] {snapshotDuration}, new String[]{Long.class.getName()});
+ consoleReader.printString(DeployUtils.reformat("Stats query snapshot was already running with duration of " + prevSnapshotDuration/60000 + " min. Now it is changed to "+ snapshotDuration/60000 + " min.", 4, 72));
+ }
+ } else {
+ Boolean status = (Boolean) kernel.invoke(gbeanName, "startSnapshot", new Object[] {snapshotDuration}, new String[]{Long.class.getName()});
+ consoleReader.printString(DeployUtils.reformat(status ? "Stats query snapshot started successfully with snapshot duration of " + snapshotDuration/60000 + " min.": "Enabling Stats query snapshot failed.", 4, 72));
+ }
+ }
+ } catch (GBeanNotFoundException e) {
+ throw new DeploymentException("Unable to find the gbean associated with monitoring.", e);
+ } catch (NoSuchOperationException e) {
+ throw new DeploymentException("Operation does not exist", e);
+ } catch (InternalKernelException e) {
+ throw new DeploymentException(e);
+ } catch (Exception e) {
+ throw new DeploymentException(e);
+ }
+ }
+}
Propchange: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandStatsQuery.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandStatsQuery.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandStatsQuery.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployTool.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployTool.java?rev=1055843&r1=1055842&r2=1055843&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployTool.java (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/DeployTool.java Thu Jan 6 12:11:39 2011
@@ -48,6 +48,7 @@ import org.apache.geronimo.cli.deployer.
import org.apache.geronimo.cli.deployer.RestartCommandMetaData;
import org.apache.geronimo.cli.deployer.SearchPluginsCommandMetaData;
import org.apache.geronimo.cli.deployer.StartCommandMetaData;
+import org.apache.geronimo.cli.deployer.StatsQueryCommandMetaData;
import org.apache.geronimo.cli.deployer.StopCommandMetaData;
import org.apache.geronimo.cli.deployer.UndeployCommandMetaData;
import org.apache.geronimo.cli.deployer.UnlockKeystoreCommandMetaData;
@@ -94,6 +95,7 @@ public class DeployTool implements Main
commands.put(InstallLibraryCommandMetaData.META_DATA, new CommandInstallLibrary());
commands.put(EncryptCommandMetaData.META_DATA, new CommandEncrypt());
commands.put(UnlockKeystoreCommandMetaData.META_DATA, new CommandUnlockKeystore());
+ commands.put(StatsQueryCommandMetaData.META_DATA, new CommandStatsQuery());
}
private boolean failed = false;