geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject cvs commit: incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/configuration LocalConfigStore.java
Date Thu, 24 Jun 2004 02:50:13 GMT
jboynes     2004/06/23 19:50:13

  Modified:    modules/deployment/src/java/org/apache/geronimo/deployment
                        RemoteDeployer.java
               modules/deployment/src/java/org/apache/geronimo/deployment/plugin/jmx
                        JMXDeploymentManager.java
               modules/kernel/src/java/org/apache/geronimo/kernel/config
                        ConfigurationStore.java
               modules/system/src/java/org/apache/geronimo/system/configuration
                        LocalConfigStore.java
  Added:       modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local
                        RedeployCommand.java UndeployCommand.java
  Log:
  Support hot undeploy and redeploy
  
  Revision  Changes    Path
  1.2       +35 -3     incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/RemoteDeployer.java
  
  Index: RemoteDeployer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/RemoteDeployer.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- RemoteDeployer.java	23 Jun 2004 22:45:20 -0000	1.1
  +++ RemoteDeployer.java	24 Jun 2004 02:50:13 -0000	1.2
  @@ -1,12 +1,16 @@
   package org.apache.geronimo.deployment;
   
   import java.io.File;
  +import java.util.ArrayList;
  +import java.util.List;
  +import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
   import javax.enterprise.deploy.spi.DeploymentManager;
   import javax.enterprise.deploy.spi.Target;
  +import javax.enterprise.deploy.spi.TargetModuleID;
   import javax.enterprise.deploy.spi.status.ProgressObject;
  -import javax.enterprise.deploy.shared.factories.DeploymentFactoryManager;
   
   import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl;
  +import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
   
   /**
    * Created by IntelliJ IDEA.
  @@ -17,12 +21,29 @@
    */
   public class RemoteDeployer {
       public static void main(String[] args) throws Exception {
  +        File module = new File(args[0]);
  +        ProgressObject po;
           new DeploymentFactoryImpl();
  +
           String uri = "deployer:geronimo:jmx:rmi://localhost/jndi/rmi:/JMXConnector";
           DeploymentManager manager = DeploymentFactoryManager.getInstance().getDeploymentManager(uri,
"system", "manager");
           Target[] targets = manager.getTargets();
  -        File module = new File(args[0]);
  -        ProgressObject po = manager.distribute(targets, module, null);
  +        TargetModuleID[] modules = manager.getAvailableModules(null, targets);
  +        List redeploy = new ArrayList();
  +        if (args.length > 1) {
  +            for (int i = 0; i < modules.length; i++) {
  +                TargetModuleIDImpl targetModuleID = (TargetModuleIDImpl)modules[i];
  +                if (targetModuleID.getModuleID().equals(args[1])) {
  +                    redeploy.add(targetModuleID);
  +                }
  +            }
  +        }
  +        if (redeploy.isEmpty()) {
  +            po = manager.distribute(targets, module, null);
  +        } else {
  +            TargetModuleID[] todo = (TargetModuleID[]) redeploy.toArray(new TargetModuleID[redeploy.size()]);
  +            po = manager.redeploy(todo, module, null);
  +        }
           while (po.getDeploymentStatus().isRunning()) {
               Thread.sleep(100);
           }
  @@ -30,5 +51,16 @@
           if (po.getDeploymentStatus().isCompleted()) {
               manager.start(po.getResultTargetModuleIDs());
           }
  +
  +//        po = manager.stop(po.getResultTargetModuleIDs());
  +//        while (po.getDeploymentStatus().isRunning()) {
  +//            Thread.sleep(100);
  +//        }
  +//        System.out.println(po.getDeploymentStatus().getMessage());
  +//        po = manager.undeploy(po.getResultTargetModuleIDs());
  +//        while (po.getDeploymentStatus().isRunning()) {
  +//            Thread.sleep(100);
  +//        }
  +//        System.out.println(po.getDeploymentStatus().getMessage());
       }
   }
  
  
  
  1.6       +16 -4     incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/jmx/JMXDeploymentManager.java
  
  Index: JMXDeploymentManager.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/jmx/JMXDeploymentManager.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- JMXDeploymentManager.java	23 Jun 2004 22:44:49 -0000	1.5
  +++ JMXDeploymentManager.java	24 Jun 2004 02:50:13 -0000	1.6
  @@ -42,6 +42,8 @@
   import org.apache.geronimo.deployment.plugin.local.StartCommand;
   import org.apache.geronimo.deployment.plugin.local.StopCommand;
   import org.apache.geronimo.deployment.plugin.local.DistributeCommand;
  +import org.apache.geronimo.deployment.plugin.local.UndeployCommand;
  +import org.apache.geronimo.deployment.plugin.local.RedeployCommand;
   import org.apache.geronimo.kernel.Kernel;
   import org.apache.geronimo.kernel.KernelMBean;
   import org.apache.geronimo.kernel.config.ConfigurationInfo;
  @@ -181,15 +183,25 @@
       }
   
       public ProgressObject undeploy(TargetModuleID[] moduleIDList) {
  -        throw new UnsupportedOperationException();
  +        if (kernel == null) {
  +            throw new IllegalStateException("Disconnected");
  +        }
  +        UndeployCommand command = new UndeployCommand(kernel, moduleIDList);
  +        new Thread(command).start();
  +        return command;
       }
   
       public boolean isRedeploySupported() {
  -        return false;
  +        return true;
       }
   
       public ProgressObject redeploy(TargetModuleID[] moduleIDList, File moduleArchive, File
deploymentPlan) {
  -        throw new UnsupportedOperationException();
  +        if (kernel == null) {
  +            throw new IllegalStateException("Disconnected");
  +        }
  +        RedeployCommand command = new RedeployCommand(kernel, moduleIDList, moduleArchive,
deploymentPlan);
  +        new Thread(command).start();
  +        return command;
       }
   
       public ProgressObject redeploy(TargetModuleID[] moduleIDList, InputStream moduleArchive,
InputStream deploymentPlan) {
  
  
  
  1.1                  incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/RedeployCommand.java
  
  Index: RedeployCommand.java
  ===================================================================
  /**
   *
   * Copyright 2003-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.plugin.local;
  
  import java.net.URI;
  import java.io.File;
  import java.util.Set;
  import java.util.Iterator;
  import javax.enterprise.deploy.spi.TargetModuleID;
  import javax.enterprise.deploy.shared.CommandType;
  import javax.management.ObjectName;
  
  import org.apache.geronimo.kernel.KernelMBean;
  import org.apache.geronimo.kernel.jmx.JMXUtil;
  import org.apache.geronimo.deployment.plugin.TargetImpl;
  import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
  
  /**
   * @version $Revision: 1.1 $ $Date: 2004/06/24 02:50:13 $
   */
  public class RedeployCommand extends CommandSupport {
      private static final String[] DEPLOY_SIG = {File.class.getName(), File.class.getName()};
      private static final String[] UNINSTALL_SIG = {URI.class.getName()};
      private final KernelMBean kernel;
      private final TargetModuleID[] modules;
      private final File moduleArchive;
      private final File deploymentPlan;
  
      public RedeployCommand(KernelMBean kernel, TargetModuleID modules[], File moduleArchive,
File deploymentPlan) {
          super(CommandType.START);
          this.kernel = kernel;
          this.modules = modules;
          this.moduleArchive = moduleArchive;
          this.deploymentPlan = deploymentPlan;
      }
  
      public void run() {
          Set deployers = kernel.listGBeans(JMXUtil.getObjectName("geronimo.deployment:role=Deployer,*"));
          if (deployers.isEmpty()) {
              fail("No deployer present in kernel");
              return;
          }
          Iterator j = deployers.iterator();
          ObjectName deployer = (ObjectName) j.next();
          if (j.hasNext()) {
              throw new UnsupportedOperationException("More than one deployer found");
          }
  
          try {
              for (int i = 0; i < modules.length; i++) {
                  TargetModuleIDImpl module = (TargetModuleIDImpl) modules[i];
  
                  URI configID = URI.create(module.getModuleID());
                  kernel.stopConfiguration(configID);
                  
                  TargetImpl target = (TargetImpl) module.getTarget();
                  ObjectName storeName = target.getObjectName();
                  kernel.invoke(storeName, "uninstall", new Object[]{configID}, UNINSTALL_SIG);
  
                  Object[] args = {moduleArchive, deploymentPlan};
                  URI configId = (URI) kernel.invoke(deployer, "deploy", args, DEPLOY_SIG);
                  module = new TargetModuleIDImpl(module.getTarget(), configId.toString());
                  addModule(module);
              }
              complete("Completed");
          } catch (Exception e) {
              fail(e.getMessage());
          }
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/UndeployCommand.java
  
  Index: UndeployCommand.java
  ===================================================================
  /**
   *
   * Copyright 2003-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.plugin.local;
  
  import java.net.URI;
  import javax.enterprise.deploy.spi.TargetModuleID;
  import javax.enterprise.deploy.shared.CommandType;
  import javax.management.ObjectName;
  
  import org.apache.geronimo.kernel.KernelMBean;
  import org.apache.geronimo.deployment.plugin.TargetImpl;
  import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
  
  /**
   * @version $Revision: 1.5 $ $Date: 2004/06/02 06:50:41 $
   */
  public class UndeployCommand extends CommandSupport {
      private static final String[] UNINSTALL_SIG = {URI.class.getName()};
      private final KernelMBean kernel;
      private final TargetModuleID[] modules;
  
      public UndeployCommand(KernelMBean kernel, TargetModuleID modules[]) {
          super(CommandType.START);
          this.kernel = kernel;
          this.modules = modules;
      }
  
      public void run() {
          try {
              for (int i = 0; i < modules.length; i++) {
                  TargetModuleIDImpl module = (TargetModuleIDImpl) modules[i];
  
                  URI moduleID = URI.create(module.getModuleID());
                  kernel.stopConfiguration(moduleID);
  
                  TargetImpl target = (TargetImpl) module.getTarget();
                  ObjectName storeName = target.getObjectName();
                  URI configID = URI.create(module.getModuleID());
                  kernel.invoke(storeName, "uninstall", new Object[]{configID}, UNINSTALL_SIG);
                  addModule(module);
              }
              complete("Completed");
          } catch (Exception e) {
              fail(e.getMessage());
          }
      }
  }
  
  
  
  1.10      +3 -1      incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStore.java
  
  Index: ConfigurationStore.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStore.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ConfigurationStore.java	23 Jun 2004 22:44:49 -0000	1.9
  +++ ConfigurationStore.java	24 Jun 2004 02:50:13 -0000	1.10
  @@ -39,6 +39,8 @@
        */
       URI install(URL source) throws IOException, InvalidConfigException;
   
  +    void uninstall(URI configID) throws NoSuchConfigException, IOException;
  +
       /**
        * Determines if the store contains a configuration with the spedified ID.
        *
  
  
  
  1.11      +31 -3     incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java
  
  Index: LocalConfigStore.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- LocalConfigStore.java	23 Jun 2004 22:44:49 -0000	1.10
  +++ LocalConfigStore.java	24 Jun 2004 02:50:13 -0000	1.11
  @@ -48,6 +48,8 @@
   import org.apache.geronimo.kernel.config.InvalidConfigException;
   import org.apache.geronimo.kernel.config.NoSuchConfigException;
   import org.apache.geronimo.system.serverinfo.ServerInfo;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   /**
    * Implementation of ConfigurationStore using the local filesystem.
  @@ -59,8 +61,9 @@
       private final String objectName;
       private final URI root;
       private final ServerInfo serverInfo;
  -    private File rootDir;
       private final Properties index = new Properties();
  +    private final Log log;
  +    private File rootDir;
       private int maxId;
   
       /**
  @@ -71,12 +74,14 @@
           serverInfo = null;
           this.root = null;
           this.rootDir = rootDir;
  +        log = LogFactory.getLog("LocalConfigStore:"+rootDir.getName());
       }
   
       public LocalConfigStore(String objectName, URI root, ServerInfo serverInfo) {
           this.objectName = objectName;
           this.root = root;
           this.serverInfo = serverInfo;
  +        log = LogFactory.getLog("LocalConfigStore:"+root.toString());
       }
   
       public String getObjectName() {
  @@ -156,9 +161,30 @@
           synchronized (this) {
               saveIndex();
           }
  +        log.info("Installed configuration " + configId + " in location " + newId);
           return configId;
       }
   
  +    public void uninstall(URI configID) throws NoSuchConfigException, IOException {
  +        String id = configID.toString();
  +        File configDir;
  +        synchronized(this) {
  +            String storeID = index.getProperty(id);
  +            if (storeID == null) {
  +                throw new NoSuchConfigException();
  +            }
  +            configDir = new File(rootDir, storeID);
  +            File tempDir = new File(rootDir, storeID + ".tmp");
  +            if (configDir.renameTo(tempDir)) {
  +                configDir = tempDir;
  +            }
  +            index.remove(id);
  +            saveIndex();
  +        }
  +        log.info("Uninstalled configuration " + configID);
  +        delete(configDir);
  +    }
  +
       public synchronized GBeanMBean getConfiguration(URI configID) throws NoSuchConfigException,
IOException, InvalidConfigException {
           return loadConfig(getRoot(configID));
       }
  @@ -258,7 +284,9 @@
               if (file.isDirectory()) {
                   delete(file);
               } else {
  -                file.delete();
  +                if (!file.delete()) {
  +                    file.deleteOnExit();
  +                };
               }
           }
           root.delete();
  
  
  

Mime
View raw message