geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r396315 - in /geronimo/branches/1.1: applications/console-standard/src/java/org/apache/geronimo/console/configmanager/ applications/console-standard/src/webapp/WEB-INF/view/configmanager/ modules/deploy-jsr88/src/java/org/apache/geronimo/de...
Date Sun, 23 Apr 2006 20:48:52 GMT
Author: ammulder
Date: Sun Apr 23 13:48:50 2006
New Revision: 396315

URL: http://svn.apache.org/viewcvs?rev=396315&view=rev
Log:
De-horribleize the console deploy portlet
 - no kernel calls (GERONIMO-1882)
 - support redeploy (GERONIMO-1741) though it could still be better

Modified:
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/DeploymentPortlet.java
    geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/configmanager/deploy.jsp
    geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
    geronimo/branches/1.1/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/DeploymentPortlet.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/DeploymentPortlet.java?rev=396315&r1=396314&r2=396315&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/DeploymentPortlet.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/configmanager/DeploymentPortlet.java
Sun Apr 23 13:48:50 2006
@@ -21,6 +21,12 @@
 import java.io.IOException;
 import java.util.Iterator;
 import java.util.List;
+import java.util.ArrayList;
+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.portlet.ActionRequest;
 import javax.portlet.ActionResponse;
 import javax.portlet.PortletConfig;
@@ -28,32 +34,20 @@
 import javax.portlet.PortletRequestDispatcher;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
-
 import org.apache.commons.fileupload.FileItem;
 import org.apache.commons.fileupload.FileUploadException;
 import org.apache.commons.fileupload.disk.DiskFileItemFactory;
 import org.apache.commons.fileupload.portlet.PortletFileUpload;
-import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.console.BasePortlet;
-import org.apache.geronimo.console.util.ObjectNameConstants;
-import org.apache.geronimo.kernel.Kernel;
-import org.apache.geronimo.kernel.KernelRegistry;
-import org.apache.geronimo.kernel.repository.Artifact;
-import org.apache.geronimo.kernel.config.ConfigurationManager;
-import org.apache.geronimo.kernel.config.ConfigurationUtil;
+import org.apache.geronimo.deployment.plugin.jmx.JMXDeploymentManager;
+import org.apache.geronimo.deployment.plugin.ConfigIDExtractor;
+import org.apache.geronimo.common.DeploymentException;
 
 public class DeploymentPortlet extends BasePortlet {
-    private final String LINE_SEP = System.getProperty("line.separator");
-
     private PortletRequestDispatcher deployView;
 
     private PortletRequestDispatcher helpView;
 
-    private Kernel kernel;
-
-    private static final String[] ARGS = {File.class.getName(),
-                                          File.class.getName()};
-
     private boolean messageNotRendered = true;
 
     public void processAction(ActionRequest actionRequest,
@@ -68,6 +62,7 @@
         File moduleFile = null;
         File planFile = null;
         String startApp = null;
+        String redeploy = null;
         try {
             List items = uploader.parseRequest(actionRequest);
             for (Iterator i = items.iterator(); i.hasNext();) {
@@ -102,55 +97,80 @@
                     // retrieve 'startApp' form field value
                     if ("startApp".equalsIgnoreCase(item.getFieldName())) {
                         startApp = item.getString();
+                    } else if ("redeploy".equalsIgnoreCase(item.getFieldName())) {
+                        redeploy = item.getString();
                     }
                 }
             }
         } catch (FileUploadException e) {
             throw new PortletException(e);
         }
+        DeploymentFactoryManager dfm = DeploymentFactoryManager.getInstance();
         try {
-            List list = (List) kernel.invoke(ObjectNameConstants.DEPLOYER_OBJECT_NAME, "deploy",
new Object[]{
-                moduleFile, planFile}, ARGS);
-            actionResponse.setRenderParameter("outcome",
-                    "The application was successfully deployed.<br/>");
-            // start installed app/s
-            if ((startApp != null) && "YES".equalsIgnoreCase(startApp)) {
-                ConfigurationManager configurationManager = ConfigurationUtil
-                        .getConfigurationManager(kernel);
-                for (Iterator iterator = list.iterator(); iterator.hasNext();) {
-                    Artifact configID = Artifact.create((String)iterator.next());
-                    if (!configurationManager.isLoaded(configID)) {
-                        configurationManager.loadConfiguration(configID);
+            DeploymentManager mgr = dfm.getDeploymentManager("deployer:geronimo:inVM", null,
null);
+            try {
+                boolean isRedeploy = redeploy != null && !redeploy.equals("");
+                if(mgr instanceof JMXDeploymentManager) {
+                    ((JMXDeploymentManager)mgr).setLogConfiguration(false, true);
+                }
+                Target[] all = mgr.getTargets();
+                ProgressObject progress;
+                if(isRedeploy) {
+                    TargetModuleID[] targets = identifyTargets(moduleFile, planFile, mgr.getAvailableModules(null,
all));
+                    progress = mgr.redeploy(targets, moduleFile, planFile);
+                } else {
+                    progress = mgr.distribute(all, moduleFile, planFile);
+                }
+                while(progress.getDeploymentStatus().isRunning()) {
+                    Thread.sleep(100);
+                }
+
+                if(progress.getDeploymentStatus().isCompleted()) {
+                    String message = "The application was successfully "+(isRedeploy ? "re"
: "")+"deployed.<br/>";
+                    // start installed app/s
+                    if (!isRedeploy && startApp != null && !startApp.equals(""))
{
+                        progress = mgr.start(progress.getResultTargetModuleIDs());
+                        while(progress.getDeploymentStatus().isRunning()) {
+                            Thread.sleep(100);
+                        }
+                        message+="The application was successfully started";
                     }
-                    configurationManager.startConfiguration(configID);
+                    actionResponse.setRenderParameter("outcome",message);
+                } else {
+                    actionResponse.setRenderParameter("outcome", "Deployment failed: "+progress.getDeploymentStatus().getMessage());
                 }
+            } finally {
+                mgr.release();
             }
-        } catch (DeploymentException e) {
-            e.printStackTrace();
-            StringBuffer buf = new StringBuffer(256);
-            Throwable cause = e;
-            while (cause != null) {
-                append(buf, cause.getMessage());
-                buf.append(LINE_SEP);
-                cause = cause.getCause();
-            }
-            actionResponse.setRenderParameter("outcome", buf.toString());
         } catch (Exception e) {
             throw new PortletException(e);
         }
     }
 
-    private void append(StringBuffer buf, String message) {
-        for (int i = 0; i < message.length(); i++) {
-            char ch = message.charAt(i);
-            if (ch == '<') {
-                buf.append("&lt;");
-            } else if (ch == '>') {
-                buf.append("&gt;");
+    private TargetModuleID[] identifyTargets(File module, File plan, TargetModuleID[] allModules)
throws PortletException {
+        String moduleId = null;
+        List modules = new ArrayList();
+        try {
+            if(plan != null) {
+                moduleId = ConfigIDExtractor.extractModuleIdFromPlan(plan);
+            } else if(module != null) {
+                moduleId = ConfigIDExtractor.extractModuleIdFromArchive(module);
+                if(moduleId == null) {
+                    int pos = module.getName().lastIndexOf('.');
+                    moduleId = pos > -1 ? module.getName().substring(0, pos) : module.getName();
+                }
+            }
+            if(moduleId != null) {
+                modules.addAll(ConfigIDExtractor.identifyTargetModuleIDs(allModules, moduleId));
             } else {
-                buf.append(ch);
+                throw new PortletException("Unable to calculate a ModuleID from supplied
module and/or plan.");
             }
+        } catch (IOException e) {
+            throw new PortletException("Unable to read input files: "+e.getMessage());
+        } catch (DeploymentException e) {
+            throw new PortletException(e.getMessage(), e);
         }
+        return (TargetModuleID[]) modules.toArray(new TargetModuleID[modules.size()]);
     }
 
     protected void doView(RenderRequest renderRequest,
@@ -171,7 +191,6 @@
 
     public void init(PortletConfig portletConfig) throws PortletException {
         super.init(portletConfig);
-        kernel = KernelRegistry.getSingleKernel();
         deployView = portletConfig.getPortletContext().getRequestDispatcher("/WEB-INF/view/configmanager/deploy.jsp");
         helpView = portletConfig.getPortletContext().getRequestDispatcher("/WEB-INF/view/configmanager/deployHelp.jsp");
     }
@@ -179,7 +198,6 @@
     public void destroy() {
         deployView = null;
         helpView = null;
-        kernel = null;
         super.destroy();
     }
 }

Modified: geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/configmanager/deploy.jsp
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/configmanager/deploy.jsp?rev=396315&r1=396314&r2=396315&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/configmanager/deploy.jsp
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/webapp/WEB-INF/view/configmanager/deploy.jsp
Sun Apr 23 13:48:50 2006
@@ -10,7 +10,10 @@
   <tr><th align="right">Plan: </th><td><input type="file" name="plan"
/></td></tr>
   <tr>
     <td></td>
-    <td><input name="startApp" type="checkbox" value="yes" checked>Start app
after install</td>
+    <td>
+        <input name="startApp" type="checkbox" value="yes" checked>Start app after
install <br />
+        <input name="redeploy" type="checkbox" value="yes">Redeploy application <br
/>
+    </td>
   </tr>
   <tr>
     <td></td>

Modified: geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java?rev=396315&r1=396314&r2=396315&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
(original)
+++ geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
Sun Apr 23 13:48:50 2006
@@ -28,10 +28,15 @@
 import java.util.jar.JarFile;
 import java.util.jar.JarEntry;
 import java.util.Stack;
+import java.util.Collection;
+import java.util.List;
+import java.util.LinkedList;
 import javax.xml.parsers.SAXParserFactory;
 import javax.xml.parsers.SAXParser;
 import javax.xml.parsers.ParserConfigurationException;
+import javax.enterprise.deploy.spi.TargetModuleID;
 import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.kernel.repository.Artifact;
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.Attributes;
@@ -132,6 +137,55 @@
         return extractModuleIdFromPlan(in);
     }
 
+    /**
+     * Given a list of all available TargetModuleIDs and the name of a module,
+     * find the TargetModuleIDs that represent that module.
+     * @throws DeploymentException If no TargetModuleIDs have that module.
+     */
+    public static Collection identifyTargetModuleIDs(TargetModuleID[] allModules, String
name) throws DeploymentException {
+        List list = new LinkedList();
+        int pos;
+        if((pos = name.indexOf('|')) > -1) {
+            String target = name.substring(0, pos);
+            String module = name.substring(pos+1);
+            Artifact artifact = Artifact.create(module);
+            if(artifact.getGroupId() == null || artifact.getType() == null) {
+                artifact = new Artifact(artifact.getGroupId() == null ? Artifact.DEFAULT_GROUP_ID
: artifact.getGroupId(),
+                        artifact.getArtifactId(), artifact.getVersion(),
+                        artifact.getType() == null ? "car" : artifact.getType());
+            }
+            // First pass: exact match
+            for(int i=0; i<allModules.length; i++) {
+                if(allModules[i].getTarget().getName().equals(target) && artifact.matches(Artifact.create(allModules[i].getModuleID())))
{
+                    list.add(allModules[i]);
+                }
+            }
+        }
+        if(!list.isEmpty()) {
+            return list;
+        }
+        // second pass: module matches
+        Artifact artifact = Artifact.create(name);
+        if(artifact.getGroupId() == null || artifact.getType() == null) {
+            artifact = new Artifact(artifact.getGroupId() == null ? Artifact.DEFAULT_GROUP_ID
: artifact.getGroupId(),
+                    artifact.getArtifactId(), artifact.getVersion(),
+                    artifact.getType() == null ? "car" : artifact.getType());
+        }
+        for(int i = 0; i < allModules.length; i++) {
+            if(artifact.matches(Artifact.create(allModules[i].getModuleID()))) {
+                list.add(allModules[i]);
+            }
+        }
+        if(list.isEmpty()) {
+            throw new DeploymentException(name+" does not appear to be a the name of a module
" +
+                    "available on the selected server. Perhaps it has already been " +
+                    "stopped or undeployed?  If you're trying to specify a " +
+                    "TargetModuleID, use the syntax TargetName|ModuleName instead. " +
+                    "If you're not sure what's running, try the list-modules command.");
+        }
+        return list;
+    }
+    
     private static String extractModuleIdFromPlan(Reader plan) throws IOException {
         SAXParserFactory factory = SAXParserFactory.newInstance();
         factory.setNamespaceAware(true);

Modified: geronimo/branches/1.1/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java?rev=396315&r1=396314&r2=396315&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java
(original)
+++ geronimo/branches/1.1/modules/deploy-tool/src/java/org/apache/geronimo/deployment/cli/DeployUtils.java
Sun Apr 23 13:48:50 2006
@@ -94,52 +94,4 @@
     }
 
 
-    /**
-     * Given a list of all available TargetModuleIDs and the name of a module,
-     * find the TargetModuleIDs that represent that module.
-     * @throws DeploymentException If no TargetModuleIDs have that module.
-     */
-    public static Collection identifyTargetModuleIDs(TargetModuleID[] allModules, String
name) throws DeploymentException {
-        List list = new LinkedList();
-        int pos;
-        if((pos = name.indexOf('|')) > -1) {
-            String target = name.substring(0, pos);
-            String module = name.substring(pos+1);
-            Artifact artifact = Artifact.create(module);
-            if(artifact.getGroupId() == null || artifact.getType() == null) {
-                artifact = new Artifact(artifact.getGroupId() == null ? Artifact.DEFAULT_GROUP_ID
: artifact.getGroupId(),
-                        artifact.getArtifactId(), artifact.getVersion(),
-                        artifact.getType() == null ? "car" : artifact.getType());
-            }
-            // First pass: exact match
-            for(int i=0; i<allModules.length; i++) {
-                if(allModules[i].getTarget().getName().equals(target) && artifact.matches(Artifact.create(allModules[i].getModuleID())))
{
-                    list.add(allModules[i]);
-                }
-            }
-        }
-        if(!list.isEmpty()) {
-            return list;
-        }
-        // second pass: module matches
-        Artifact artifact = Artifact.create(name);
-        if(artifact.getGroupId() == null || artifact.getType() == null) {
-            artifact = new Artifact(artifact.getGroupId() == null ? Artifact.DEFAULT_GROUP_ID
: artifact.getGroupId(),
-                    artifact.getArtifactId(), artifact.getVersion(),
-                    artifact.getType() == null ? "car" : artifact.getType());
-        }
-        for(int i = 0; i < allModules.length; i++) {
-            if(artifact.matches(Artifact.create(allModules[i].getModuleID()))) {
-                list.add(allModules[i]);
-            }
-        }
-        if(list.isEmpty()) {
-            throw new DeploymentException(name+" does not appear to be a the name of a module
" +
-                    "available on the selected server. Perhaps it has already been " +
-                    "stopped or undeployed?  If you're trying to specify a " +
-                    "TargetModuleID, use the syntax TargetName|ModuleName instead. " +
-                    "If you're not sure what's running, try the list-modules command.");
-        }
-        return list;
-    }
 }



Mime
View raw message