geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r567809 - in /geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands: ./ src/main/groovy/org/apache/geronimo/commands/
Date Mon, 20 Aug 2007 20:07:42 GMT
Author: jdillon
Date: Mon Aug 20 13:07:41 2007
New Revision: 567809

URL: http://svn.apache.org/viewvc?rev=567809&view=rev
Log:
Add custom logging to strip off to set emacs mode ant adapt to JCL
Bring back the server proxy

Added:
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
  (with props)
    geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java
  (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

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?rev=567809&r1=567808&r2=567809&view=diff
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/pom.xml (original)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/pom.xml Mon Aug 20 13:07:41
2007
@@ -45,16 +45,16 @@
             <version>1.1-beta-2</version>
         </dependency>
         
-        <!--
         <dependency>
             <groupId>org.apache.geronimo.modules</groupId>
             <artifactId>geronimo-kernel</artifactId>
             <version>${version}</version>
         </dependency>
-        -->
     </dependencies>
 
     <build>
+        <sourceDirectory>${pom.basedir}/src/main/groovy</sourceDirectory>
+        
         <plugins>
             <plugin>
                 <groupId>org.codehaus.mojo.groovy</groupId>

Added: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java?rev=567809&view=auto
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
(added)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AntBuilder.java
Mon Aug 20 13:07:41 2007
@@ -0,0 +1,106 @@
+/*
+ * 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 java.io.PrintStream;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildLogger;
+import org.apache.tools.ant.DefaultLogger;
+
+import org.apache.commons.logging.Log;
+
+/**
+ * Custom AntBuilder to hook up to desired logging muck.
+ *
+ * @version $Id$
+ */
+public class AntBuilder
+    extends groovy.util.AntBuilder
+{
+    public AntBuilder(final Log log) {
+        super(createProject(log));
+    }
+
+    protected static Project createProject(final Log log) {
+        assert log != null;
+
+        Project project = new Project();
+
+        // Add a custom adapter for logging
+        BuildLogger logger = new LogAdapter(log);
+        logger.setOutputPrintStream(System.out);
+        logger.setErrorPrintStream(System.err);
+
+        // Allow debug messages from Ant tasks when `mvn -X` is used
+        if (log.isDebugEnabled()) {
+            logger.setMessageOutputLevel(Project.MSG_DEBUG);
+        }
+        else {
+            logger.setMessageOutputLevel(Project.MSG_INFO);
+        }
+
+        // Do not print task prefixes
+        logger.setEmacsMode(true);
+
+        project.addBuildListener(logger);
+
+        project.init();
+        project.getBaseDir();
+
+        return project;
+    }
+
+    private static class LogAdapter
+        extends DefaultLogger
+    {
+        protected Log log;
+
+        public LogAdapter(final Log log) {
+            assert log != null;
+
+            this.log = log;
+        }
+
+        protected void printMessage(final String message, final PrintStream stream, final
int priority) {
+            assert message != null;
+            assert stream != null;
+
+            switch (priority) {
+                case Project.MSG_ERR:
+                    log.error(message);
+                    break;
+
+                case Project.MSG_WARN:
+                    log.warn(message);
+                    break;
+
+                case Project.MSG_INFO:
+                    log.info(message);
+                    break;
+
+                case Project.MSG_VERBOSE:
+                case Project.MSG_DEBUG:
+                    log.debug(message);
+                    break;
+            }
+        }
+    }
+}

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

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

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

Added: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java?rev=567809&view=auto
==============================================================================
--- geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java
(added)
+++ geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java
Mon Aug 20 13:07:41 2007
@@ -0,0 +1,228 @@
+/**
+ *  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 java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.Iterator;
+import java.io.IOException;
+
+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$
+ */
+public class ServerProxy
+{
+    private static final Log log = LogFactory.getLog(ServerProxy.class);
+
+    private JMXServiceURL url;
+
+    private Map environment;
+
+    private MBeanServerConnection mbeanConnection;
+
+    private Throwable lastError;
+
+    public ServerProxy(final JMXServiceURL url, final Map environment) throws Exception {
+        init(url, environment);
+    }
+
+    public ServerProxy(final String hostname, final int port, final String username, final
String password) throws Exception {
+        //
+        // TODO: Check if this is the right way to build up the URI
+        //
+        
+        this("service:jmx:rmi://" + hostname + "/jndi/rmi://" + hostname + ":" + port + "/JMXConnector",
username, password);
+    }
+
+    public ServerProxy(final String url, final String username, final String password) throws
Exception {
+        assert url != null;
+        assert username != null;
+        assert password != null;
+        
+        Map env = new HashMap();
+        env.put("jmx.remote.credentials", new String[] {username, password});
+
+        init(new JMXServiceURL(url), env);
+    }
+
+    private void init(final JMXServiceURL url, final Map environment) throws Exception {
+        assert url != null;
+        assert environment != null;
+        
+        this.url = url;
+        this.environment = new HashMap();
+        this.environment.put("jmx.remote.credentials", new String[] {"system", "manager"});
+
+        log.debug("Initialized with URL: " + url + ", environment: " + environment);
+    }
+
+    private MBeanServerConnection getConnection() throws IOException {
+        if (this.mbeanConnection == null) {
+            log.debug("Connecting to: " + url);
+            
+            JMXConnector connector = JMXConnectorFactory.connect(url, environment);
+            this.mbeanConnection = connector.getMBeanServerConnection();
+            
+            log.debug("Connected");
+        }
+
+        return mbeanConnection;
+    }
+
+    public boolean isFullyStarted() {
+        boolean fullyStarted = true;
+
+        try {
+            AbstractNameQuery query = new AbstractNameQuery(PersistentConfigurationList.class.getName());
+            Set result = listGBeans(query);
+            Iterator iter = result.iterator();
+            while (iter.hasNext()) {
+                AbstractName name = (AbstractName)iter.next();
+                boolean 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;
+    }
+
+    public String getGeronimoHome() {
+        String home = null;
+
+        try {
+            ObjectName systemInfoQuery = new ObjectName("*:name=ServerInfo,j2eeType=GBean,*");
+
+            getConnection();
+           
+            Set set = this.mbeanConnection.queryNames(systemInfoQuery, null);
+
+            if (set.size() > 0) {
+                ObjectName found = (ObjectName)set.iterator().next();
+                home = (String)this.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;
+    }
+
+    public Throwable getLastError() {
+        return lastError;
+    }
+
+    public void shutdown() {
+        try {
+            invoke("shutdown");
+        }
+        catch (Exception e) {
+            log.warn("Unable to shutdown the server", e);
+            lastError = e;
+        }
+    }
+
+    //
+    // Kernel invocation helpers
+    //
+
+    private Object invoke(final String operation, final Object[] args, final String[] signature)
throws Exception {
+        assert operation != null;
+        assert args != null;
+        assert signature != null;
+
+        return getConnection().invoke(Kernel.KERNEL, operation, args, signature);
+    }
+
+    private Object invoke(final String operation, final Object[] args) throws Exception {
+        assert args != null;
+
+        String[] signature = new String[args.length];
+        for (int i=0; i<args.length; i++) {
+            signature[i] = args[i].getClass().getName();
+        }
+
+        return invoke(operation, args, signature);
+    }
+
+    private Object invoke(final String operation) throws Exception {
+        return invoke(operation, new Object[0]);
+    }
+
+    private Set listGBeans(final AbstractNameQuery query) throws Exception {
+        return (Set)invoke("listGBeans", new Object[] { query });
+    }
+
+    private Object getAttribute(final AbstractName name, final String attribute) throws Exception
{
+        assert name != null;
+        assert attribute != null;
+
+        return invoke("getAttribute", new Object[] { name, attribute });
+    }
+
+    private boolean getBooleanAttribute(final AbstractName name, final String attribute)
throws Exception {
+        Object obj = getAttribute(name, attribute);
+        if (obj instanceof Boolean) {
+            return ((Boolean)obj).booleanValue();
+        }
+        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.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Propchange: geronimo/sandbox/server-gshell-launcher/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ServerProxy.java
------------------------------------------------------------------------------
    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?rev=567809&r1=567808&r2=567809&view=diff
==============================================================================
--- 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
Mon Aug 20 13:07:41 2007
@@ -27,6 +27,8 @@
 import org.apache.commons.cli.OptionBuilder
 import org.apache.commons.cli.Options
 
+import org.apache.geronimo.commands.AntBuilder
+
 /**
  * Starts a new Geronimo server instance.
  *
@@ -237,7 +239,7 @@
         
         log.info('Starting Geronimo server...')
         
-        def ant = new AntBuilder()
+        def ant = new AntBuilder(log)
         
         if (!geronimoHome) {
             geronimoHome = new File(System.properties['gshell.home'])



Mime
View raw message