geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r563023 - in /geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands: ./ src/main/groovy/org/apache/geronimo/commands/ src/main/resources/org/apache/geronimo/commands/
Date Mon, 06 Aug 2007 04:12:28 GMT
Author: jdillon
Date: Sun Aug  5 21:12:27 2007
New Revision: 563023

URL: http://svn.apache.org/viewvc?view=rev&rev=563023
Log:
Adding cli bits, commiting bits from thurs-fri when I was offline

Added:
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.groovy
  (with props)
Modified:
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/pom.xml
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties

Modified: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/pom.xml?view=diff&rev=563023&r1=563022&r2=563023
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/pom.xml (original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/pom.xml Sun Aug  5 21:12:27
2007
@@ -44,6 +44,12 @@
             <artifactId>groovy-all</artifactId>
             <version>1.1-beta-2</version>
         </dependency>
+        
+        <dependency>
+            <groupId>org.apache.geronimo.modules</groupId>
+            <artifactId>geronimo-kernel</artifactId>
+            <version>${version}</version>
+        </dependency>
     </dependencies>
 
     <build>

Added: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.groovy?view=auto&rev=563023
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.groovy
(added)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.groovy
Sun Aug  5 21:12:27 2007
@@ -0,0 +1,214 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License") you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.geronimo.commands
+
+import javax.management.remote.JMXServiceURL
+import javax.management.remote.JMXConnector
+import javax.management.remote.JMXConnectorFactory
+import javax.management.MBeanServerConnection
+import javax.management.ObjectName
+
+//
+// FIXME: It should be possible to query state with-out any Geronimo classes,
+//        just using JMX interfaces.
+//
+
+import org.apache.geronimo.gbean.AbstractName
+import org.apache.geronimo.gbean.AbstractNameQuery
+import org.apache.geronimo.kernel.Kernel
+import org.apache.geronimo.kernel.config.PersistentConfigurationList
+
+import org.apache.commons.logging.Log
+import org.apache.commons.logging.LogFactory
+
+/**
+ * Helper to communicate with a remote server via JMX.
+ *
+ * @version $Rev$ $Date$
+ */
+class ServerProxy
+{
+    private Log log = LogFactory.getLog(ServerProxy.class)
+
+    private JMXServiceURL url
+
+    private Map environment
+
+    private MBeanServerConnection mbeanConnection
+
+    Throwable lastError
+
+    ServerProxy(JMXServiceURL url, Map environment) {
+        init(url, environment)
+    }
+
+    ServerProxy(String hostname, int port, String username, String password) {
+        this("service:jmx:rmi://$hostname/jndi/rmi://$hostname:$port/JMXConnector", username,
password)
+    }
+
+    ServerProxy(String url, String username, String password) {
+        assert url
+        assert username
+        assert password
+        
+        def env = [:]
+        env['jmx.remote.credentials'] = [ username, password ]
+
+        init(new JMXServiceURL(url), env)
+    }
+
+    private void init(JMXServiceURL url, Map environment) {
+        assert url
+        assert environment
+        
+        this.url = url
+        this.environment = [:]
+        this.environment['jmx.remote.credentials'] = ['system', 'manager']
+
+        log.debug("Initialized with URL: $url, environment: environment")
+    }
+
+    private MBeanServerConnection getConnection() {
+        if (!mbeanConnection) {
+            log.debug("Connecting to: $url")
+            
+            JMXConnector connector = JMXConnectorFactory.connect(url, environment)
+            mbeanConnection = connector.mBeanServerConnection
+            
+            log.debug('Connected')
+        }
+
+        return mbeanConnection
+    }
+
+    boolean isFullyStarted() {
+        boolean fullyStarted = true
+
+        try {
+            def query = new AbstractNameQuery(PersistentConfigurationList.class.name)
+            def result = listGBeans(query)
+            
+            for (name in result) {
+                def started = getBooleanAttribute(name, 'kernelFullyStarted')
+                if (!started) {
+                    fullyStarted = false
+                    break
+                }
+            }
+        }
+        catch (IOException e) {
+            log.debug('Connection failure ignoring', e)
+            fullyStarted = false
+            lastError = e
+        }
+        catch (Exception e) {
+            log.debug('Unable to determine if the server is fully started', e)
+            fullyStarted = false
+            lastError = e
+        }
+        
+        return fullyStarted
+    }
+
+    String getGeronimoHome() {
+        String home = null
+
+        try {
+            def systemInfoQuery = new ObjectName('*:name=ServerInfo,j2eeType=GBean,*')
+
+            getConnection()
+
+            def set = mbeanConnection.queryNames(systemInfoQuery, null)
+            
+            if (set.size() > 0) {
+                def found = set[0] // set.iterator().next()
+                home = mbeanConnection.getAttribute(found, 'currentBaseDirectory')
+            }
+        }
+        catch (IOException e) {
+            log.debug('Connection failure ignoring', e)
+            lastError = e
+        }
+        catch (Exception e) {
+            log.debug('Unable to determine if the server home directory', e)
+            lastError = e
+        }
+        
+        return home
+    }
+
+    void shutdown() {
+        try {
+            invoke('shutdown')
+        }
+        catch (Exception e) {
+            log.warn('Unable to shutdown the server', e)
+            lastError = e
+        }
+    }
+
+    //
+    // Kernel invocation helpers
+    //
+
+    private Object invoke(String operation, Object[] args, String[] signature) {
+        assert operation
+        assert args
+        assert signature
+
+        return connection.invoke(Kernel.KERNEL, operation, args, signature)
+    }
+
+    private Object invoke(String operation, Object[] args) {
+        assert args != null
+
+        String[] signature = new String[args.length]
+        args.each {
+            signature[i] = it.class.name
+        }
+
+        return invoke(operation, args, signature)
+    }
+
+    private Object invoke(String operation) {
+        return invoke(operation, new Object[0])
+    }
+
+    private Set listGBeans(AbstractNameQuery query) {
+        return (Set)invoke('listGBeans', [ query ])
+    }
+
+    private Object getAttribute(AbstractName name, String attribute) {
+        assert name != null
+        assert attribute != null
+
+        return invoke('getAttribute', [ name, attribute ])
+    }
+
+    private boolean getBooleanAttribute(AbstractName name, String attribute) {
+        Object obj = getAttribute(name, attribute)
+        if (obj instanceof Boolean) {
+            return obj
+        }
+        else {
+            throw new RuntimeException("Attribute is not of type Boolean: $attribute")
+        }
+    }
+}

Propchange: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.groovy
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.groovy
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.groovy
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy?view=diff&rev=563023&r1=563022&r2=563023
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
(original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/StartServerCommand.groovy
Sun Aug  5 21:12:27 2007
@@ -24,6 +24,8 @@
 import org.apache.geronimo.gshell.command.CommandException
 
 import org.apache.commons.cli.CommandLine
+import org.apache.commons.cli.OptionBuilder
+import org.apache.commons.cli.Options
 
 /**
  * Starts a new Geronimo server instance.
@@ -35,56 +37,25 @@
 {
     File geronimoHome
 
-    /**
-     * Flag to control if we background the server or block Maven execution.
-     */
-    boolean background = false
-    
-    /**
-     * Set the maximum memory for the forked JVM.
-     */
-    String maximumMemory
-
-    /**
-     * The location of the Java Virtual Machine executable to launch the server with.
-     */
     File javaVirtualMachine
     
-    /**
-     * Enable quiet mode.
-     */
+    String javaAgent
+    
+    File logFile
+    
     boolean quiet = false
 
-    /**
-     * Enable verbose mode.
-     */
-    boolean verbose = true
-
-    /**
-     * Enable veryverbose mode.
-     */
+    boolean verbose = false
+
     boolean veryverbose = false
 
-    /**
-     * Time in seconds to wait before terminating the forked JVM.
-     */
     int timeout = -1
-
-    /**
-     * Time in seconds to wait while verifing that the server has started.
-     */
-    int verifyTimeout = -1
-
-    /**
-     * Enable propagation of <tt>org.apache.geronimo.*</tt> and <tt>geronimo.*</tt>
-     * properties from Maven to the forked server process.
-     */
-    boolean propagateGeronimoProperties = true
     
     StartServerCommand() {
         super('start-server')
     }
 
+    /*
     protected String getUsage() {
         //
         // NOTE: super.usage here makes a stack over flow, should probably report to the
groovy folks
@@ -92,13 +63,111 @@
         
         return super.getUsage() // TODO:
     }
-
+    */
+    
+    protected Options getOptions() {
+        def messages = getMessageSource()
+        def options = super.getOptions()
+
+        options.addOption(OptionBuilder.withLongOpt('verbose')
+            .withDescription(messages.getMessage('cli.option.verbose'))
+            .create('v'))
+
+        options.addOption(OptionBuilder.withLongOpt('quiet')
+            .withDescription(messages.getMessage('cli.option.quiet'))
+            .create('q'))
+        
+        options.addOption(OptionBuilder.withLongOpt('logfile')
+            .withDescription(messages.getMessage('cli.option.logfile'))
+            .hasArg()
+            .withArgName('file')
+            .create('l'))
+        
+        options.addOption(OptionBuilder.withLongOpt('timeout')
+            .withDescription(messages.getMessage('cli.option.timeout'))
+            .hasArg()
+            .withArgName('seconds')
+            .create('t'))
+        
+        options.addOption(OptionBuilder.withLongOpt('jvm')
+            .withDescription(messages.getMessage('cli.option.jvm'))
+            .hasArg()
+            .withArgName('dir')
+            .create('j'))
+        
+        options.addOption(OptionBuilder.withLongOpt('property')
+            .withDescription(messages.getMessage('cli.option.property'))
+            .hasArg()
+            .withArgName('name=value')
+            .create('D'))
+        
+        options.addOption(OptionBuilder.withLongOpt('javaopt')
+            .withDescription(messages.getMessage('cli.option.javaopt'))
+            .hasArg()
+            .withArgName('option')
+            .create('J'))
+        
+        options.addOption(OptionBuilder.withLongOpt('home')
+            .withDescription(messages.getMessage('cli.option.home'))
+            .hasArg()
+            .withArgName('dir')
+            .create('H'))
+        
+        options.addOption(OptionBuilder.withLongOpt('javaagent')
+            .withDescription(messages.getMessage('cli.option.javaagent'))
+            .hasArg()
+            .withArgName('jar')
+            .create('A'))
+        
+        return options
+    }
+    
     protected boolean processCommandLine(CommandLine line) throws CommandException {
         assert line
-
-        //
-        // TODO:
-        //
+        
+        def args = line.getArgs()
+        
+        println args
+        
+        def io = getIO()
+        def messages = getMessageSource()
+        
+        if (args.length > 0) {
+            io.err.println(messages.getMessage("info.unexpected_args", args.join(' ')))
+            return true
+        }
+        
+        if (line.hasOption('v')) {
+            verbose = true
+        }
+        
+        if (line.hasOption('q')) {
+            quiet = true
+        }
+        
+        if (line.hasOption('l')) {
+            logFile = new File(line.getOptionValue('l')).canonicalFile
+        }
+        
+        if (line.hasOption('t')) {
+            timeout = Integer.parseInt(line.getOptionValue('t'))
+        }
+        
+        if (line.hasOption('j')) {
+            javaVirtualMachine = new File(line.getOptionValue('j')).canonicalFile
+        }
+        
+        if (line.hasOption('H')) {
+            geronimoHome = new File(line.getOptionValue('H')).canonicalFile
+        }
+        
+        if (line.hasOption('H')) {
+            javaAgent = line.getOptionValue('H')
+        }
+        
+        // -D
+        
+        // -J
         
         return false
     }
@@ -106,13 +175,14 @@
     protected Object doExecute(Object[] args) throws Exception {
         assert args != null
         
+        log.info('Starting Geronimo server...')
+        
         def ant = new AntBuilder()
         
         if (!geronimoHome) {
             geronimoHome = new File(System.properties['gshell.home'])
         }
-        
-        log.info("Geronimo home: $geronimoHome")
+        log.debug("Geronimo home: $geronimoHome")
         
         ant.java(jar: "$geronimoHome/bin/server.jar", dir: geronimoHome, failonerror: true,
fork: true) {
             def node = current.wrapper
@@ -122,53 +192,45 @@
                 node.setAttribute('timeout', "${timeout * 1000}")
             }
             
-            /*
-            if (maximumMemory) {
-                node.setAttribute('maximumMemory', maximumMemory)
-            }
-            
             if (javaVirtualMachine) {
                 if (!javaVirtualMachine.exists()) {
                     fail("Java virtual machine is not valid: $javaVirtualMachine")
                 }
                 
                 log.info("Using Java virtual machine: $javaVirtualMachine")
-                node.setAttribute('jvm', javaVirtualMachine.canonicalPath)
+                node.setAttribute('jvm', javaVirtualMachine)
             }
             
-            if (logOutput) {
-                def file = getLogFile()
-                
-                FileUtils.forceMkdir(file.parentFile)
-                
-                log.info("Redirecting output to: $file")
-                redirector(output: file)
+            if (logFile) {
+                log.info("Redirecting output to: $logFile")
+                logFile.parentFile.mkdirs()
+                redirector(output: logFile)
             }
-            */
+            
             
             //
-            // TODO: Make this optional, so it can be disabled if needed for some reason
+            // TODO: Methodize this...
             //
             
             // Load the Java programming language agent for JPA if the jar exists
             def javaAgentJar = new File(geronimoHome, 'bin/jpa.jar')
-            if (javaAgentJar.exists()) {
-                jvmarg(value: "-javaagent:${javaAgentJar.canonicalPath}")
-            }
-            else {
-                log.warn("Missing JPA agent jar: $javaAgentJar")
+            
+            if (javaAgent) {
+                if (javaAgent.toLowerCase() == 'none') {
+                    javaAgentJar = null
+                }
+                else {
+                    javaAgentJar = new File(javaAgent)
+                }
             }
             
-            // Propagate some properties from Maven to the server if enabled
-            if (propagateGeronimoProperties) {
-                System.properties.each { name, value ->
-                    if (name == 'geronimo.bootstrap.logging.enabled') {
-                        // Skip this property, never propagate it
-                    }
-                    else if (name.startsWith('org.apache.geronimo') || name.startsWith('geronimo'))
{
-                        log.debug("Propagating: $name=$value")
-                        sysproperty(key: name, value: value)
-                    }
+            if (javaAgentJar) {
+                if (javaAgentJar.exists()) {
+                    log.info("Using Java Agent: $javaAgentJar")
+                    jvmarg(value: "-javaagent:${javaAgentJar.canonicalPath}")
+                }
+                else {
+                    log.warn("Missing Java Agent jar: $javaAgentJar")
                 }
             }
             
@@ -189,6 +251,10 @@
                 arg(value: '--verbose')
             }
             
+            //
+            // FIXME: Use -vv, and -vvv for logging control
+            //
+            
             if (veryverbose) {
                 arg(value: '--veryverbose')
             }
@@ -215,26 +281,6 @@
     
     /*
     void execute() {
-        //
-        // TODO: Split this entire method up into a few smaller methods
-        //
-        
-        if (install) {
-            installAssembly()
-        }
-        else {
-            log.info('Skipping assembly installation')
-
-            if (!geronimoHome.exists()) {
-                fail("Missing pre-installed assembly directory: $geronimoHome")
-                
-                // TRIMMED...
-            }
-            catch (Exception e) {
-                errors << e
-            }
-        }
-        
         log.info('Starting Geronimo server...')
         
         // Start the server in a seperate thread

Modified: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties?view=diff&rev=563023&r1=563022&r2=563023
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties
(original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/resources/org/apache/geronimo/commands/StartServerCommandMessages.properties
Sun Aug  5 21:12:27 2007
@@ -27,6 +27,24 @@
 
 cli.option.help=Display this help message
 
+cli.option.verbose=Enable verbose output
+
+cli.option.quiet=Suppress informative and warning messages
+
+cli.option.logfile=Capture console output to file
+
+cli.option.timeout=Specify the timeout for the server process in seconds
+
+cli.option.jvm=Use a specific Java Virtual Machine for server process
+
+cli.option.property=Set a system property
+
+cli.option.javaopt=Set a JVM flag
+
+cli.option.home=Use a specific Geronimo home directory
+
+cli.option.javaagent=Use a specific Java Agent, set to "none" to disable
+
 ##
 ## Option usage (help)
 ##
@@ -34,3 +52,9 @@
 cli.usage.description=Starts a new Geronimo server instance
 
 cli.usage.footer=
+
+##
+## Information messages
+##
+
+info.unexpected_args=Unexpected arguments: %s



Mime
View raw message