You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by li...@apache.org on 2008/09/05 22:21:57 UTC

svn commit: r692528 - in /geronimo/server/trunk/framework/modules: geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/

Author: linsun
Date: Fri Sep  5 13:21:56 2008
New Revision: 692528

URL: http://svn.apache.org/viewvc?rev=692528&view=rev
Log:
GERONIMO-4282 - Enhance deploy/assemble gshell command usability by providing 3 custom server assembly modes

Modified:
    geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AssembleServerCommand.groovy
    geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java

Modified: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AssembleServerCommand.groovy
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AssembleServerCommand.groovy?rev=692528&r1=692527&r2=692528&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AssembleServerCommand.groovy (original)
+++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AssembleServerCommand.groovy Fri Sep  5 13:21:56 2008
@@ -27,7 +27,7 @@
 import org.apache.geronimo.kernel.repository.Artifact
 
 /**
- * Extract a bunch of plugins into a server.
+ * Extract a bunch of plugins into a custom assembly server.
  *
  * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $
  */
@@ -37,6 +37,9 @@
 {
     @Option (name = '-l', aliases = ['--list'], description = 'refresh plugin list')
     boolean refreshList = false
+    
+    @Option (name = '-m', aliases = ['--mode'], description = 'custom assembly mode')
+    String mode
 
     @Option (name = '-t', aliases = ['--path'], description = 'assembly location')
     String relativeServerPath = "var/temp/assembly"
@@ -57,39 +60,78 @@
     List<String> pluginArtifacts
 
     protected Object doExecute() throws Exception {
-        io.out.println('Listing configurations from Geronimo server')
-
-        def connection = connect()
+    
+        def connection = connect()        
+        def command = new CommandListConfigurations()
+        def consoleReader = new ConsoleReader(io.inputStream, io.out)
+	    
+        io.out.println('Available custom assembly modes:')
+        io.out.println(' 1:    Function Centric')
+        io.out.println(' 2:    Application Centric')
+        io.out.println(' 3:    Expert Users')
+        
+        if (!mode) {
+            mode = prompter.readLine('Please select a custom assembly mode [1,2,3]').trim()
+            if (!mode || (mode.compareTo("1") != 0 && mode.compareTo("2") != 0 && mode.compareTo("3") != 0)) {
+                throw new IllegalArgumentException('Please enter a valid Assembly server mode')
+            } 
+        }
               
+        if (!group) {
+            group = prompter.readLine('Assembly server group name: ').trim()
+            if (!group) {
+                throw new IllegalArgumentException('Assembly server group name is required')
+            }
+        }
+        
         if (!artifact) {
-            artifact = prompter.readLine('Server artifact name: ')
+            artifact = prompter.readLine('Assembly server artifact name: ').trim()
             if (!artifact) {
-                throw new IllegalArgumentException('Server artifact name is required')
+                throw new IllegalArgumentException('Assembly server artifact name is required')
             }
         }
         
-        def command = new CommandListConfigurations()
-        def consoleReader = new ConsoleReader(io.inputStream, io.out)
-        def plugins = variables.get('LocalPlugins')
-        
-        if (refreshList || !plugins) {
-            plugins = command.getLocalPluginCategories(connection.getDeploymentManager(), consoleReader)
-            variables.parent.set('LocalPlugins', plugins)
-        }
-
-        if (pluginArtifacts) {
-            command.assembleServer(connection.getDeploymentManager(), pluginArtifacts, plugins, 'repository', relativeServerPath, consoleReader)
+	    def plugins = variables.get('LocalPlugins')
+	        
+	    if (refreshList || !plugins) {
+	        plugins = command.getLocalPluginCategories(connection.getDeploymentManager(), consoleReader)
+	        variables.parent.set('LocalPlugins', plugins)
+	    }
+	    
+	    if (pluginArtifacts) {
+	        command.assembleServer(connection.getDeploymentManager(), pluginArtifacts, plugins, 'repository', relativeServerPath, consoleReader)
             connection.getDeploymentManager().archive(relativeServerPath, 'var/temp', new Artifact(group, artifact, (String)version, format));
-        }
-        else {
-            def pluginsToInstall = command.getInstallList(plugins, consoleReader, null)
-            
+	    } else {
+	        def pluginsToInstall;
+	          	                
+            if (mode.compareTo("1") == 0) {
+                io.out.println('Listing plugin groups from the local Geronimo server')
+	            def pluginGroups = variables.get('LocalPluginGroups')
+	        
+	            if (refreshList || !pluginGroups) {
+	                pluginGroups = command.getLocalPluginGroups(connection.getDeploymentManager(), consoleReader)
+	                variables.parent.set('LocalPluginGroups', pluginGroups)
+	            }
+	            pluginsToInstall = command.getInstallList(pluginGroups, consoleReader, null)
+	                    
+            } else if (mode.compareTo("2") == 0) {
+                io.out.println('Listing application plugins from the local Geronimo server')
+	            def appPlugins = variables.get('LocalAppPlugins')
+	        
+	            if (refreshList || !appPlugins) {
+	                appPlugins = command.getLocalApplicationPlugins(connection.getDeploymentManager(), consoleReader)
+	                variables.parent.set('LocalAppPlugins', appPlugins)
+	            }
+	            pluginsToInstall = command.getInstallList(appPlugins, consoleReader, null)
+            } else {
+                io.out.println('Listing plugins from the local Geronimo server')
+                pluginsToInstall = command.getInstallList(plugins, consoleReader, null)
+            } 
+	            
             if (pluginsToInstall) {
                 command.assembleServer(connection.getDeploymentManager(), pluginsToInstall, 'repository', relativeServerPath, consoleReader)
-                connection.getDeploymentManager().archive(relativeServerPath, 'var/temp', new Artifact(group, artifact, (String)version, format));
+                connection.getDeploymentManager().archive(relativeServerPath, 'var/temp', new Artifact(group, artifact, (String)version, format));            
             }
-        }
-        
-        io.out.println('list ended')
+        }       
     }
 }
\ No newline at end of file

Modified: geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java?rev=692528&r1=692527&r2=692528&view=diff
==============================================================================
--- geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java (original)
+++ geronimo/server/trunk/framework/modules/geronimo-deploy-tool/src/main/java/org/apache/geronimo/deployment/cli/CommandListConfigurations.java Fri Sep  5 13:21:56 2008
@@ -21,19 +21,29 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Comparator;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeMap;
 import java.util.TreeSet;
 
+import javax.enterprise.deploy.shared.ModuleType;
 import javax.enterprise.deploy.spi.DeploymentManager;
+import javax.enterprise.deploy.spi.exceptions.TargetException;
+import javax.enterprise.deploy.spi.Target;
+import javax.enterprise.deploy.spi.TargetModuleID;
 import javax.security.auth.login.FailedLoginException;
 
 import jline.ConsoleReader;
+
 import org.apache.geronimo.cli.deployer.CommandArgs;
 import org.apache.geronimo.common.DeploymentException;
 import org.apache.geronimo.deployment.plugin.GeronimoDeploymentManager;
+import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl;
 import org.apache.geronimo.kernel.config.NoSuchStoreException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.KernelRegistry;
 import org.apache.geronimo.system.plugin.DownloadResults;
 import org.apache.geronimo.system.plugin.PluginInstallerGBean;
 import org.apache.geronimo.system.plugin.model.PluginArtifactType;
@@ -152,6 +162,39 @@
         return data;
     }
 
+    public PluginListType getLocalApplicationPlugins(GeronimoDeploymentManager mgr, ConsoleReader consoleReader) throws DeploymentException, IOException {
+        PluginListType data = getLocalPluginCategories(mgr, consoleReader);
+        List<String> appList = getApplicationModuleLists(mgr);
+
+        return getPluginsFromIds(appList, data);
+    }
+    
+    public PluginListType getLocalPluginGroups(GeronimoDeploymentManager mgr, ConsoleReader consoleReader) throws DeploymentException, IOException {
+        PluginListType data = getLocalPluginCategories(mgr, consoleReader);
+        PluginListType appData = new PluginListType();
+
+        for (PluginType metadata: data.getPlugin()) {
+            // ignore plugins which have no artifacts defined
+            if (metadata.getPluginArtifact().isEmpty()) {
+                continue;
+            }
+
+            if (metadata.getCategory() == null) {
+                metadata.setCategory("Unspecified");
+            }
+       
+            //determine if the plugin is a plugin group
+            if (metadata.isPluginGroup() != null && metadata.isPluginGroup()) {
+                appData.getPlugin().add(metadata);
+            }
+        }
+        
+        if (appData == null || appData.getPlugin().size() == 0) {
+            return null;
+        }
+        return appData;
+    }
+    
     private Map<String, Collection<PluginType>> writePluginList(PluginListType data, ConsoleReader consoleReader) throws IOException {
         if (data == null) {
             consoleReader.printNewline();
@@ -270,5 +313,30 @@
         PluginListType selected = getPluginsFromIds(list, all);
         assembleServer(mgr, selected, repositoryPath, relativeServerPath, consoleReader);
     }
-
+    
+    private List<String> getApplicationModuleLists(GeronimoDeploymentManager mgr) throws DeploymentException {
+        List<String> apps = new ArrayList<String>();
+        
+        TargetModuleID[] modules;
+        
+        try {
+            modules = mgr.getAvailableModules(null, mgr.getTargets());
+        } catch (TargetException e) {
+            throw new DeploymentException("Unable to query available modules", e);
+        } catch (IllegalStateException e) {
+            throw new DeploymentSyntaxException(e.getMessage(), e);
+        }
+        
+        for (int i = 0; i < modules.length; i++) {
+            ModuleType type = ((TargetModuleIDImpl)modules[i]).getType();
+            if (type != null) {
+                if (type.equals(ModuleType.WAR) || type.equals(ModuleType.EAR) || type.equals(ModuleType.EJB) || type.equals(ModuleType.RAR) || type.equals(ModuleType.CAR)) {
+                    apps.add(((TargetModuleIDImpl)modules[i]).getModuleID());
+                }
+            }
+        }
+        
+        return apps;
+        
+    }
 }