[jboss-cvs] JBossAS SVN: r88309 - in branches/Branch_5_x: adminclient and 8 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 6 18:36:36 EDT 2009
Author: ispringer
Date: 2009-05-06 18:36:36 -0400 (Wed, 06 May 2009)
New Revision: 88309
Added:
branches/Branch_5_x/adminclient/
branches/Branch_5_x/adminclient/pom.xml
branches/Branch_5_x/adminclient/src/
branches/Branch_5_x/adminclient/src/main/
branches/Branch_5_x/adminclient/src/main/java/
branches/Branch_5_x/adminclient/src/main/java/org/
branches/Branch_5_x/adminclient/src/main/java/org/jboss/
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/
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/
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
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListComponentsCommand.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListDeploymentsCommand.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/QuitCommand.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/RefreshCommand.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/AbstractProfileServiceConnectionProvider.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnection.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnectionImpl.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnectionProvider.java
branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/RemoteProfileServiceConnectionProvider.java
Log:
early version of an interactive command-line client for the Profile Service
Added: branches/Branch_5_x/adminclient/pom.xml
===================================================================
--- branches/Branch_5_x/adminclient/pom.xml (rev 0)
+++ branches/Branch_5_x/adminclient/pom.xml 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,274 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+ <parent>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-parent</artifactId>
+ <version>5.1.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-adminclient</artifactId>
+ <packaging>jar</packaging>
+ <name>JBoss Application Server Admin Client</name>
+ <description>JBoss Application Server (admin client module)</description>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.jboss.adminclient.AdminClientMain</mainClass>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>lib</classpathPrefix>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>copy-dependencies</id>
+ <phase>package</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <includeScope>runtime</includeScope>
+ <excludeTransitive>true</excludeTransitive>
+ <outputDirectory>target/lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+<!--
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>assembly</id>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ <phase>package</phase>
+ </execution>
+ </executions>
+ <configuration>
+ <descriptorSourceDirectory>src/assembly</descriptorSourceDirectory>
+ </configuration>
+ </plugin>
+-->
+ </plugins>
+ </build>
+
+ <dependencies>
+
+ <!-- AS client jars -->
+
+ <dependency>
+ <groupId>org.jboss.naming</groupId>
+ <artifactId>jnp-client</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.security</groupId>
+ <artifactId>jbosssx-client</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.aspects</groupId>
+ <artifactId>jboss-security-aspects</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.aop</groupId>
+ <artifactId>jboss-aop</artifactId>
+ <classifier>client</classifier>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-common-core</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.remoting</groupId>
+ <artifactId>jboss-remoting</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-aspects</artifactId>
+ <version>${project.version}</version>
+ <classifier>jboss-aspect-jdk50-client</classifier>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>trove</groupId>
+ <artifactId>trove</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javassist</groupId>
+ <artifactId>javassist</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.security</groupId>
+ <artifactId>jboss-security-spi</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.javaee</groupId>
+ <artifactId>jboss-javaee</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>oswego-concurrent</groupId>
+ <artifactId>concurrent</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.client</groupId>
+ <artifactId>jboss-client</artifactId>
+ <scope>runtime</scope>
+ <!--<version>${project.version}</version>-->
+ <version>5.1.0.CR1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss</groupId>
+ <artifactId>jboss-mdr</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-spi</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.logging</groupId>
+ <artifactId>jboss-logging-log4j</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-security</artifactId>
+ <version>${project.version}</version>
+ <classifier>client</classifier>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.integration</groupId>
+ <artifactId>jboss-transaction-spi</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-common</artifactId>
+ <classifier>client</classifier>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-core</artifactId>
+ <classifier>client</classifier>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-ext-api</artifactId>
+ <version>1.0.0</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-proxy-spi</artifactId>
+ <classifier>client</classifier>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-proxy-impl</artifactId>
+ <classifier>client</classifier>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.ejb3</groupId>
+ <artifactId>jboss-ejb3-security</artifactId>
+ <classifier>client</classifier>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.integration</groupId>
+ <artifactId>jboss-profileservice-spi</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-managed</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>org.jboss.man</groupId>
+ <artifactId>jboss-metatype</artifactId>
+ </dependency>
+
+ <!-- *************** TODO: Remove this!!! **************** -->
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-profileservice</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <!-- other deps -->
+
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>net.sf.jopt-simple</groupId>
+ <artifactId>jopt-simple</artifactId>
+ <version>3.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>jline</groupId>
+ <artifactId>jline</artifactId>
+ <version>0.9.94</version>
+ </dependency>
+
+ </dependencies>
+
+</project>
Property changes on: branches/Branch_5_x/adminclient/pom.xml
___________________________________________________________________
Name: svn:mime-type
+ text/xml
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/AdminClientMain.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,510 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.StreamTokenizer;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import jline.ArgumentCompletor;
+import jline.Completor;
+import jline.ConsoleReader;
+import jline.SimpleCompletor;
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.command.ClientCommand;
+import org.jboss.adminclient.command.ConnectCommand;
+import org.jboss.adminclient.command.DisconnectCommand;
+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.connection.ProfileServiceConnection;
+
+/**
+ * @author Ian Springer
+ */
+public class AdminClientMain
+{
+ public static Class[] COMMAND_CLASSES = new Class[]{
+ ConnectCommand.class,
+ RefreshCommand.class,
+ ListDeploymentsCommand.class,
+ ListComponentsCommand.class,
+ DisconnectCommand.class,
+ QuitCommand.class
+ };
+ private static final Map<String, ClientCommand> COMMANDS = new HashMap<String, ClientCommand>();
+
+ static
+ {
+ for (Class commandClass : COMMAND_CLASSES)
+ {
+ ClientCommand command;
+ try
+ {
+ command = (ClientCommand)commandClass.newInstance();
+ COMMANDS.put(command.getPromptCommandString(), command);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ /**
+ * This is the thread that is running the input loop; it accepts prompt commands from the user.
+ */
+ private Thread inputLoopThread;
+
+ private BufferedReader inputReader;
+
+ private ConsoleReader consoleReader;
+
+ private boolean stdinInput = true;
+
+ private PrintWriter outputWriter;
+
+ private ProfileServiceConnection connection;
+
+ String host;
+ Integer port;
+ String username;
+ String password;
+ boolean verbose;
+
+ public static void main(String[] args) throws Exception
+ {
+
+ /*Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+ public void run() {
+ try {
+ new UnixTerminal().restoreTerminal(); }
+ catch (Exception e) { }
+ }
+ }));*/
+ try
+ {
+// new UnixTerminal().initializeTerminal();
+
+ AdminClientMain main = new AdminClientMain();
+ main.processArguments(args);
+ main.inputLoop();
+ }
+ finally
+ {
+ //new UnixTerminal().restoreTerminal();
+ }
+ }
+
+ public AdminClientMain() throws Exception
+ {
+
+// this.inputReader = new BufferedReader(new InputStreamReader(System.in));
+ this.outputWriter = new PrintWriter(System.out, true);
+
+ consoleReader = new jline.ConsoleReader();
+ consoleReader.addCompletor(
+ new SimpleCompletor(COMMANDS.keySet().toArray(new String[COMMANDS.size()])));
+ consoleReader.addCompletor(
+ new ArgumentCompletor(
+ new Completor[]{
+ new SimpleCompletor("help"),
+ new SimpleCompletor(COMMANDS.keySet().toArray(new String[COMMANDS.size()]))}));
+
+ consoleReader.setUsePagination(true);
+
+ }
+
+ public void start()
+ {
+ outputWriter = new PrintWriter(System.out);
+// inputReader = new BufferedReader(new InputStreamReader(System.in));
+
+ }
+
+ public String getUserInput(String prompt)
+ {
+
+ String inputString = "";
+ boolean useDefaultPrompt = (prompt == null);
+
+ while ((inputString != null) && (inputString.trim().length() == 0))
+ {
+ if (prompt == null)
+ {
+ if (!isConnected())
+ {
+ prompt = "unconnected> ";
+ }
+ else
+ {
+
+ prompt = host + ":" + port + "> ";
+ }
+ }
+// outputWriter.print(prompt);
+
+ try
+ {
+ outputWriter.flush();
+ inputString = consoleReader.readLine(prompt);
+ //inputReader.readLine();
+ }
+ catch (Exception e)
+ {
+ inputString = null;
+ }
+ }
+
+ if (inputString != null)
+ {
+ // if we are processing a script, show the input that was just read in
+ if (!stdinInput)
+ {
+ outputWriter.println(inputString);
+ }
+ }
+ else if (!stdinInput)
+ {
+ // if we are processing a script, we hit the EOF, so close the input stream
+ try
+ {
+ inputReader.close();
+ }
+ catch (IOException e1)
+ {
+ }
+
+ // if we are not in daemon mode, let's now start processing prompt commands coming in via stdin
+// if (!m_daemonMode) {
+// inputReader = new BufferedReader(new InputStreamReader(System.in));
+// stdinInput = true;
+// input_string = "";
+// } else {
+// inputReader = null;
+// }
+ }
+
+ return inputString;
+ }
+
+ public boolean isConnected()
+ {
+ return (this.connection != null && this.connection.getConnectionProvider().isConnected());
+ }
+
+ /**
+ * This enters in an infinite loop. Because this never returns, the current thread never dies and hence the agent
+ * stays up and running. The user can enter agent commands at the prompt - the commands are sent to the agent as if
+ * the user is a remote client.
+ */
+ private void inputLoop()
+ {
+ // we need to start a new thread and run our loop in it; otherwise, our shutdown hook doesn't work
+ Runnable loopRunnable = new Runnable()
+ {
+ public void run()
+ {
+ while (true)
+ {
+ // get a command from the user
+ // if in daemon mode, only get input if reading from an input file; ignore stdin
+ String cmd;
+// if ((m_daemonMode == false) || (stdinInput == false)) {
+ cmd = getUserInput(null);
+// } else {
+// 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;
+ }
+ // 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)
+ break;
+ }
+
+ return;
+ }
+ };
+
+ // Start the input thread.
+ inputLoopThread = new Thread(loopRunnable);
+ inputLoopThread.setName("JBoss AS Admin Client Prompt Input Thread");
+ inputLoopThread.setDaemon(false);
+ inputLoopThread.start();
+
+ return;
+ }
+
+ private boolean executePromptCommand(String[] args)
+ {
+ String commandName = args[0];
+ if (COMMANDS.containsKey(commandName))
+ {
+ ClientCommand command = COMMANDS.get(commandName);
+ if (command.isConnectionRequired() && !isConnected())
+ {
+ outputWriter.println("The '" + commandName + "' command requires a connection. Please run the 'connect' command first.");
+ return true;
+ }
+ String[] params = new String[args.length - 1];
+ System.arraycopy(args, 1, params, 0, args.length - 1);
+ OptionParser optionParser = command.getOptionParser();
+ optionParser.acceptsAll(asList("h", "?", "help"), "display help");
+ OptionSet options = optionParser.parse(params);
+ if (options.has("help"))
+ {
+ try
+ {
+ optionParser.printHelpOn(this.outputWriter);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+ else
+ {
+ try
+ {
+ return command.execute(this, options);
+ }
+ catch (Exception e)
+ {
+ getPrintWriter().write("Command failed: " + e.getLocalizedMessage());
+ e.printStackTrace(getPrintWriter());
+ }
+ }
+ }
+ else
+ {
+ //return COMMANDS.get("exec").execute(this, args);
+ outputWriter.println("Unknown command: " + commandName);
+ }
+ return true;
+ }
+
+
+ /**
+ * Given a command line, this will parse each argument and return the argument array.
+ *
+ * @param cmdLine the command line
+ * @return the array of command line arguments
+ */
+ private String[] parseCommandLine(String cmdLine)
+ {
+ ByteArrayInputStream in = new ByteArrayInputStream(cmdLine.getBytes());
+ StreamTokenizer strtok = new StreamTokenizer(new InputStreamReader(in));
+ List<String> args = new ArrayList<String>();
+ boolean keep_going = true;
+
+ // we don't want to parse numbers and we want ' to be a normal word character
+ strtok.ordinaryChars('0', '9');
+ strtok.ordinaryChar('.');
+ strtok.ordinaryChar('-');
+ strtok.ordinaryChar('\'');
+ strtok.wordChars(33, 127);
+ strtok.quoteChar('\"');
+
+ // parse the command line
+ while (keep_going)
+ {
+ int nextToken;
+
+ try
+ {
+ nextToken = strtok.nextToken();
+ }
+ catch (IOException e)
+ {
+ nextToken = StreamTokenizer.TT_EOF;
+ }
+
+ if (nextToken == java.io.StreamTokenizer.TT_WORD)
+ {
+ args.add(strtok.sval);
+ }
+ else if (nextToken == '\"')
+ {
+ args.add(strtok.sval);
+ }
+ else if ((nextToken == java.io.StreamTokenizer.TT_EOF) || (nextToken == java.io.StreamTokenizer.TT_EOL))
+ {
+ keep_going = false;
+ }
+ }
+
+ return args.toArray(new String[args.size()]);
+ }
+
+
+ private void displayUsage()
+ {
+ outputWriter.println("rhq-client.sh [-h] [-u user] [-p pass] [-s host] [-t port] [-f file]");
+ }
+
+
+ void processArguments(String[] args) throws IllegalArgumentException, IOException
+ {
+ OptionParser optionParser = new OptionParser()
+ {
+ {
+ acceptsAll(asList("H", "host")).withRequiredArg().ofType(String.class)
+ .describedAs("the JBoss AS instance's JNP host (may be a hostname or an IP address)");
+ acceptsAll(asList("P", "port")).withRequiredArg().ofType(Integer.class)
+ .describedAs("the JBoss AS instance's the JNP port");
+ acceptsAll(asList("u", "username")).withRequiredArg().ofType(String.class)
+ .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("h", "?", "help"), "display help");
+ acceptsAll(asList("v", "verbose"), "enable verbose output");
+ //accepts( "output-file" ).withOptionalArg().ofType( File.class ).describedAs( "file" );
+ }
+ };
+
+ OptionSet options = optionParser.parse(args);
+
+ if (options.has("help"))
+ optionParser.printHelpOn(this.outputWriter);
+
+ this.host = (String)options.valueOf("host");
+ this.port = (Integer)options.valueOf("port");
+ this.username = (String)options.valueOf("username");
+ this.password = (String)options.valueOf("password");
+ this.verbose = options.has("verbose");
+
+ ClientCommand connectCommand = COMMANDS.get(ConnectCommand.COMMAND_NAME);
+ OptionParser connectOptionParser = connectCommand.getOptionParser();
+ List<String> connectOptions = new ArrayList<String>();
+ if (this.host != null)
+ {
+ connectOptions.add("--host");
+ connectOptions.add(this.host);
+ }
+ if (this.port != null)
+ {
+ connectOptions.add("--port");
+ connectOptions.add(this.port.toString());
+ }
+ if (this.username != null)
+ {
+ connectOptions.add("--username");
+ connectOptions.add(this.username);
+ }
+ if (this.password != null)
+ {
+ connectOptions.add("--password");
+ connectOptions.add(this.password);
+ }
+ OptionSet connectOptionSet = connectOptionParser.parse(connectOptions.toArray(new String[connectOptions.size()]));
+ connectCommand.execute(this, connectOptionSet);
+ }
+
+/*
+ public RHQRemoteClient getRemoteClient() {
+ return remoteClient;
+ }
+
+ public void setRemoteClient(RHQRemoteClient remoteClient) {
+ this.remoteClient = remoteClient;
+ if (remoteClient != null) {
+ consoleReader.addCompletor(
+ new ArgumentCompletor(
+ new Completor[]{
+ new SimpleCompletor("help"),
+ new SimpleCompletor("api"),
+ new SimpleCompletor(this.getRemoteClient().getAllServices().keySet().toArray(new String[this.getRemoteClient().getAllServices().size()]))}));
+
+ consoleReader.addCompletor(new ServiceCompletor(this.getRemoteClient().getAllServices()));
+ }
+ }
+*/
+
+ public PrintWriter getPrintWriter()
+ {
+ return outputWriter;
+ }
+
+ public int getConsoleWidth()
+ {
+ return this.consoleReader.getTermwidth();
+ }
+
+
+ public Map<String, ClientCommand> getCommands()
+ {
+ return COMMANDS;
+ }
+
+ public ProfileServiceConnection getConnection()
+ {
+ return connection;
+ }
+
+ public void setConnection(ProfileServiceConnection connection)
+ {
+ this.connection = connection;
+ }
+
+ public void setHost(String host)
+ {
+ this.host = host;
+ }
+
+ public void setPort(Integer port)
+ {
+ this.port = port;
+ }
+
+ public boolean isVerbose()
+ {
+ return this.verbose;
+ }
+
+ private static <T> List<T> asList(T... items)
+ {
+ return Arrays.asList(items);
+ }
+}
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/AdminClientMain.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/AbstractClientCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/AbstractClientCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/AbstractClientCommand.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,44 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.command;
+
+import java.util.Arrays;
+import java.util.List;
+
+import joptsimple.OptionParser;
+
+/**
+ * @author Ian Springer
+ */
+public abstract class AbstractClientCommand implements ClientCommand
+{
+ protected <T> List<T> asList(T... items)
+ {
+ return Arrays.asList(items);
+ }
+
+ public OptionParser getOptionParserWithHelpOptionSpec()
+ {
+ getOptionParser().acceptsAll(asList("h", "?", "help"), "display help");
+ return getOptionParser();
+ }
+}
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/AbstractClientCommand.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/ClientCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,82 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.command;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.AdminClientMain;
+
+/**
+ * @author Ian Springer
+ */
+public interface ClientCommand
+{
+ /**
+ * All implementations must indicate what the prompt command is that will trigger its execution. This method returns
+ * the prompt command name.
+ *
+ * @return the prompt command string - if the first prompt argument is this value, then this prompt command will be
+ * executed.
+ */
+ String getPromptCommandString();
+
+ /**
+ * Executes the agent prompt command with the given arguments.
+ *
+ * @param client the ClientMain class itself
+ * @param args the arguments passed to the agent on the agent prompt
+ * @return <code>true</code> if the agent can continue accepting prompt commands; <code>false</code> if the agent
+ * should die
+ */
+ boolean execute(AdminClientMain client, OptionSet options);
+
+ /**
+ * Returns a help summary to describe to the user what the prompt command does and its purpose. It is usually a
+ * short one line help summary.
+ *
+ * @return help string
+ */
+ String getHelp();
+
+ /**
+ * Returns a detailed help message to describe to the user what the command's syntax is and any detailed information
+ * that is useful to the user that wants to use this command.
+ *
+ * @return detailed help string
+ */
+ String getDetailedHelp();
+
+ /**
+ * TODO
+ *
+ * @return
+ */
+ OptionParser getOptionParser();
+
+ /**
+ * TODO
+ *
+ * @return
+ */
+ boolean isConnectionRequired();
+}
\ No newline at end of file
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ClientCommand.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/ConnectCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.command;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.AdminClientMain;
+import org.jboss.adminclient.connection.ProfileServiceConnection;
+import org.jboss.adminclient.connection.ProfileServiceConnectionProvider;
+import org.jboss.adminclient.connection.RemoteProfileServiceConnectionProvider;
+
+/**
+ * @author Ian Springer
+ */
+public class ConnectCommand extends AbstractClientCommand
+{
+ public static final String COMMAND_NAME = "connect";
+
+ public String getPromptCommandString()
+ {
+ return COMMAND_NAME;
+ }
+
+ public OptionParser getOptionParser()
+ {
+ return new OptionParser()
+ {
+ {
+ acceptsAll(asList("H", "host")).withRequiredArg().ofType(String.class)
+ .describedAs("the JBoss AS instance's JNP host (may be a hostname or an IP address)");
+ acceptsAll(asList("P", "port")).withRequiredArg().ofType(String.class)
+ .describedAs("the JBoss AS instance's the JNP port");
+ acceptsAll(asList("u", "username")).withRequiredArg().ofType(String.class)
+ .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");
+ }
+ };
+ }
+
+ public boolean execute(AdminClientMain client, OptionSet options)
+ {
+ 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;
+
+ 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);
+ }
+ return true;
+ }
+
+ public String getHelp()
+ {
+ return "Connect to the JBoss AS Profile Service.";
+ }
+
+ public String getDetailedHelp()
+ {
+ return null;
+ }
+
+ public boolean isConnectionRequired()
+ {
+ return false;
+ }
+}
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ConnectCommand.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/DisconnectCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/DisconnectCommand.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.command;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.AdminClientMain;
+
+/**
+ * @author Ian Springer
+ */
+public class DisconnectCommand extends AbstractClientCommand
+{
+ public String getPromptCommandString()
+ {
+ return "disconnect";
+ }
+
+ public OptionParser getOptionParser()
+ {
+ return new OptionParser();
+ }
+
+ public boolean execute(AdminClientMain client, OptionSet options)
+ {
+ 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);
+ }
+ return true;
+ }
+
+ public String getHelp()
+ {
+ return "Disconnect from the JBoss AS Profile Service.";
+ }
+
+ 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/DisconnectCommand.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/ListComponentsCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListComponentsCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListComponentsCommand.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.command;
+
+import java.util.List;
+import java.util.Set;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.AdminClientMain;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
+
+/**
+ * @author Ian Springer
+ */
+public class ListComponentsCommand extends AbstractClientCommand
+{
+ public String getPromptCommandString()
+ {
+ return "listcomponents";
+ }
+
+ public OptionParser getOptionParser()
+ {
+ return new OptionParser();
+ }
+
+ public boolean execute(AdminClientMain client, OptionSet options)
+ {
+ List<String> nonOptionArgs = options.nonOptionArguments();
+ if (nonOptionArgs.size() != 2)
+ throw new IllegalArgumentException("Usage: " + getPromptCommandString() + " <type> <subtype>");
+ String type = nonOptionArgs.get(0);
+ String subtype = nonOptionArgs.get(1);
+ ManagementView managementView = client.getConnection().getManagementView();
+ ComponentType componentType = new ComponentType(type, subtype);
+ Set<ManagedComponent> components;
+ try
+ {
+ components = managementView.getComponentsForType(componentType);
+ }
+ catch (Exception e)
+ {
+ throw new IllegalStateException(e);
+ }
+ for (ManagedComponent managedComponent : components)
+ client.getPrintWriter().println(managedComponent.getName());
+ return true;
+ }
+
+ public String getHelp()
+ {
+ return "List all components of the specified type.";
+ }
+
+ 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/ListComponentsCommand.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/ListDeploymentsCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListDeploymentsCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/ListDeploymentsCommand.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,83 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.command;
+
+import java.util.Set;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.AdminClientMain;
+import org.jboss.deployers.spi.management.ManagementView;
+
+/**
+ * @author Ian Springer
+ */
+public class ListDeploymentsCommand extends AbstractClientCommand
+{
+ public String getPromptCommandString()
+ {
+ return "listdeployments";
+ }
+
+ public OptionParser getOptionParser()
+ {
+ return new OptionParser()
+ {
+ {
+ acceptsAll(asList("t", "type")).withRequiredArg().ofType(String.class)
+ .describedAs("an optional type (e.g. war) to filter by");
+ }
+ };
+ }
+
+ public boolean execute(AdminClientMain client, OptionSet options)
+ {
+ if (!options.nonOptionArguments().isEmpty())
+ throw new IllegalArgumentException("Usage: " + getPromptCommandString() + " [--type <type>]");
+ String type = (String)options.valueOf("type");
+ ManagementView managementView = client.getConnection().getManagementView();
+ Set<String> deploymentNames;
+ if (type != null)
+ deploymentNames = managementView.getDeploymentNamesForType(type);
+ else
+ deploymentNames = managementView.getDeploymentNames();
+ for (String deploymentName : deploymentNames)
+ client.getPrintWriter().println(deploymentName);
+ return true;
+ }
+
+ public String getHelp()
+ {
+ return "List all deployments, or, if a type is specified, all deployments of that type.";
+ }
+
+ 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/ListDeploymentsCommand.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/QuitCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/QuitCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/QuitCommand.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,66 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.command;
+
+import joptsimple.OptionParser;
+import joptsimple.OptionSet;
+
+import org.jboss.adminclient.AdminClientMain;
+
+/**
+ * @author Ian Springer
+ */
+public class QuitCommand extends AbstractClientCommand
+{
+ public String getPromptCommandString()
+ {
+ return "quit";
+ }
+
+ public OptionParser getOptionParser()
+ {
+ return new OptionParser();
+ }
+
+ public boolean execute(AdminClientMain client, OptionSet options)
+ {
+ if (!options.nonOptionArguments().isEmpty())
+ throw new IllegalArgumentException("Usage: " + getPromptCommandString());
+ client.getPrintWriter().println("Goodbye.");
+ return false;
+ }
+
+ public String getHelp()
+ {
+ return "Quit this program.";
+ }
+
+ public String getDetailedHelp()
+ {
+ return null;
+ }
+
+ public boolean isConnectionRequired()
+ {
+ return false;
+ }
+}
\ No newline at end of file
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/QuitCommand.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/RefreshCommand.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/RefreshCommand.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/command/RefreshCommand.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,74 @@
+/*
+ * 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 RefreshCommand extends AbstractClientCommand
+{
+ public String getPromptCommandString()
+ {
+ return "refresh";
+ }
+
+ public OptionParser getOptionParser()
+ {
+ return new OptionParser();
+ }
+
+ public boolean execute(AdminClientMain client, OptionSet options)
+ {
+ if (!options.nonOptionArguments().isEmpty())
+ throw new IllegalArgumentException("Usage: " + getPromptCommandString());
+ try
+ {
+ ManagementView managementView = client.getConnection().getManagementView();
+ managementView.load();
+ client.getPrintWriter().println(managementView.getDeploymentNames());
+ client.getPrintWriter().println("Refreshed management view.");
+ }
+ catch (Exception e)
+ {
+ client.getPrintWriter().println("Failed to refresh management view: " + e);
+ }
+ 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/RefreshCommand.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/connection/AbstractProfileServiceConnectionProvider.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/AbstractProfileServiceConnectionProvider.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/AbstractProfileServiceConnectionProvider.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,98 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.connection;
+
+import java.util.Properties;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author Ian Springer
+ */
+public abstract class AbstractProfileServiceConnectionProvider implements ProfileServiceConnectionProvider
+{
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ private ProfileServiceConnectionImpl existingConnection;
+ private boolean connected;
+
+ public final ProfileServiceConnection connect()
+ {
+ ProfileServiceConnectionImpl connection = doConnect();
+ this.connected = true;
+ if (this.existingConnection == null)
+ this.existingConnection = connection;
+ return this.existingConnection;
+ }
+
+ protected abstract ProfileServiceConnectionImpl doConnect();
+
+ public boolean isConnected()
+ {
+ return this.connected;
+ }
+
+ public final void disconnect()
+ {
+ this.connected = false;
+ doDisconnect();
+ }
+
+ protected abstract void doDisconnect();
+
+ public ProfileServiceConnection getExistingConnection()
+ {
+ return this.existingConnection;
+ }
+
+ protected InitialContext createInitialContext(Properties env)
+ {
+ InitialContext initialContext;
+ this.log.debug("Creating JNDI InitialContext with env [" + env + "]...");
+ try
+ {
+ initialContext = new InitialContext(env);
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException("Failed to create JNDI InitialContext.", e);
+ }
+ this.log.debug("Created JNDI InitialContext [" + initialContext + "].");
+ return initialContext;
+ }
+
+ protected Object lookup(InitialContext initialContext, String name)
+ {
+ try
+ {
+ return initialContext.lookup(name);
+ }
+ catch (NamingException e)
+ {
+ throw new RuntimeException("Failed to lookup JNDI name '" + name + "' from InitialContext.", e);
+ }
+ }
+}
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/AbstractProfileServiceConnectionProvider.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/connection/ProfileServiceConnection.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnection.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnection.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,40 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.connection;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.profileservice.spi.ProfileService;
+
+/**
+ * @author Ian Springer
+ */
+public interface ProfileServiceConnection
+{
+ ProfileServiceConnectionProvider getConnectionProvider();
+
+ ProfileService getProfileService();
+
+ ManagementView getManagementView();
+
+ DeploymentManager getDeploymentManager();
+}
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnection.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/connection/ProfileServiceConnectionImpl.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnectionImpl.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnectionImpl.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.connection;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+
+/**
+ * @author Ian Springer
+ */
+public class ProfileServiceConnectionImpl implements ProfileServiceConnection
+{
+ private static final ProfileKey DEFAULT_PROFILE_KEY = new ProfileKey(ProfileKey.DEFAULT);
+
+ private AbstractProfileServiceConnectionProvider connectionProvider;
+ private ProfileService profileService;
+ private ManagementView managementView;
+ private DeploymentManager deploymentManager;
+
+ protected ProfileServiceConnectionImpl(AbstractProfileServiceConnectionProvider connectionProvider,
+ ProfileService profileService, ManagementView managementView, DeploymentManager deploymentManager)
+ {
+ this.connectionProvider = connectionProvider;
+ this.profileService = profileService;
+ this.managementView = managementView;
+ this.managementView.load();
+ this.deploymentManager = deploymentManager;
+ // Load and associate the given profile with the DeploymentManager for future operations. This is mandatory
+ // in order for us to be able to successfully invoke the various DeploymentManager methods.
+ try
+ {
+ this.deploymentManager.loadProfile(DEFAULT_PROFILE_KEY);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public ProfileServiceConnectionProvider getConnectionProvider()
+ {
+ return this.connectionProvider;
+ }
+
+ public ProfileService getProfileService()
+ {
+ return this.profileService;
+ }
+
+ public ManagementView getManagementView()
+ {
+ return this.managementView;
+ }
+
+ public DeploymentManager getDeploymentManager()
+ {
+ return this.deploymentManager;
+ }
+}
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnectionImpl.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/connection/ProfileServiceConnectionProvider.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnectionProvider.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnectionProvider.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,36 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.connection;
+
+/**
+ * @author Ian Springer
+ */
+public interface ProfileServiceConnectionProvider
+{
+ boolean isConnected();
+
+ ProfileServiceConnection connect();
+
+ void disconnect();
+
+ ProfileServiceConnection getExistingConnection();
+}
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/ProfileServiceConnectionProvider.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/connection/RemoteProfileServiceConnectionProvider.java
===================================================================
--- branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/RemoteProfileServiceConnectionProvider.java (rev 0)
+++ branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/RemoteProfileServiceConnectionProvider.java 2009-05-06 22:36:36 UTC (rev 88309)
@@ -0,0 +1,121 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.adminclient.connection;
+
+import java.util.Properties;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.deployers.spi.management.deploy.DeploymentManager;
+import org.jboss.profileservice.spi.ProfileService;
+
+/**
+ * @author Ian Springer
+ */
+public class RemoteProfileServiceConnectionProvider extends AbstractProfileServiceConnectionProvider
+{
+ private static final String NAMING_CONTEXT_FACTORY = "org.jnp.interfaces.NamingContextFactory";
+ private static final String JNDI_LOGIN_INITIAL_CONTEXT_FACTORY = "org.jboss.security.jndi.JndiLoginInitialContextFactory";
+
+ private static final String PROFILE_SERVICE_JNDI_NAME = "ProfileService";
+ private static final String SECURE_PROFILE_SERVICE_JNDI_NAME = "SecureProfileService/remote";
+ private static final String SECURE_MANAGEMENT_VIEW_JNDI_NAME = "SecureManagementView/remote";
+ private static final String SECURE_DEPLOYMENT_MANAGER_JNDI_NAME = "SecureDeploymentManager/remote";
+
+ private static final String JNP_DISABLE_DISCOVERY_JNP_INIT_PROP = "jnp.disableDiscovery";
+
+ /**
+ * This is the timeout for the initial attempt to establish the remote connection.
+ */
+ private static final int JNP_TIMEOUT = 60 * 1000; // 60 seconds
+ /**
+ * This is the timeout for methods invoked on the remote ProfileService. NOTE: This timeout comes into play if the
+ * JBossAS instance has gone down since the original JNP connection was made.
+ */
+ private static final int JNP_SO_TIMEOUT = 60 * 1000; // 60 seconds
+
+ private final Log log = LogFactory.getLog(this.getClass());
+
+ private String providerURL;
+ private String principal;
+ private String credentials;
+
+ public RemoteProfileServiceConnectionProvider(String providerURL, String principal, String credentials)
+ {
+ this.providerURL = providerURL;
+ this.principal = principal;
+ this.credentials = credentials;
+ }
+
+ protected ProfileServiceConnectionImpl doConnect()
+ {
+ Properties env = new Properties();
+ env.setProperty(Context.PROVIDER_URL, this.providerURL);
+ ProfileService profileService;
+ ManagementView managementView;
+ DeploymentManager deploymentManager;
+ ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
+ try
+ {
+ Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
+ if (this.principal != null)
+ {
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, JNDI_LOGIN_INITIAL_CONTEXT_FACTORY);
+ env.setProperty(Context.SECURITY_PRINCIPAL, this.principal);
+ env.setProperty(Context.SECURITY_CREDENTIALS, this.credentials);
+ log.debug("Connecting to Profile Service via remote JNDI using env [" + env + "]...");
+ InitialContext initialContext = createInitialContext(env);
+ profileService = (ProfileService)lookup(initialContext, SECURE_PROFILE_SERVICE_JNDI_NAME);
+ managementView = (ManagementView)lookup(initialContext, SECURE_MANAGEMENT_VIEW_JNDI_NAME);
+ deploymentManager = (DeploymentManager)lookup(initialContext, SECURE_DEPLOYMENT_MANAGER_JNDI_NAME);
+ }
+ else
+ {
+ env.setProperty(Context.INITIAL_CONTEXT_FACTORY, NAMING_CONTEXT_FACTORY);
+ env.setProperty(JNP_DISABLE_DISCOVERY_JNP_INIT_PROP, "true");
+ // Make sure the timeout always happens, even if the JBoss server is hung.
+ env.setProperty("jnp.timeout", String.valueOf(JNP_TIMEOUT));
+ env.setProperty("jnp.sotimeout", String.valueOf(JNP_SO_TIMEOUT));
+ log.debug("Connecting to Profile Service via remote JNDI using env [" + env + "]...");
+ InitialContext initialContext = createInitialContext(env);
+ profileService = (ProfileService)lookup(initialContext, PROFILE_SERVICE_JNDI_NAME);
+ managementView = profileService.getViewManager();
+ deploymentManager = profileService.getDeploymentManager();
+ }
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(originalContextClassLoader);
+ }
+ return new ProfileServiceConnectionImpl(this, profileService, managementView, deploymentManager);
+ }
+
+ protected void doDisconnect()
+ {
+ return;
+ }
+}
Property changes on: branches/Branch_5_x/adminclient/src/main/java/org/jboss/adminclient/connection/RemoteProfileServiceConnectionProvider.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