geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject cvs commit: incubator-geronimo/modules/maven-plugin/src/java/org/apache/geronimo/deployment/mavenplugin StartRemoteServer.java StopRemoteServer.java WaitForStarted.java
Date Sun, 01 Aug 2004 02:09:06 GMT
djencks     2004/07/31 19:09:06

  Modified:    modules/maven-plugin plugin.jelly project.xml
  Added:       modules/maven-plugin/src/java/org/apache/geronimo/deployment/mavenplugin
                        StartRemoteServer.java StopRemoteServer.java
                        WaitForStarted.java
  Log:
  Support for starting and stopping remote servers in plugin.  The WaitForStarted doesn't
work yet
  
  Revision  Changes    Path
  1.4       +12 -0     incubator-geronimo/modules/maven-plugin/plugin.jelly
  
  Index: plugin.jelly
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/maven-plugin/plugin.jelly,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- plugin.jelly	25 Jul 2004 08:22:06 -0000	1.3
  +++ plugin.jelly	1 Aug 2004 02:09:06 -0000	1.4
  @@ -33,8 +33,20 @@
               className="org.apache.geronimo.deployment.mavenplugin.StartServer"
               method="execute"/>
           <define:jellybean
  +            name="startRemoteServer"
  +            className="org.apache.geronimo.deployment.mavenplugin.StartRemoteServer"
  +            method="execute"/>
  +        <define:jellybean
  +            name="waitForStarted"
  +            className="org.apache.geronimo.deployment.mavenplugin.WaitForStarted"
  +            method="execute"/>
  +        <define:jellybean
               name="stopServer"
               className="org.apache.geronimo.deployment.mavenplugin.StopServer"
  +            method="execute"/>
  +        <define:jellybean
  +            name="stopRemoteServer"
  +            className="org.apache.geronimo.deployment.mavenplugin.StopRemoteServer"
               method="execute"/>
   
       </define:taglib>
  
  
  
  1.18      +3 -1      incubator-geronimo/modules/maven-plugin/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/maven-plugin/project.xml,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- project.xml	28 Jul 2004 19:16:08 -0000	1.17
  +++ project.xml	1 Aug 2004 02:09:06 -0000	1.18
  @@ -18,7 +18,7 @@
   
   <project>
       <pomVersion>3</pomVersion>
  -    <extend>${basedir}/../../etc/project.xml</extend>
  +    <!--extend>${basedir}/../../etc/project.xml</extend-->
       
       <groupId>geronimo</groupId>
       <id>geronimo-deployment-plugin</id>
  @@ -32,6 +32,8 @@
       <package>org.apache.geronimo</package>
       <logo></logo>
   
  +    <currentVersion>1.0-SNAPSHOT</currentVersion>
  +    
       <dependencies>
           <!--dependency>
               <groupId>xml-resolver</groupId>
  
  
  
  1.1                  incubator-geronimo/modules/maven-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StartRemoteServer.java
  
  Index: StartRemoteServer.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.deployment.mavenplugin;
  
  import java.io.File;
  import java.io.IOException;
  import java.io.InputStream;
  import java.io.OutputStream;
  import java.util.ArrayList;
  import java.util.StringTokenizer;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/08/01 02:09:06 $
   *
   * */
  public class StartRemoteServer {
  
      private String geronimoTarget;
      private String configs;
  
      public String getGeronimoTarget() {
          return geronimoTarget;
      }
  
      public void setGeronimoTarget(String geronimoTarget) {
          this.geronimoTarget = geronimoTarget;
      }
  
      public String getConfigs() {
          return configs;
      }
  
      public void setConfigs(String configs) {
          this.configs = configs;
      }
  
      public void execute() throws Exception {
          ArrayList cmd = new ArrayList();
          File root = new File(getGeronimoTarget());
          File systemFile = new File(root, "bin/server.jar");
          String s = java.io.File.separator;
          String java = System.getProperty("java.home")+s+"bin"+s+"java";
  
          cmd.add(java);
  
          cmd.add("-jar");
          cmd.add(systemFile.getCanonicalPath());
  
          for (StringTokenizer st = new StringTokenizer(getConfigs()); st.hasMoreTokens();
) {
              cmd.add(st.nextToken());
          }
          String[] command = (String[]) cmd.toArray(new String[0]);
  
          Runtime runtime = Runtime.getRuntime();
          Process server = runtime.exec( command );
  
  
          // Pipe the processes STDOUT to ours
          InputStream out = server.getInputStream();
          Thread serverOut = new Thread(new Pipe(out, System.out));
          serverOut.setDaemon(true);
          serverOut.start();
  
          // Pipe the processes STDERR to ours
          InputStream err = server.getErrorStream();
          Thread serverErr = new Thread(new Pipe(err, System.err));
          serverErr.setDaemon(true);
          serverErr.start();
  
      }
  
      private final class Pipe implements Runnable {
  
          private final InputStream in;
          private final OutputStream out;
  
          public Pipe(InputStream in, OutputStream out) {
              this.in = in;
              this.out = out;
          }
  
          public void run() {
              int i;
              try {
                  do {
                      i = in.read();
                      out.write(i);
                  } while (i != -1);
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/maven-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/StopRemoteServer.java
  
  Index: StopRemoteServer.java
  ===================================================================
  package org.apache.geronimo.deployment.mavenplugin;
  
  import org.apache.geronimo.kernel.KernelMBean;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.kernel.jmx.MBeanProxyFactory;
  import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl;
  
  import javax.management.MBeanServerConnection;
  import javax.management.remote.JMXConnector;
  import javax.management.remote.JMXServiceURL;
  import javax.management.remote.JMXConnectorFactory;
  import java.util.Map;
  import java.util.HashMap;
  import java.io.IOException;
  
  /**
   */
  public class StopRemoteServer extends AbstractModuleCommand {
  
      private MBeanServerConnection mbServerConnection;
      private KernelMBean kernel;
  
      public void execute() throws Exception {
          String uri = getUri().substring(DeploymentFactoryImpl.URI_PREFIX.length());
          if (!uri.startsWith("jmx")) {
              throw new Exception("bad uri");
          }
  
          Map environment = new HashMap();
          String[] credentials = new String[]{getUsername(), getPassword()};
          environment.put(JMXConnector.CREDENTIALS, credentials);
  
          JMXServiceURL address = new JMXServiceURL("service:" + uri);
          ClassLoader oldcl = Thread.currentThread().getContextClassLoader();
          try {
              Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
              JMXConnector jmxConnector = JMXConnectorFactory.connect(address, environment);
              mbServerConnection = jmxConnector.getMBeanServerConnection();
              kernel = (KernelMBean) MBeanProxyFactory.getProxy(KernelMBean.class, mbServerConnection,
Kernel.KERNEL);
              kernel.shutdown();
  
          } finally {
              Thread.currentThread().setContextClassLoader(oldcl);
          }
  
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/maven-plugin/src/java/org/apache/geronimo/deployment/mavenplugin/WaitForStarted.java
  
  Index: WaitForStarted.java
  ===================================================================
  /**
   *
   * Copyright 2004 The Apache Software Foundation
   *
   *  Licensed 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.deployment.mavenplugin;
  
  import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl;
  import org.apache.geronimo.kernel.Kernel;
  import org.apache.geronimo.kernel.KernelMBean;
  import org.apache.geronimo.kernel.jmx.MBeanProxyFactory;
  import org.apache.geronimo.kernel.management.State;
  
  import javax.management.MBeanServerConnection;
  import javax.management.remote.JMXConnector;
  import javax.management.remote.JMXConnectorFactory;
  import javax.management.remote.JMXServiceURL;
  import java.io.IOException;
  import java.net.URI;
  import java.util.HashMap;
  import java.util.Map;
  
  public class WaitForStarted extends AbstractModuleCommand {
  
      private int maxTries = 20;
  
      private MBeanServerConnection mbServerConnection;
      private KernelMBean kernel;
      private String id;
  
      public String getId() {
          return id;
      }
  
      public void setId(String id) {
          this.id = id;
      }
  
      public void execute() throws Exception {
          String uri = getUri().substring(DeploymentFactoryImpl.URI_PREFIX.length());
          if (!uri.startsWith("jmx")) {
              throw new Exception("bad uri");
          }
  
          Map environment = new HashMap();
          String[] credentials = new String[]{getUsername(), getPassword()};
          environment.put(JMXConnector.CREDENTIALS, credentials);
  
          JMXServiceURL address = new JMXServiceURL("service:" + uri);
          ClassLoader oldcl = Thread.currentThread().getContextClassLoader();
          try {
              Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader());
              for (int tries = maxTries; true; tries--) {
                  try {
                      JMXConnector jmxConnector = JMXConnectorFactory.connect(address, environment);
                      mbServerConnection = jmxConnector.getMBeanServerConnection();
                      kernel = (KernelMBean) MBeanProxyFactory.getProxy(KernelMBean.class,
mbServerConnection, Kernel.KERNEL);
                      break;
                  } catch (IOException e) {
                      if (tries == 0) {
                          throw new Exception("Could not connect");
                      }
                      Thread.sleep(1000);
                  }
              }
          } finally {
              Thread.currentThread().setContextClassLoader(oldcl);
          }
          URI id = new URI(getId());
          for (int tries = maxTries; tries > 0; tries--) {
              int state = kernel.getConfigurationState(id);
              if (state == State.RUNNING_INDEX) {
                  return;
              }
              Thread.sleep(1000);
          }
          throw new Exception("Configuration is not yet started");
      }
  
  }
  
  
  

Mime
View raw message