You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by gd...@apache.org on 2004/07/16 06:39:41 UTC

cvs commit: incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli DeploymentContext.java Deployer.java TextController.java

gdamour     2004/07/15 21:39:41

  Modified:    modules/core/src/java/org/apache/geronimo/console/cli/controller
                        TopLevel.java
               modules/core/src/java/org/apache/geronimo/console/cli
                        DeploymentContext.java Deployer.java
                        TextController.java
  Added:       modules/core/src/java/org/apache/geronimo/console/cli/controller
                        DistributeModule.java ConnectDeploymentManager.java
  Log:
  Re-enables the command line deployer. This latter takes as parameter a list of archives defining
  vendor specific DeploymentFactory implementations as per the JSR 88 specifications.
  
  It is possible to distribute, start and stop a plan or module to a running Geronimo server.
  
  Revision  Changes    Path
  1.4       +35 -22    incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/controller/TopLevel.java
  
  Index: TopLevel.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/controller/TopLevel.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TopLevel.java	10 Mar 2004 09:58:41 -0000	1.3
  +++ TopLevel.java	16 Jul 2004 04:39:41 -0000	1.4
  @@ -22,8 +22,6 @@
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.console.cli.TextController;
   import org.apache.geronimo.console.cli.DeploymentContext;
  -import org.apache.geronimo.console.cli.module.EJBJARInfo;
  -import org.apache.geronimo.console.cli.module.WARInfo;
   
   /**
    * Top-level menu for working with the DeploymentManager.
  @@ -39,20 +37,15 @@
   
       public void execute() {
           while(true) {
  -            if(context.moduleInfo instanceof EJBJARInfo) {
  -                new WorkWithEJBJAR(context).execute();
  -                continue;
  -            } else if(context.moduleInfo instanceof WARInfo) {
  -                new WorkWithWAR(context).execute();
  -                continue;
  -            }
  -            println("\n\nNo J2EE module is currently selected.");
  -            println("  "+(context.connected ? "1)" : "--")+" Control existing deployments (review, start, stop, undeploy)");
  -            println("  2) Select an EJB JAR or WAR to configure, deploy, or redeploy"); //todo: change text when other modules are supported
  -            println("  "+(context.connected ? "3)" : "--")+" Disconnect from the server.");
  +            println("  "+(context.connected ? "--" : "1)")+" Connect to the deployment server");
  +            println("  "+(context.connected ? "2)" : "--")+" Configure a module");
  +            println("  "+(context.connected ? "3)" : "--")+" Control working targets");
  +            println("  "+(context.connected ? "4)" : "--")+" Distribute plan or module");
  +            println("  "+(context.connected ? "5)" : "--")+" Control existing plans or modules");
  +            println("  "+(context.connected ? "6)" : "--")+" Disconnect from the deployment server");
               String choice;
               while(true) {
  -                print("Action ([1-3] or [Q]uit): ");
  +                print("Action ([1-6] or [Q]uit): ");
                   context.out.flush();
                   try {
                       choice = context.in.readLine().trim().toLowerCase();
  @@ -61,21 +54,40 @@
                       return;
                   }
                   if(choice.equals("1")) {
  -                    if(!context.connected) {
  +                    if( context.connected ) {
  +                        println("To re-connect, please disconnect first.");
                           continue;
                       }
  -                    new ControlDeployments(context).execute();
  +                    new ConnectDeploymentManager(context).execute();
                       break;
                   } else if(choice.equals("2")) {
  -                    new SelectModule(context).execute();
  -                    break;
  +                    println("Not yet available");
  +//                    new SelectModule(context).execute();
                   } else if(choice.equals("3")) {
  -                    if(!context.connected) {
  +                    if( !ensureConnected() ) {
  +                        continue;
  +                    }
  +                    new SelectServer(context).execute();
  +                    break;
  +                } else if(choice.equals("4")) {
  +                    if( !ensureConnected() ) {
  +                        continue;
  +                    }
  +                    new DistributeModule(context).execute();
  +                    break;
  +                } else if(choice.equals("5")) {
  +                    if( !ensureConnected() ) {
                           continue;
                       }
  +                    new ControlDeployments(context).execute();
  +                    break;
  +                } else if(choice.equals("6")) {
  +                    if( !ensureConnected() ) {
  +                        continue;
  +                    }
  +                    println("Disconnecting from deployment server...");
                       context.deployer.release();
  -                    context.connected = false;
  -                    println("Released any server resources and disconnected.");
  +                    println("Disconnected.");
                       break;
                   } else if(choice.equals("q")) {
                       return;
  @@ -83,4 +95,5 @@
               }
           }
       }
  +
   }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/controller/DistributeModule.java
  
  Index: DistributeModule.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.console.cli.controller;
  
  import java.io.File;
  import java.io.IOException;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.geronimo.console.cli.DeploymentContext;
  import org.apache.geronimo.console.cli.TextController;
  
  /**
   * Distribute a module to the current deployment manager.
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/16 04:39:41 $
   */
  public class DistributeModule
      extends TextController
  {
  
      private static final Log log = LogFactory.getLog(DistributeModule.class);
  
      public DistributeModule(DeploymentContext context) {
          super(context);
      }
  
      public void execute() {
          context.out.println("\nCurrent directory is "+context.saveDir);
          context.out.println("Select a plan or module to distribute");
          String choice;
          File file;
          while(true) {
              context.out.print("File Name: ");
              context.out.flush();
              try {
                  choice = context.in.readLine().trim();
              } catch(IOException e) {
                  log.error("Unable to read user input", e);
                  return;
              }
              file = new File(context.saveDir, choice);
              if( !file.canRead() || file.isDirectory() ) {
                  context.out.println("ERROR: cannot read from this file.  Please try again.");
                  continue;
              }
              context.saveDir = file.getParentFile();
              break;
          }
  
          println("Starting the distribute operation...");
          context.deployer.distribute(context.targets, file, null);
          println("Distributed.");
      }
  
  }
  
  
  
  1.1                  incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/controller/ConnectDeploymentManager.java
  
  Index: ConnectDeploymentManager.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.console.cli.controller;
  
  import java.io.IOException;
  
  import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
  import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.apache.geronimo.console.cli.DeploymentContext;
  import org.apache.geronimo.console.cli.TextController;
  
  /**
   * Connect to a DeploymentManager.
   *
   * @version $Revision: 1.1 $ $Date: 2004/07/16 04:39:41 $
   */
  public class ConnectDeploymentManager
      extends TextController
  {
  
      private static final Log log = LogFactory.getLog(ConnectDeploymentManager.class);
  
      /**
       * Default URL of a Geronimo DeploymentManager.
       */
      public static final String DEFAULT_URI = "deployer:geronimo:jmx:rmi://localhost/jndi/rmi:/JMXConnector";
      
      public ConnectDeploymentManager(DeploymentContext context) {
          super(context);
      }
  
      public void execute() {
          context.out.println("\n\nEnter deployment server URI. Leave blank for the default URL '" + DEFAULT_URI + "'");
          context.out.print("URI: ");
          context.out.flush();
          try {
              String uri = context.in.readLine();
              if( uri.equals("") ) {
                  uri = DEFAULT_URI;
              }
  
              context.out.println("Enter an optional username");
              context.out.print("Username: ");
              context.out.flush();
              String username = context.in.readLine();
              if( username.equals("") ) {
                  username = null;
              }
  
              context.out.println("Enter an optional password");
              context.out.print("Password: ");
              context.out.flush();
              String password = context.in.readLine();
              if( password.equals("") ) {
                  password = null;
              }
  
              context.out.println("\nConnecting to DeploymentManager " +
                  username + "@" + uri + "...");
              context.deployer = DeploymentFactoryManager.getInstance().getDeploymentManager(uri, username, password);
              context.out.println("Connected.");
              context.connected = true;
              context.uri = uri;
              context.username = username;
              context.password = password;
          } catch(DeploymentManagerCreationException e) {
              log.error("Can't create deployment manager", e);
              return;
          } catch(IOException e) {
              log.error("Unable to read user input", e);
              return;
          }
      }
  
  }
  
  
  
  1.5       +13 -1     incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/DeploymentContext.java
  
  Index: DeploymentContext.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/DeploymentContext.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DeploymentContext.java	10 Mar 2004 09:58:41 -0000	1.4
  +++ DeploymentContext.java	16 Jul 2004 04:39:41 -0000	1.5
  @@ -32,6 +32,18 @@
    * @version $Revision$ $Date$
    */
   public class DeploymentContext {
  +    /**
  +     * URI of the DeploymentManager.
  +     */
  +    public String uri;
  +    /**
  +     * Optional username provided when retrieving the DeploymentManager.
  +     */
  +    public String username;
  +    /**
  +     * Optional password provided when retrieving the DeploymentManager.
  +     */
  +    public String password;
       public DeploymentManager deployer;
       public DeployableObject standardModule;
       public DeploymentConfiguration serverModule;
  
  
  
  1.10      +75 -110   incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/Deployer.java
  
  Index: Deployer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/Deployer.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- Deployer.java	10 Mar 2004 09:58:41 -0000	1.9
  +++ Deployer.java	16 Jul 2004 04:39:41 -0000	1.10
  @@ -24,15 +24,18 @@
   import java.io.OutputStreamWriter;
   import java.io.PrintWriter;
   import java.io.Reader;
  +import java.net.MalformedURLException;
  +import java.net.URL;
  +import java.net.URLClassLoader;
  +import java.util.jar.Attributes;
   import java.util.jar.JarFile;
  +import java.util.jar.Manifest;
  +
   import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
  -import javax.enterprise.deploy.spi.exceptions.DeploymentManagerCreationException;
  -import javax.enterprise.deploy.spi.Target;
  +import javax.enterprise.deploy.spi.factories.DeploymentFactory;
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.console.cli.controller.TopLevel;
  -import org.apache.geronimo.console.cli.module.EJBJARInfo;
  -import org.apache.geronimo.console.cli.module.WARInfo;
   
   /**
    * Initializes a command-line JSR-88 deployer.
  @@ -40,20 +43,80 @@
    * @version $Revision$ $Date$
    */
   public class Deployer {
  +
       private static final Log log = LogFactory.getLog(Deployer.class);
  +
       private final DeploymentContext context = new DeploymentContext();
   
  -    static {
  +    /**
  +     * Entry point of a potential executable jar.
  +     * 
  +     * @param args Array of file names. These files must be .jar files defining
  +     * DeploymentFactories as per the JSR 88 requirements.
  +     */
  +    public static void main(String[] args) {
  +       if ( 0 == args.length ) {
  +           System.err.println("DeploymentFactory archives not specified.");
  +           System.exit(1);
  +       }
  +       
  +       for (int i = 0; i < args.length; i++) {
  +            File file = new File(args[i]);
  +            if (!file.isFile()) {
  +                System.err.println(args[i] + " does not exist.");
  +                System.exit(2);
  +            }
  +            registerDeploymentFactory(file);
  +        }
  +       
  +       Deployer deployer = new Deployer();
  +       deployer.run();
  +    }
  +    
  +    private static void registerDeploymentFactory(File anArchive) {
  +        String clazzName = null;
  +        try {
  +            JarFile jarFile = new JarFile(anArchive);
  +            Manifest manifest = jarFile.getManifest();
  +            Attributes attributes = manifest.getMainAttributes();
  +            clazzName = attributes.getValue(
  +                "J2EE-DeploymentFactory-Implementation-Class");
  +        } catch (IOException e) {
  +            e.printStackTrace();
  +            System.err.println("Can not retrieve DeploymentManagerFactory");
  +            System.exit(3);
  +        } catch (IllegalArgumentException e) {
  +            e.printStackTrace();
  +            System.err.println("No J2EE-DeploymentFactory-Implementation-Class.");
  +            System.exit(4);
  +        }
  +        
           try {
  -            Class.forName("org.apache.geronimo.enterprise.deploy.server.GeronimoDeploymentFactory");
  -        } catch(ClassNotFoundException e) {
  -            log.error("Unable to load Geronimo JSR-88 implementation");
  +            URLClassLoader cl = new URLClassLoader(new URL[]{anArchive.toURL()});
  +            Class clazz = cl.loadClass(clazzName);
  +            DeploymentFactoryManager.getInstance().
  +                registerDeploymentFactory(
  +                    (DeploymentFactory) clazz.newInstance());
  +        } catch (ClassNotFoundException e) {
  +            e.printStackTrace();
  +            System.err.println("Can not load " + clazzName);
  +            System.exit(5);
  +        } catch (InstantiationException e) {
  +            e.printStackTrace();
  +            System.err.println("Can not create " + clazzName);
  +            System.exit(5);
  +        } catch (IllegalAccessException e) {
  +            e.printStackTrace();
  +            System.err.println("Can not create " + clazzName);
  +            System.exit(5);
  +        } catch (MalformedURLException e) {
  +            throw new AssertionError();
           }
       }
  -
  +    
       /**
        * Creates a new instance using System.out and System.in to interact with
  -     * the user.  The user will need ot begin by selecting an EJB JAR file
  +     * the user.  The user will need to begin by selecting an EJB JAR file
        * to work with.
        */
       public Deployer() throws IllegalStateException, IllegalArgumentException {
  @@ -61,49 +124,13 @@
       }
   
       /**
  -     * Creates a new instance for the provided EJB JAR file using System.out
  -     * and System.in to interact with the user.
  -     */
  -    public Deployer(File jarFile) throws IllegalStateException, IllegalArgumentException {
  -        this(jarFile, new PrintWriter(new OutputStreamWriter(System.out), true), new BufferedReader(new InputStreamReader(System.in)));
  -    }
  -
  -    /**
        * Creates a new instance using the provided input/output streams to
  -     * interact with the user.  The user will need ot begin by selecting an EJB
  +     * interact with the user.  The user will need to begin by selecting an EJB
        * JAR file to work with.
        */
       public Deployer(PrintWriter out, Reader in) throws IllegalStateException, IllegalArgumentException {
           context.out = out;
           context.in = in instanceof BufferedReader ? (BufferedReader)in : new BufferedReader(in);
  -        if(!connect()) {
  -            throw new IllegalStateException("Unable to connect to Deployment service");
  -        }
  -    }
  -
  -    /**
  -     * Creates a new instance for the provided module file and input/output
  -     * streams.
  -     */
  -    public Deployer(File jarFile, PrintWriter out, Reader in) throws IllegalStateException, IllegalArgumentException {
  -        context.out = out;
  -        context.in = in instanceof BufferedReader ? (BufferedReader)in : new BufferedReader(in);
  -        if(jarFile.getName().endsWith(".jar")) {
  -            context.moduleInfo = new EJBJARInfo(context);
  -        } else if(jarFile.getName().endsWith(".war")) {
  -            context.moduleInfo = new WARInfo(context);
  -        } else {
  -            throw new IllegalArgumentException("Expecting file name to end in .jar or .war");
  -        }
  -        try {
  -            context.moduleInfo.file = jarFile;
  -            context.moduleInfo.jarFile = new JarFile(jarFile);
  -        } catch(IOException e) {
  -            throw new IllegalArgumentException(jarFile+" is not a valid JAR file!");
  -        }
  -        if(!connect() || !context.moduleInfo.initialize()) {
  -            throw new IllegalStateException("Unable to connect to Deployment service or prepare deployment information");
  -        }
       }
   
       /**
  @@ -115,66 +142,4 @@
           context.deployer.release();
       }
   
  -    /**
  -     * Prompts the user to enter a Deployer URL and then gets a DeploymentManager
  -     * for that URL.
  -     *
  -     * @return <tt>true</tt> if the connection was successful.
  -     */
  -    private boolean connect() {
  -        context.out.println("\n\nEnter the deployer URL.  Leave blank for the default URL 'deployer:geronimo:'");
  -        context.out.print("URL: ");
  -        context.out.flush();
  -        try {
  -            String url = context.in.readLine();
  -            if(url.equals("")) {
  -                url = "deployer:geronimo:";
  -                context.connected = false;
  -            } else {
  -                context.connected = true; //todo: maybe prompt whether you should connect to the server?
  -            }
  -            context.deployer = DeploymentFactoryManager.getInstance().getDeploymentManager(url, null, null);
  -            Target[] targets = context.deployer.getTargets();
  -            if(targets.length == 1) {
  -                context.targets = targets;
  -            }
  -        } catch(DeploymentManagerCreationException e) {
  -            log.error("Can't create deployment manager",e);
  -            return false;
  -        } catch(IOException e) {
  -            log.error("Unable to read user input", e);
  -            return false;
  -        }
  -
  -        return true;
  -    }
  -
  -    /** XMLBeans Test
  -     try {
  -     // warm up
  -     InputStream in = new BufferedInputStream(new FileInputStream("modules/core/src/test-data/xml/deployment/simple-alt-ejb-jar.xml"));
  -     org.apache.geronimo.xbeans.j2ee.EjbJarDocument doc = org.apache.geronimo.xbeans.j2ee.EjbJarDocument.Factory.parse(in);
  -     in.close();
  -     //real
  -     in = new BufferedInputStream(new FileInputStream("modules/core/src/test-data/xml/deployment/simple-ejb-jar.xml"));
  -     XmlOptions opts = new XmlOptions();
  -     opts.setEntityResolver(new LocalEntityResolver());
  -     long before = System.currentTimeMillis();
  -     doc = org.apache.geronimo.xbeans.j2ee.EjbJarDocument.Factory.parse(in, opts);
  -     long after = System.currentTimeMillis();
  -     in.close();
  -     log.info("Read XML document in "+(after-before)+" ms");
  -     Writer out = new PrintWriter(new FileWriter("test.out"), true);
  -     before = System.currentTimeMillis();
  -     doc.save(out, opts);
  -     after = System.currentTimeMillis();
  -     out.flush();
  -     out.close();
  -     log.info("Wrote XML document in "+(after-before)+" ms");
  -     } catch(IOException e) {
  -     e.printStackTrace();
  -     } catch(org.apache.xmlbeans.XmlException e) {
  -     e.printStackTrace();
  -     }
  -     */
   }
  
  
  
  1.5       +12 -1     incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/TextController.java
  
  Index: TextController.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/core/src/java/org/apache/geronimo/console/cli/TextController.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- TextController.java	10 Mar 2004 09:58:41 -0000	1.4
  +++ TextController.java	16 Jul 2004 04:39:41 -0000	1.5
  @@ -40,6 +40,14 @@
           this.context = context;
       }
   
  +    protected boolean ensureConnected() {
  +        if( context.connected ) {
  +            return true;
  +        }
  +        context.out.println("Not connected.");
  +        return false;
  +    }
  +    
       protected void newScreen(String title) {
           context.out.println("\n\n------ "+title+" ------");
       }
  @@ -53,6 +61,9 @@
       }
   
       protected String truncate(String s, int size) {
  +        if ( null == s ) {
  +            return "";
  +        }
           if(s.length() <= size) {
               return s;
           }