[jboss-cvs] JBossAS SVN: r88388 - in branches/Branch_5_x/adminclient: src/main/java/org/jboss/adminclient and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 7 22:27:40 EDT 2009
Author: ispringer
Date: 2009-05-07 22:27:40 -0400 (Thu, 07 May 2009)
New Revision: 88388
Added:
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/HelpCommand.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/LoadCommand.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ReloadCommand.java
Modified:
branches/Branch_5_x/adminclient/pom.xml
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/AbstractClientCommand.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java
Log:
add a few more commands
Modified: branches/Branch_5_x/adminclient/pom.xml
===================================================================
--- branches/Branch_5_x/adminclient/pom.xml 2009-05-07 23:09:13 UTC (rev 88387)
+++ branches/Branch_5_x/adminclient/pom.xml 2009-05-08 02:27:40 UTC (rev 88388)
@@ -146,14 +146,14 @@
<scope>runtime</scope>
</dependency>
+ <!-- aka jboss-client.jar -->
<dependency>
- <groupId>org.jboss.client</groupId>
- <artifactId>jboss-client</artifactId>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-server</artifactId>
+ <classifier>client</classifier>
<scope>runtime</scope>
- <!--<version>${project.version}</version>-->
- <version>5.1.0.CR1</version>
- </dependency>
-
+ </dependency>
+
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-mdr</artifactId>
@@ -258,6 +258,12 @@
</dependency>
<dependency>
+ <groupId>gnu-getopt</groupId>
+ <artifactId>getopt</artifactId>
+ </dependency>
+
+ <!-- going to use getopt instead since it's already included w/ JBAS... -->
+ <dependency>
<groupId>net.sf.jopt-simple</groupId>
<artifactId>jopt-simple</artifactId>
<version>3.1</version>
Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java 2009-05-07 23:09:13 UTC (rev 88387)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java 2009-05-08 02:27:40 UTC (rev 88388)
@@ -46,7 +46,9 @@
import org.jboss.adminclient.command.ListComponentsCommand;
import org.jboss.adminclient.command.ListDeploymentsCommand;
import org.jboss.adminclient.command.QuitCommand;
-import org.jboss.adminclient.command.RefreshCommand;
+import org.jboss.adminclient.command.ReloadCommand;
+import org.jboss.adminclient.command.HelpCommand;
+import org.jboss.adminclient.command.LoadCommand;
import org.jboss.adminclient.connection.ProfileServiceConnection;
/**
@@ -54,13 +56,15 @@
*/
public class AdminClientMain
{
- public static Class[] COMMAND_CLASSES = new Class[]{
+ private static Class[] COMMAND_CLASSES = new Class[]{
ConnectCommand.class,
- RefreshCommand.class,
+ DisconnectCommand.class,
+ HelpCommand.class,
+ ListComponentsCommand.class,
ListDeploymentsCommand.class,
- ListComponentsCommand.class,
- DisconnectCommand.class,
- QuitCommand.class
+ LoadCommand.class,
+ QuitCommand.class,
+ ReloadCommand.class
};
private static final Map<String, ClientCommand> COMMANDS = new HashMap<String, ClientCommand>();
@@ -104,7 +108,6 @@
public static void main(String[] args) throws Exception
{
-
/*Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
public void run() {
try {
@@ -168,7 +171,6 @@
}
else
{
-
prompt = host + ":" + port + "> ";
}
}
@@ -246,18 +248,7 @@
// cmd = null;
// }
- boolean continueRunning;
- try
- {
- // parse the command into separate arguments and execute it
- String[] cmdArgs = parseCommandLine(cmd);
- continueRunning = executePromptCommand(cmdArgs);
- }
- catch (RuntimeException e)
- {
- e.printStackTrace(getPrintWriter()); // TODO: handle better
- continueRunning = true;
- }
+ boolean continueRunning = executeCommand(cmd);
// break the input loop if the prompt command told us to exit
// if we are not in daemon mode, this really will end up killing the agent
if (!continueRunning)
@@ -277,8 +268,25 @@
return;
}
- private boolean executePromptCommand(String[] args)
+ private boolean executeCommand(String cmd)
{
+ boolean continueRunning;
+ try
+ {
+ // parse the command into separate arguments and execute it
+ String[] cmdArgs = parseCommandLine(cmd);
+ continueRunning = executeCommand(cmdArgs);
+ }
+ catch (RuntimeException e)
+ {
+ e.printStackTrace(getPrintWriter()); // TODO: handle better
+ continueRunning = true;
+ }
+ return continueRunning;
+ }
+
+ private boolean executeCommand(String[] args)
+ {
String commandName = args[0];
if (COMMANDS.containsKey(commandName))
{
@@ -398,6 +406,8 @@
.describedAs("the username used to authenticate against the JBoss AS Profile Service");
acceptsAll(asList("p", "password")).withRequiredArg().ofType(String.class)
.describedAs("the password used to authenticate against the JBoss AS Profile Service");
+ acceptsAll(asList("e", "execute")).withRequiredArg().ofType(String.class)
+ .describedAs("a semicolon-separated list of commands to execute");
acceptsAll(asList("h", "?", "help"), "display help");
acceptsAll(asList("v", "verbose"), "enable verbose output");
//accepts( "output-file" ).withOptionalArg().ofType( File.class ).describedAs( "file" );
@@ -415,6 +425,16 @@
this.password = (String)options.valueOf("password");
this.verbose = options.has("verbose");
+ String execute = (String)options.valueOf("execute");
+ if (execute != null) {
+ String[] commands = execute.split(";");
+ for (String command : commands)
+ {
+ if (!executeCommand(command))
+ System.exit(0);
+ }
+ }
+
ClientCommand connectCommand = COMMANDS.get(ConnectCommand.COMMAND_NAME);
OptionParser connectOptionParser = connectCommand.getOptionParser();
List<String> connectOptions = new ArrayList<String>();
@@ -472,7 +492,6 @@
return this.consoleReader.getTermwidth();
}
-
public Map<String, ClientCommand> getCommands()
{
return COMMANDS;
Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/AbstractClientCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/AbstractClientCommand.java 2009-05-07 23:09:13 UTC (rev 88387)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/AbstractClientCommand.java 2009-05-08 02:27:40 UTC (rev 88388)
@@ -41,4 +41,9 @@
getOptionParser().acceptsAll(asList("h", "?", "help"), "display help");
return getOptionParser();
}
+
+ public boolean isUndocumented()
+ {
+ return false;
+ }
}
Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java 2009-05-07 23:09:13 UTC (rev 88387)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java 2009-05-08 02:27:40 UTC (rev 88388)
@@ -79,4 +79,11 @@
* @return
*/
boolean isConnectionRequired();
+
+ /**
+ * TODO
+ *
+ * @return
+ */
+ boolean isUndocumented();
}
\ No newline at end of file
Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java 2009-05-07 23:09:13 UTC (rev 88387)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java 2009-05-08 02:27:40 UTC (rev 88388)
@@ -62,26 +62,19 @@
{
if (!options.nonOptionArguments().isEmpty())
throw new IllegalArgumentException("Usage: " + getPromptCommandString() + " ...");
- try
- {
- String host = options.has("host") ? (String)options.valueOf("host") : "127.0.0.1";
- int port = options.has("port") ? (Integer)options.valueOf("port") : 1099;
- String username = (String)options.valueOf("username");
- String password = (String)options.valueOf("password");
- String jnpURL = "jnp://" + host + ":" + port;
+ String host = options.has("host") ? (String)options.valueOf("host") : "127.0.0.1";
+ int port = options.has("port") ? (Integer)options.valueOf("port") : 1099;
+ String username = (String)options.valueOf("username");
+ String password = (String)options.valueOf("password");
+ String jnpURL = "jnp://" + host + ":" + port;
- ProfileServiceConnectionProvider connectionProvider =
- new RemoteProfileServiceConnectionProvider(jnpURL, username, password);
- ProfileServiceConnection connection = connectionProvider.connect();
- client.setConnection(connection);
- client.setHost(host);
- client.setPort(port);
- client.getPrintWriter().println("Connected.");
- }
- catch (Exception e)
- {
- client.getPrintWriter().println("Failed to connect: " + e);
- }
+ ProfileServiceConnectionProvider connectionProvider =
+ new RemoteProfileServiceConnectionProvider(jnpURL, username, password);
+ ProfileServiceConnection connection = connectionProvider.connect();
+ client.setConnection(connection);
+ client.setHost(host);
+ client.setPort(port);
+ client.getPrintWriter().println("Connected.");
return true;
}
Modified: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java 2009-05-07 23:09:13 UTC (rev 88387)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java 2009-05-08 02:27:40 UTC (rev 88388)
@@ -45,16 +45,9 @@
{
if (!options.nonOptionArguments().isEmpty())
throw new IllegalArgumentException("Usage: " + getPromptCommandString());
- try
- {
- if (client.getConnection() != null)
- client.getConnection().getConnectionProvider().disconnect();
- client.getPrintWriter().println("Disconnected.");
- }
- catch (Exception e)
- {
- client.getPrintWriter().println("Failed to disconnect: " + e);
- }
+ if (client.getConnection() != null)
+ client.getConnection().getConnectionProvider().disconnect();
+ client.getPrintWriter().println("Disconnected.");
return true;
}
Added: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/HelpCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/HelpCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/HelpCommand.java 2009-05-08 02:27:40 UTC (rev 88388)
@@ -0,0 +1,95 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.jboss.adminclient.command;
+
+import java.util.List;
+import java.io.IOException;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.AdminClientMain;
+
+/**
+ * @author Ian Springer
+ */
+public class HelpCommand extends AbstractClientCommand
+{
+ public String getPromptCommandString()
+ {
+ return "help";
+ }
+
+ public OptionParser getOptionParser()
+ {
+ return new OptionParser();
+ }
+
+ public boolean execute(AdminClientMain client, OptionSet options)
+ {
+ List<String> nonOptionArgs = options.nonOptionArguments();
+ if (nonOptionArgs.size() > 1)
+ throw new IllegalArgumentException("Usage: " + getPromptCommandString() + " [command]");
+ if (nonOptionArgs.isEmpty()) {
+ client.getPrintWriter().println("The following commands are available:\n");
+ for (ClientCommand command : client.getCommands().values()) {
+ if (!command.isUndocumented())
+ client.getPrintWriter().println(" " + command.getPromptCommandString() + "\t" + command.getHelp());
+ }
+ client.getPrintWriter().println("\nEnter 'help <command>' to display detailed help for a command.");
+ } else {
+ String commandName = nonOptionArgs.get(0);
+ ClientCommand command = client.getCommands().get(commandName);
+ if (command != null) {
+ client.getPrintWriter().println("Command: " + command.getPromptCommandString());
+ String detailedHelp = (command.getDetailedHelp() != null) ? command.getDetailedHelp() :
+ command.getHelp();
+ client.getPrintWriter().println("\n" + detailedHelp);
+ String syntax = "TODO";
+ client.getPrintWriter().println("Usage: " + command.getPromptCommandString() + "\t" + syntax);
+ try
+ {
+ command.getOptionParser().printHelpOn(client.getPrintWriter());
+ }
+ catch (IOException e)
+ {
+ throw new IllegalStateException(e);
+ }
+ } else {
+ client.getPrintWriter().println("Unknown command: " + commandName);
+ }
+ }
+ return true;
+ }
+
+ public String getHelp()
+ {
+ return "Refresh the Profile Service management view.";
+ }
+
+ public String getDetailedHelp()
+ {
+ return null;
+ }
+
+ public boolean isConnectionRequired()
+ {
+ return true;
+ }
+}
\ No newline at end of file
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/HelpCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Author Id Revision HeadURL
Name: svn:eol-style
+ LF
Added: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/LoadCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/LoadCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/LoadCommand.java 2009-05-08 02:27:40 UTC (rev 88388)
@@ -0,0 +1,75 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.jboss.adminclient.command;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.AdminClientMain;
+import org.jboss.deployers.spi.management.ManagementView;
+
+/**
+ * @author Ian Springer
+ */
+public class LoadCommand extends AbstractClientCommand
+{
+ public String getPromptCommandString()
+ {
+ return "load";
+ }
+
+ public OptionParser getOptionParser()
+ {
+ return new OptionParser();
+ }
+
+ public boolean execute(AdminClientMain client, OptionSet options)
+ {
+ if (!options.nonOptionArguments().isEmpty())
+ throw new IllegalArgumentException("Usage: " + getPromptCommandString());
+ ManagementView managementView = client.getConnection().getManagementView();
+ boolean wasReloaded = managementView.load();
+ if (wasReloaded)
+ client.getPrintWriter().println("Reloaded management view.");
+ else
+ client.getPrintWriter().println("Management view is already up-to-date.");
+ return true;
+ }
+
+ public String getHelp()
+ {
+ return "Check if the Profile Service management view is up-to-date, and, if not, reload it.";
+ }
+
+ public String getDetailedHelp()
+ {
+ return null;
+ }
+
+ public boolean isConnectionRequired()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isUndocumented()
+ {
+ return true;
+ }
+}
\ No newline at end of file
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/LoadCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Author Id Revision HeadURL
Name: svn:eol-style
+ LF
Added: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ReloadCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ReloadCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ReloadCommand.java 2009-05-08 02:27:40 UTC (rev 88388)
@@ -0,0 +1,72 @@
+/*
+ * RHQ Management Platform
+ * Copyright (C) 2005-2008 Red Hat, Inc.
+ * All rights reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+package org.jboss.adminclient.command;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.AdminClientMain;
+import org.jboss.deployers.spi.management.ManagementView;
+
+/**
+ * @author Ian Springer
+ */
+public class ReloadCommand extends AbstractClientCommand
+{
+ public String getPromptCommandString()
+ {
+ return "reload";
+ }
+
+ public OptionParser getOptionParser()
+ {
+ return new OptionParser();
+ }
+
+ public boolean execute(AdminClientMain client, OptionSet options)
+ {
+ if (!options.nonOptionArguments().isEmpty())
+ throw new IllegalArgumentException("Usage: " + getPromptCommandString());
+ ManagementView managementView = client.getConnection().getManagementView();
+ managementView.reload();
+ client.getPrintWriter().println("Reloaded management view.");
+ return true;
+ }
+
+ public String getHelp()
+ {
+ return "Reload the Profile Service management view.";
+ }
+
+ public String getDetailedHelp()
+ {
+ return null;
+ }
+
+ public boolean isConnectionRequired()
+ {
+ return true;
+ }
+
+ @Override
+ public boolean isUndocumented()
+ {
+ return true;
+ }
+}
\ No newline at end of file
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ReloadCommand.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Date Author Id Revision HeadURL
Name: svn:eol-style
+ LF
More information about the jboss-cvs-commits
mailing list