geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r353874 - in /geronimo/trunk/modules: deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/jmx/ deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/ deploy-tool/src/java/org/apache/geronimo/deployment/cli/ deployment/sr...
Date Sun, 04 Dec 2005 17:07:19 GMT
Author: ammulder
Date: Sun Dec  4 09:07:10 2005
New Revision: 353874

URL: http://svn.apache.org/viewcvs?rev=353874&view=rev
Log:
Hot deployer gripes if it can tell you unpacked a module directly
  into the deploy/ directory instead of as a subdirectory (GERONIMO-1228)
Streamline the notifications and errors from the hot deployer
Fix the runtime deployer configId in the "not found" error message
Change the "currently I can't tell the difference" message and improve the
  syntax a bit

Modified:
    geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/jmx/JMXDeploymentManager.java
    geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java
    geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java
    geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
    geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryHotDeployer.java
    geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryMonitor.java

Modified: geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/jmx/JMXDeploymentManager.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/jmx/JMXDeploymentManager.java?rev=353874&r1=353873&r2=353874&view=diff
==============================================================================
--- geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/jmx/JMXDeploymentManager.java
(original)
+++ geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/jmx/JMXDeploymentManager.java
Sun Dec  4 09:07:10 2005
@@ -300,6 +300,11 @@
         public CommandContext() {
         }
 
+        public CommandContext(boolean logErrors, boolean verbose) {
+            this.logErrors = logErrors;
+            this.verbose = verbose;
+        }
+
         public boolean isLogErrors() {
             return logErrors;
         }

Modified: geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java?rev=353874&r1=353873&r2=353874&view=diff
==============================================================================
--- geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java
(original)
+++ geronimo/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/local/AbstractDeployCommand.java
Sun Dec  4 09:07:10 2005
@@ -66,13 +66,13 @@
                  "This usually indicates a serious problem with the configuration of " +
                  "your running Geronimo server.  If " +
                  "the deployer is present but not started, the workaround is to run " +
-                 "a deploy command like 'start org/apache/geronimo/RuntimeDeployer'.  " +
+                 "a deploy command like 'start geronimo/runtime-deployer/1.0/car'.  " +
                  "If the deployer service is not present at all (it was undeployed) then
" +
                  "you need to either re-install Geronimo or get a deployment plan for the
" +
                  "runtime deployer and distribute it while the server is not running and
" +
                  "then start the server with a command like the above.  For help on this,
" +
                  "write to user@geronimo.apache.org and include the contents of your " +
-                 "config-store/index.properties and var/config/config.list files.");
+                 "config-store/index.properties and var/config/config.xml files.");
             return null;
         }
         Iterator j = deployers.iterator();

Modified: geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java?rev=353874&r1=353873&r2=353874&view=diff
==============================================================================
--- geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java
(original)
+++ geronimo/trunk/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java
Sun Dec  4 09:07:10 2005
@@ -49,7 +49,6 @@
      * @param endCol The maximum width of the entire line in characters,
      *               including indent (indent 10 with endCol 70 results
      *               in 60 "usable" characters).
-     * @return
      */
     public static String reformat(String source, int indent, int endCol) {
         if(endCol-indent < 10) {
@@ -173,13 +172,15 @@
      * for a Geronimo deployment plan in the usual place, and if one is found,
      * retrieve the configId from the Geronimo deployment plan.
      *
+     * todo: Handle Spring and other weird deployment types?
+     *
      * @param module A Jar file or directory representing a J2EE module
      * @return The configId in the Geronimo deployment plan for this module,
      *         or null if no Geronimo deployment plan was identified.
      */
     public static String extractModuleIdFromArchive(File module) throws IOException, DeploymentException
{
         if(!module.canRead()) {
-            throw new IllegalArgumentException("Not a readable file");
+            throw new DeploymentException("Not a readable file ("+module.getAbsolutePath()+")");
         }
         if(module.isDirectory()) {
             File target = null;
@@ -200,7 +201,7 @@
             }
         } else {
             if(!isJarFile(module)) {
-                throw new IllegalArgumentException(module.getAbsolutePath()+" is neither
a JAR file nor a directory!");
+                throw new DeploymentException(module.getAbsolutePath()+" is neither a JAR
file nor a directory!");
             }
             JarFile input = new JarFile(module);
             //todo: instead of looking for specific file names here, do something generic.

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java?rev=353874&r1=353873&r2=353874&view=diff
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
Sun Dec  4 09:07:10 2005
@@ -132,9 +132,9 @@
                 }
             }
             if (builder == null) {
-                throw new DeploymentException("Syntax error in deployment plan or no deployer
service available (currently I can't tell the difference):" +
-                        (planFile == null ? "" : " planFile=" + planFile.getAbsolutePath())
+
-                        (moduleFile == null ? "" : ", moduleFile" + moduleFile.getAbsolutePath()));
+                throw new DeploymentException("Cannot deploy the requested application module
(" +
+                        (planFile == null ? "" : "planFile=" + planFile.getAbsolutePath())
+
+                        (moduleFile == null ? "" : (planFile == null ? "" : ", ")+"moduleFile="
+ moduleFile.getAbsolutePath())+")");
             }
 
             // Make sure this configuration doesn't already exist

Modified: geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryHotDeployer.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryHotDeployer.java?rev=353874&r1=353873&r2=353874&view=diff
==============================================================================
--- geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryHotDeployer.java
(original)
+++ geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryHotDeployer.java
Sun Dec  4 09:07:10 2005
@@ -22,6 +22,7 @@
 import org.apache.geronimo.gbean.GBeanQuery;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
 import org.apache.geronimo.deployment.plugin.factories.DeploymentFactoryImpl;
+import org.apache.geronimo.deployment.plugin.jmx.JMXDeploymentManager;
 import org.apache.geronimo.deployment.cli.DeployUtils;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.kernel.config.PersistentConfigurationList;
@@ -46,7 +47,12 @@
  * @version $Rev: 53762 $ $Date: 2004-10-04 18:54:53 -0400 (Mon, 04 Oct 2004) $
  */
 public class DirectoryHotDeployer implements HotDeployer, GBeanLifecycle { //todo: write
unit tests
-    private static final Log log = LogFactory.getLog(DirectoryHotDeployer.class);
+    private static final Log log = LogFactory.getLog("org.apache.geronimo.deployment.hot.Hot
Deployer");
+    // Try to make this stand out as the user is likely to get a ton of errors if this comes
up
+    private static final String BAD_LAYOUT_MESSAGE = "CANNOT DEPLOY: It looks like you unpacked
an application or module "+
+                   "directly into the hot deployment directory.  THIS DOES NOT WORK.  You
need to unpack into a "+
+                   "subdirectory directly under the hot deploy directory.  For example, if
the hot deploy directory "+
+                   "is 'deploy/' and your file is 'webapp.war' then you could unpack it into
a directory 'deploy/webapp.war/'";
     private DirectoryMonitor monitor;
     private String path;
     private ServerInfo serverInfo;
@@ -129,14 +135,12 @@
         }
         DeploymentManager mgr = null;
         try {
-            mgr = factory.getDeploymentManager(deploymentURI, deploymentUser, deploymentPassword);
+            mgr = getDeploymentManager();
             Target[] targets = mgr.getTargets();
             startupModules = mgr.getAvailableModules(null, targets);
             mgr.release();
             mgr = null;
             monitor = new DirectoryMonitor(dir, this, pollIntervalMillis);
-            monitor.initialize();
-            startupModules = null;
             log.debug("Hot deploy scanner intialized; starting main loop.");
             Thread t = new Thread(monitor, "Geronimo hot deploy scanner");
             t.setDaemon(true);
@@ -188,18 +192,37 @@
         return file.lastModified(); //todo: how can we find out when a module was deployed?
     }
 
-    public boolean fileAdded(File file) {
+    public void started() {
+        startupModules = null;
+        log.debug("Initialization complete; directory scanner entering normal scan mode");
+    }
+
+    public boolean validateFile(File file, String configId) {
+        //todo: some more detailed evaluation
+        if(file.isDirectory() && (file.getName().equals("WEB-INF") || file.getName().equals("META-INF")))
{
+            log.error("("+file.getName()+") "+BAD_LAYOUT_MESSAGE);
+            return false;
+        }
+        return true;
+    }
+
+    public String fileAdded(File file) {
+        log.info("Deploying "+file.getName());
         DeploymentManager mgr = null;
+        TargetModuleID[] modules = null;
+        boolean completed = false;
         try {
-            mgr = factory.getDeploymentManager(deploymentURI, deploymentUser, deploymentPassword);
+            mgr = getDeploymentManager();
             Target[] targets = mgr.getTargets();
             ProgressObject po = mgr.distribute(targets, file, null);
             waitForProgress(po);
             if(po.getDeploymentStatus().isCompleted()) {
-                TargetModuleID[] modules = po.getResultTargetModuleIDs();
+                modules = po.getResultTargetModuleIDs();
                 po = mgr.start(modules);
                 waitForProgress(po);
-                if(!po.getDeploymentStatus().isCompleted()) {
+                if(po.getDeploymentStatus().isCompleted()) {
+                    completed = true;
+                } else {
                     log.warn("Unable to start some modules for "+file.getAbsolutePath());
                 }
                 modules = po.getResultTargetModuleIDs();
@@ -214,22 +237,41 @@
                     }
                 }
             } else {
-                log.error("Unable to deploy: "+po.getDeploymentStatus().getMessage(), new
DeploymentException());
-                return false;
+                log.error("Unable to deploy: "+po.getDeploymentStatus().getMessage());
+                return null;
             }
         } catch (DeploymentManagerCreationException e) {
             log.error("Unable to open deployer", e);
-            return false;
+            return null;
         } finally {
             if(mgr != null) mgr.release();
         }
-        return true;
+        if(completed && modules != null) {
+            if(modules.length == 1) {
+                return modules[0].getModuleID();
+            } else {
+                return "";
+            }
+        } else if(modules != null) { //distribute completed but not start or something like
that
+            return "";
+        } else {
+            return null;
+        }
+    }
+
+    private DeploymentManager getDeploymentManager() throws DeploymentManagerCreationException
{
+        DeploymentManager manager = factory.getDeploymentManager(deploymentURI, deploymentUser,
deploymentPassword);
+        if(manager instanceof JMXDeploymentManager) {
+            ((JMXDeploymentManager)manager).setCommandContext(new JMXDeploymentManager.CommandContext(false,
true));
+        }
+        return manager;
     }
 
     public boolean fileRemoved(File file, String configId) {
+        log.info("Undeploying "+file.getName());
         DeploymentManager mgr = null;
         try {
-            mgr = factory.getDeploymentManager(deploymentURI, deploymentUser, deploymentPassword);
+            mgr = getDeploymentManager();
             Target[] targets = mgr.getTargets();
             TargetModuleID[] ids = mgr.getAvailableModules(null, targets);
             ids = (TargetModuleID[]) DeployUtils.identifyTargetModuleIDs(ids, configId).toArray(new
TargetModuleID[0]);
@@ -258,9 +300,10 @@
     }
 
     public void fileUpdated(File file, String configId) {
+        log.info("Redeploying "+file.getName());
         DeploymentManager mgr = null;
         try {
-            mgr = factory.getDeploymentManager(deploymentURI, deploymentUser, deploymentPassword);
+            mgr = getDeploymentManager();
             Target[] targets = mgr.getTargets();
             TargetModuleID[] ids = mgr.getAvailableModules(null, targets);
             ids = (TargetModuleID[]) DeployUtils.identifyTargetModuleIDs(ids, configId).toArray(new
TargetModuleID[0]);

Modified: geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryMonitor.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryMonitor.java?rev=353874&r1=353873&r2=353874&view=diff
==============================================================================
--- geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryMonitor.java
(original)
+++ geronimo/trunk/modules/hot-deploy/src/java/org/apache/geronimo/deployment/hot/DirectoryMonitor.java
Sun Dec  4 09:07:10 2005
@@ -19,14 +19,14 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.Log;
 import org.apache.geronimo.deployment.cli.DeployUtils;
-import org.apache.geronimo.common.DeploymentException;
 import java.io.File;
 import java.io.Serializable;
-import java.io.IOException;
 import java.util.Map;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.List;
+import java.util.LinkedList;
 
 /**
  * Meant to be run as a Thread that tracks the contents of a directory.
@@ -66,10 +66,30 @@
         long getDeploymentTime(File file, String configId);
 
         /**
-         * @return true if the addition was processed successfully.  If not
-         *         the file will be added again next time it changes.
+         * Called to indicate that the monitor has fully initialized
+         * and will be doing normal deployment operations from now on.
          */
-        boolean fileAdded(File file);
+        void started();
+
+        /**
+         * Called to check whether a file passes the smell test before
+         * attempting to deploy it.
+         *
+         * @return true if there's nothing obviously wrong with this file.
+         *         false if there is (for example, it's clearly not
+         *         deployable).
+         */
+        boolean validateFile(File file, String configId);
+
+        /**
+         * @return A configId for the deployment if the addition was processed
+         *         successfully (or an empty String if the addition was OK but
+         *         the configId could not be determined).  null if the addition
+         *         failed, in which case the file will be added again next time
+         *         it changes.
+         */
+        String fileAdded(File file);
+
         /**
          * @return true if the removal was processed successfully.  If not
          *         the file will be removed again on the next pass.
@@ -132,14 +152,26 @@
     }
 
     public void run() {
+        boolean serverStarted = false, initialized = false;
         while(!done) {
             try {
                 Thread.sleep(pollIntervalMillis);
             } catch (InterruptedException e) {
                 continue;
             }
-            if(listener != null && listener.isServerRunning()) {
-                scanDirectory();
+            if(listener != null) {
+                if(!serverStarted && listener.isServerRunning()) {
+                    serverStarted = true;
+                }
+                if(serverStarted) {
+                    if(!initialized) {
+                        initialized = true;
+                        initialize();
+                        listener.started();
+                    } else {
+                        scanDirectory();
+                    }
+                }
             }
         }
     }
@@ -163,7 +195,7 @@
                     files.put(now.getPath(), now);
                 }
             } catch (Exception e) {
-                log.error("Unable to scan file "+child.getAbsolutePath()+" during initialization");
+                log.error("Unable to scan file "+child.getAbsolutePath()+" during initialization",
e);
             }
         }
     }
@@ -180,6 +212,7 @@
             return;
         }
         HashSet oldList = new HashSet(files.keySet());
+        List actions = new LinkedList();
         for (int i = 0; i < children.length; i++) {
             File child = children[i];
             if(!child.canRead()) {
@@ -195,21 +228,14 @@
                 oldList.remove(then.getPath());
                 if(now.isSame(then)) { // File is the same as the last time we scanned it
                     if(then.isChanging()) {
-                        try {
-                            log.debug("File finished changing: "+now.getPath());
-                            // Used to be changing, now in (hopefully) its final state
-                            if(then.isNewFile()) {
-                                then.setConfigId(calculateModuleId(child));
-                                if(listener == null || listener.fileAdded(child)) {
-                                    then.setNewFile(false);
-                                }
-                            } else {
-                                if(listener != null) listener.fileUpdated(child, then.getConfigId());
-                            }
-                            then.setChanging(false);
-                        } catch (Exception e) {
-                            log.error("Unable to deploy file "+child.getAbsolutePath(), e);
+                        log.debug("File finished changing: "+now.getPath());
+                        // Used to be changing, now in (hopefully) its final state
+                        if(then.isNewFile()) {
+                            actions.add(new FileAction(FileAction.NEW_FILE, child, then));
+                        } else {
+                            actions.add(new FileAction(FileAction.UPDATED_FILE, child, then));
                         }
+                        then.setChanging(false);
                     } // else it's just totally unchanged and we ignore it this pass
                 } else {
                     // The two records are different -- record the latest as a file that's
changing
@@ -226,14 +252,66 @@
             String name = (String) it.next();
             FileInfo info = (FileInfo) files.get(name);
             log.debug("File removed: "+name);
-            if(info.isNewFile() || listener == null || listener.fileRemoved(new File(name),
info.getConfigId())) {
+            if(info.isNewFile()) { // Was never added, just whack it
                 files.remove(name);
+            } else {
+                actions.add(new FileAction(FileAction.REMOVED_FILE, new File(name), info));
+            }
+        }
+        if(listener != null) {
+            // First pass: validate all changed files, so any obvious errors come out first
+            for (Iterator it = actions.iterator(); it.hasNext();) {
+                FileAction action = (FileAction) it.next();
+                if(!listener.validateFile(action.child, action.info.getConfigId())) {
+                    resolveFile(action);
+                    it.remove();
+                }
+            }
+            // Second pass: do what we're meant to do
+            for (Iterator it = actions.iterator(); it.hasNext();) {
+                FileAction action = (FileAction) it.next();
+                try {
+                    if(action.action == FileAction.REMOVED_FILE) {
+                        if(listener.fileRemoved(action.child, action.info.getConfigId()))
{
+                            files.remove(action.child.getPath());
+                        }
+                    } else if(action.action == FileAction.NEW_FILE) {
+                        String result = listener.fileAdded(action.child);
+                        if(result != null) {
+                            if(!result.equals("")) {
+                                action.info.setConfigId(result);
+                            } else {
+                                action.info.setConfigId(calculateModuleId(action.child));
+                            }
+                            action.info.setNewFile(false);
+                        }
+                    } else if(action.action == FileAction.UPDATED_FILE) {
+                        listener.fileUpdated(action.child, action.info.getConfigId());
+                    }
+                } catch (Exception e) {
+                    log.error("Unable to "+action.getActionName()+" file "+action.child.getAbsolutePath(),
e);
+                } finally {
+                    resolveFile(action);
+                }
             }
         }
     }
 
-    private static String calculateModuleId(File module) throws IOException, DeploymentException
{
-        String moduleId = DeployUtils.extractModuleIdFromArchive(module);
+    private void resolveFile(FileAction action) {
+        if(action.action == FileAction.REMOVED_FILE) {
+            files.remove(action.child.getPath());
+        } else {
+            action.info.setChanging(false);
+        }
+    }
+
+    private static String calculateModuleId(File module) {
+        String moduleId = null;
+        try {
+            moduleId = DeployUtils.extractModuleIdFromArchive(module);
+        } catch (Exception e) {
+            log.warn("Unable to calculate module ID for module "+module.getAbsolutePath()+"
["+e.getMessage()+"]");
+        }
         if(moduleId == null) {
             int pos = module.getName().lastIndexOf('.');
             moduleId = pos > -1 ? module.getName().substring(0, pos) : module.getName();
@@ -281,6 +359,24 @@
         return info;
     }
 
+    private static class FileAction {
+        private static int NEW_FILE = 1;
+        private static int UPDATED_FILE = 2;
+        private static int REMOVED_FILE = 3;
+        private int action;
+        private File child;
+        private FileInfo info;
+
+        public FileAction(int action, File child, FileInfo info) {
+            this.action = action;
+            this.child = child;
+            this.info = info;
+        }
+
+        public String getActionName() {
+            return action == NEW_FILE ? "deploy" : action == UPDATED_FILE ? "redeploy" :
"undeploy";
+        }
+    }
 
     private static class FileInfo implements Serializable {
         private String path;



Mime
View raw message