You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ga...@apache.org on 2008/02/25 21:54:48 UTC

svn commit: r630987 - in /geronimo/server/branches/2.1/framework/modules: geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/

Author: gawor
Date: Mon Feb 25 12:54:43 2008
New Revision: 630987

URL: http://svn.apache.org/viewvc?rev=630987&view=rev
Log:
reuse connection established by deploy/connect for geronimo/stop-server (plus a few other minor fixes) (GERONIMO-3869)

Modified:
    geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy
    geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/DisconnectCommand.groovy
    geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java
    geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StopServerCommand.groovy
    geronimo/server/branches/2.1/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/RemoteDeploymentManager.java

Modified: geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy?rev=630987&r1=630986&r2=630987&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ConnectCommand.groovy Mon Feb 25 12:54:43 2008
@@ -54,7 +54,7 @@
     @Requirement
     PromptReader prompter
 
-    protected Object doExecute() throws Exception {
+    protected Object doExecute() throws Exception {               
         io.out.println("Connecting to Geronimo server: ${hostname}:${port}")
         
         // If the username/password was not configured via cli, then prompt the user for the values
@@ -78,9 +78,22 @@
         def connectionParams = new ConnectionParamsImpl(host: hostname, port: port, user: username, password: password, offline: false)
         def connection = new ServerConnection(connectionParams, io.out, io.inputStream, kernel, deploymentFactory)
 
+        disconnect();
+        
         variables.parent.set("ServerConnection", connection)
 
         io.out.println("Connection established")
         return connection
     }
-}
\ No newline at end of file
+    
+    private void disconnect() {
+        def connection = variables.get("ServerConnection")
+        if (connection) {
+            try {
+            	connection.close()
+            } catch (Exception e) {
+                // ignore
+            }
+        }
+    }
+}

Modified: geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/DisconnectCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/DisconnectCommand.groovy?rev=630987&r1=630986&r2=630987&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/DisconnectCommand.groovy (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/DisconnectCommand.groovy Mon Feb 25 12:54:43 2008
@@ -34,14 +34,18 @@
 {
 
     protected Object doExecute() throws Exception {
-        io.out.println("Disconnecting from Geronimo server")
-
         def connection = variables.get("ServerConnection")
         if (connection) {
-            connection.close()
+            io.out.println("Disconnecting from Geronimo server")
+            try {
+            	connection.close()
+            } catch (Exception e) {
+                // ignore
+            }           
+            variables.parent.unset("ServerConnection")            
+            io.out.println("Connection ended")
+        } else {
+            io.out.println("Not connected")
         }
-        variables.parent.unset("ServerConnection")
-        
-        io.out.println("Connection ended")
     }
 }

Modified: geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java?rev=630987&r1=630986&r2=630987&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java Mon Feb 25 12:54:43 2008
@@ -87,6 +87,10 @@
         log.debug("Initialized with URL: " + url + ", environment: " + environment);
     }
 
+    public ServerProxy(JMXConnector connector) throws Exception {
+        this.mbeanConnection = connector.getMBeanServerConnection();
+    }
+    
     private MBeanServerConnection getConnection() throws IOException {
         if (this.mbeanConnection == null) {
             log.debug("Connecting to: " + url);

Modified: geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StopServerCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StopServerCommand.groovy?rev=630987&r1=630986&r2=630987&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StopServerCommand.groovy (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StopServerCommand.groovy Mon Feb 25 12:54:43 2008
@@ -24,6 +24,7 @@
 import org.apache.geronimo.gshell.command.CommandSupport
 import org.apache.geronimo.gshell.command.annotation.Requirement
 import org.apache.geronimo.gshell.console.PromptReader
+import org.apache.geronimo.deployment.plugin.jmx.RemoteDeploymentManager
 
 /**
  * Stops a running Geronimo server instance.
@@ -31,46 +32,23 @@
  * @version $Rev$ $Date$
  */
 @CommandComponent(id='geronimo-commands:stop-server', description="Stop a Geronimo server")
-class StopServerCommand
-    extends CommandSupport
-{
-    @Option(name='-s', aliases=['--hostname', '--server'], description='Hostname, default localhost')
-    String hostname = 'localhost'
-
-    @Option(name='-p', aliases=['--port'], description='Port, default 1099')
-    int port = 1099
-
-    @Option(name='-u', aliases=['--username'], description='Username')
-    String username
-    
-    @Option(name='-w', aliases=['--password'], description='Password')
-    String password
-    
-    @Requirement
-    PromptReader prompter
+class StopServerCommand extends ConnectCommand {
     
     protected Object doExecute() throws Exception {
-        io.out.println("Stopping Geronimo server: ${hostname}:${port}")
-        
-        // If the username/password was not configured via cli, then prompt the user for the values
-        if (username == null || password == null) {
-            if (username == null) {
-                username = prompter.readLine("Username: ");
-            }
-
-            if (password == null) {
-                password = prompter.readPassword("Password: ");
-            }
-
-            //
-            // TODO: Handle null inputs...
-            //
+        def connection = variables.get("ServerConnection")
+        if (!connection) {
+            connection = super.doExecute()
         }
+                         
+        io.out.println("Stopping Geronimo server")
+        
+        RemoteDeploymentManager deploymentManager = 
+            (RemoteDeploymentManager)connection.getDeploymentManager();
         
-        def server = new ServerProxy(hostname, port, username, password)
+        def server = new ServerProxy(deploymentManager.getJMXConnector())
 
         server.shutdown();
 
-        io.out.println("Shutdown request has been issued");
+        io.out.println("Shutdown request has been issued");        
     }
-}
\ No newline at end of file
+}

Modified: geronimo/server/branches/2.1/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/RemoteDeploymentManager.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/2.1/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/RemoteDeploymentManager.java?rev=630987&r1=630986&r2=630987&view=diff
==============================================================================
--- geronimo/server/branches/2.1/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/RemoteDeploymentManager.java (original)
+++ geronimo/server/branches/2.1/framework/modules/geronimo-deploy-jsr88/src/main/java/org/apache/geronimo/deployment/plugin/jmx/RemoteDeploymentManager.java Mon Feb 25 12:54:43 2008
@@ -89,6 +89,10 @@
         checkSameMachine(hostname);
     }
 
+    public JMXConnector getJMXConnector() {
+        return this.jmxConnector;
+    }
+    
     public boolean isSameMachine() {
         return isSameMachine;
     }