You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2006/04/20 00:12:58 UTC

svn commit: r395410 - in /geronimo/branches/1.1: modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PackageBuilder.java

Author: djencks
Date: Wed Apr 19 15:12:56 2006
New Revision: 395410

URL: http://svn.apache.org/viewcvs?rev=395410&view=rev
Log:
GERONIMO-1866 step 1, supply a target config store to the deployer

Modified:
    geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
    geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PackageBuilder.java

Modified: geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java?rev=395410&r1=395409&r2=395410&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java (original)
+++ geronimo/branches/1.1/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java Wed Apr 19 15:12:56 2006
@@ -33,6 +33,7 @@
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
+import java.net.URI;
 
 import javax.management.ObjectName;
 
@@ -116,9 +117,9 @@
         }
 
         try {
-            return deploy(inPlace, planFile, moduleFile, null, true, null, null, null, null);
+            return deploy(inPlace, planFile, moduleFile, null, true, null, null, null, null, null);
         } catch (DeploymentException e) {
-            log.debug("Deployment failed: plan=" + planFile +", module=" + originalModuleFile, e);
+            log.debug("Deployment failed: plan=" + planFile + ", module=" + originalModuleFile, e);
             throw e.cleanse();
         } finally {
             if (tmpDir != null) {
@@ -142,7 +143,7 @@
     public String getRemoteDeployUploadURL() {
         // Get the token GBean from the remote deployment configuration
         Set set = kernel.listGBeans(new AbstractNameQuery("org.apache.geronimo.deployment.remote.RemoteDeployToken"));
-        if(set.size() == 0) {
+        if (set.size() == 0) {
             return null;
         }
         AbstractName token = (AbstractName) set.iterator().next();
@@ -151,12 +152,12 @@
         ObjectName config = null;
         for (Iterator it = set.iterator(); it.hasNext();) {
             AbstractName name = (AbstractName) it.next();
-            if(Configuration.isConfigurationObjectName(name.getObjectName())) {
+            if (Configuration.isConfigurationObjectName(name.getObjectName())) {
                 config = name.getObjectName();
                 break;
             }
         }
-        if(config == null) {
+        if (config == null) {
             log.warn("Unable to find remote deployment configuration; is the remote deploy web application running?");
             return null;
         }
@@ -172,7 +173,7 @@
             String containerName = (String) kernel.getAttribute(module, "containerName");
             String contextPath = (String) kernel.getAttribute(module, "contextPath");
             String urlPrefix = getURLFor(containerName);
-            return urlPrefix+contextPath+"/upload";
+            return urlPrefix + contextPath + "/upload";
         } catch (Exception e) {
             log.error("Unable to look up remote deploy upload URL", e);
             return null;
@@ -191,7 +192,7 @@
             String[] cntNames = (String[]) kernel.getAttribute(mgrName, "containers");
             for (int i = 0; i < cntNames.length; i++) {
                 String cntName = cntNames[i];
-                if(cntName.equals(containerName)) {
+                if (cntName.equals(containerName)) {
                     String[] cncNames = (String[]) kernel.invoke(mgrName, "getConnectorsForContainer", new Object[]{cntName}, new String[]{"java.lang.String"});
                     Map map = new HashMap();
                     for (int j = 0; j < cncNames.length; j++) {
@@ -201,7 +202,7 @@
                         map.put(protocol, url);
                     }
                     String urlPrefix;
-                    if((urlPrefix = (String) map.get("HTTP")) == null) {
+                    if ((urlPrefix = (String) map.get("HTTP")) == null) {
                         urlPrefix = (String) map.get("HTTPS");
                     }
                     return urlPrefix;
@@ -211,7 +212,16 @@
         return null;
     }
 
-    public List deploy(boolean inPlace, File planFile, File moduleFile, File targetFile, boolean install, String mainClass, String classPath, String endorsedDirs, String extensionDirs) throws DeploymentException {
+    public List deploy(boolean inPlace,
+            File planFile,
+            File moduleFile,
+            File targetFile,
+            boolean install,
+            String mainClass,
+            String classPath,
+            String endorsedDirs,
+            String extensionDirs,
+            String targetConfigurationStore) throws DeploymentException {
         if (planFile == null && moduleFile == null) {
             throw new DeploymentException("No plan or module specified");
         }
@@ -255,26 +265,26 @@
             if (builder == null) {
                 throw new DeploymentException("Cannot deploy the requested application module (" +
                         (planFile == null ? "" : "planFile=" + planFile.getAbsolutePath()) +
-                        (moduleFile == null ? "" : (planFile == null ? "" : ", ")+"moduleFile=" + moduleFile.getAbsolutePath())+")");
+                        (moduleFile == null ? "" : (planFile == null ? "" : ", ") + "moduleFile=" + moduleFile.getAbsolutePath()) + ")");
             }
 
             Artifact configID = builder.getConfigurationID(plan, module);
             // If the Config ID isn't fully resolved, populate it with defaults
-            if(!configID.isResolved()) {
+            if (!configID.isResolved()) {
                 String group = configID.getGroupId();
-                if(group == null) {
+                if (group == null) {
                     group = Artifact.DEFAULT_GROUP_ID;
                 }
                 String artifactId = configID.getArtifactId();
-                if(artifactId == null) {
-                    throw new DeploymentException("Every configuration to deploy must have a ConfigID with an ArtifactID (not "+configID+")");
+                if (artifactId == null) {
+                    throw new DeploymentException("Every configuration to deploy must have a ConfigID with an ArtifactID (not " + configID + ")");
                 }
                 Version version = configID.getVersion();
-                if(version == null) {
+                if (version == null) {
                     version = new Version(Long.toString(System.currentTimeMillis()));
                 }
                 String type = configID.getType();
-                if(type == null) {
+                if (type == null) {
                     type = "car";
                 }
                 configID = new Artifact(group, artifactId, version, type);
@@ -282,7 +292,7 @@
             // Make sure this configuration doesn't already exist
             try {
                 kernel.getGBeanState(Configuration.getConfigurationAbstractName(configID));
-                throw new DeploymentException("Module "+configID+" already exists in the server.  Try to undeploy it first or use the redeploy command.");
+                throw new DeploymentException("Module " + configID + " already exists in the server.  Try to undeploy it first or use the redeploy command.");
             } catch (GBeanNotFoundException e) {
                 // this is good
             }
@@ -309,11 +319,16 @@
                 manifest = null;
             }
 
-            //TODO adapt to multiple config stores!
             if (stores.isEmpty()) {
                 throw new DeploymentException("No ConfigurationStores!");
             }
-            ConfigurationStore store = (ConfigurationStore) stores.iterator().next();
+            ConfigurationStore store;
+            if (targetConfigurationStore != null) {
+                AbstractName targetStoreName = new AbstractName(new URI(targetConfigurationStore));
+                store = (ConfigurationStore) kernel.getGBean(targetStoreName);
+            } else {
+                store = (ConfigurationStore) stores.iterator().next();
+            }
             // It's our responsibility to close this context, once we're done with it...
             DeploymentContext context = builder.buildConfiguration(inPlace, configID, plan, module, stores, artifactResolver, store);
             List configurations = new ArrayList();
@@ -358,7 +373,7 @@
                     context.close();
                 }
             }
-        } catch(Throwable e) {
+        } catch (Throwable e) {
             //TODO not clear all errors will result in total cleanup
 //            File configurationDir = configurationData.getConfigurationDir();
 //            if (!DeploymentUtil.recursiveDelete(configurationDir)) {
@@ -371,9 +386,9 @@
 
             if (e instanceof Error) {
                 log.error("Deployment failed due to ", e);
-                throw (Error)e;
+                throw (Error) e;
             } else if (e instanceof DeploymentException) {
-                throw (DeploymentException)e;
+                throw (DeploymentException) e;
             } else if (e instanceof Exception) {
                 log.error("Deployment failed due to ", e);
                 throw new DeploymentException(e);
@@ -414,7 +429,7 @@
 
         public void run() {
             log.debug("ConfigStoreReaper started");
-            while(!done) {
+            while (!done) {
                 try {
                     Thread.sleep(reaperInterval);
                 } catch (InterruptedException e) {
@@ -425,7 +440,7 @@
         }
 
         /**
-         * For every directory in the pendingDeletionIndex, attempt to delete all 
+         * For every directory in the pendingDeletionIndex, attempt to delete all
          * sub-directories and files.
          */
         public void reap() {
@@ -435,7 +450,7 @@
             // Otherwise, attempt to delete all of the directories
             Enumeration list = pendingDeletionIndex.propertyNames();
             while (list.hasMoreElements()) {
-                String dirName = (String)list.nextElement();
+                String dirName = (String) list.nextElement();
                 File deleteDir = new File(dirName);
 
                 if (!DeploymentUtil.recursiveDelete(deleteDir)) {
@@ -445,7 +460,7 @@
             }
         }
     }
-    
+
     public static final GBeanInfo GBEAN_INFO;
 
     private static final String DEPLOYER = "Deployer";
@@ -456,7 +471,7 @@
         infoFactory.addAttribute("kernel", Kernel.class, false);
         infoFactory.addAttribute("remoteDeployUploadURL", String.class, false);
         infoFactory.addOperation("deploy", new Class[]{boolean.class, File.class, File.class});
-        infoFactory.addOperation("deploy", new Class[]{boolean.class, File.class, File.class, File.class, boolean.class, String.class, String.class, String.class, String.class});
+        infoFactory.addOperation("deploy", new Class[]{boolean.class, File.class, File.class, File.class, boolean.class, String.class, String.class, String.class, String.class, String.class});
 
         infoFactory.addReference("Builders", ConfigurationBuilder.class, "ConfigBuilder");
         infoFactory.addReference("Store", ConfigurationStore.class, "ConfigurationStore");

Modified: geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PackageBuilder.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PackageBuilder.java?rev=395410&r1=395409&r2=395410&view=diff
==============================================================================
--- geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PackageBuilder.java (original)
+++ geronimo/branches/1.1/plugins/geronimo-packaging-plugin/src/java/org/apache/geronimo/plugin/packaging/PackageBuilder.java Wed Apr 19 15:12:56 2006
@@ -68,6 +68,7 @@
             String.class.getName(),
             String.class.getName(),
             String.class.getName(),
+            String.class.getName(),
     };
 
     private String repositoryClass;
@@ -87,6 +88,8 @@
     private String extensionDirs;
     private String explicitResolutionLocation;
 
+    private String targetConfigStore;
+
     public String getRepositoryClass() {
         return repositoryClass;
     }
@@ -256,7 +259,7 @@
             }
 
             AbstractName deployer = locateDeployer(kernel);
-            invokeDeployer(kernel, deployer);
+            invokeDeployer(kernel, deployer, targetConfigStore);
             System.out.println("Generated package " + packageFile);
         } catch (Exception e) {
             log.error(e.getClass().getName() + ": " + e.getMessage(), e);
@@ -267,7 +270,7 @@
     /**
      * Create a Geronimo Kernel to contain the deployment configurations.
      */
-    private static synchronized Kernel createKernel(File repository, String repoClass, String configStoreClass, String explicitResolutionLocation) throws Exception {
+    private synchronized Kernel createKernel(File repository, String repoClass, String configStoreClass, String explicitResolutionLocation) throws Exception {
         // first return our cached version
         if (kernel != null) {
             return kernel;
@@ -294,7 +297,7 @@
      * This contains Repository and ConfigurationStore GBeans that map to
      * the local maven installation.
      */
-    private static void bootDeployerSystem(Kernel kernel, File repository, String
+    private void bootDeployerSystem(Kernel kernel, File repository, String
             repoClass, String configStoreClass, String explicitResolutionLocation) throws Exception {
         Artifact baseId = new Artifact("geronimo", "packaging", "fixed", "car");
         Naming naming = kernel.getNaming();
@@ -317,14 +320,7 @@
         if (configStoreInfo.getReference("Repository") != null) {
             storeGBean.setReferencePattern("Repository", repoGBean.getAbstractName());
         }
-//        Set refs = configStoreInfo.getReferences();
-//        for (Iterator iterator = refs.iterator(); iterator.hasNext();) {
-//            GReferenceInfo refInfo = (GReferenceInfo) iterator.next();
-//            if ("Repository".equals(refInfo.getName())) {
-//                storeGBean.setReferencePattern("Repository", repositoryName);
-//                break;
-//            }
-//        }
+        targetConfigStore = storeGBean.getAbstractName().toString();
 
         GBeanData attrManagerGBean = bootstrap.addGBean("AttributeStore", MavenAttributeStore.GBEAN_INFO);
 
@@ -337,67 +333,6 @@
 
         ConfigurationUtil.loadBootstrapConfiguration(kernel, bootstrap, cl);
 
-//        Map nameMap = new HashMap();
-//        nameMap.put("type", "plugin");
-//        nameMap.put("name", "packaging");
-//        ObjectName objectName;
-//        try {
-//            objectName = ObjectName.getInstance(KERNEL_NAME + "j2eeType=plugin,name=packaging");
-//        } catch (MalformedObjectNameException e) {
-//            throw (IllegalArgumentException)new IllegalArgumentException("Could not construct a fixed object name").initCause(e);
-//        }
-//        AbstractName rootName = new AbstractName(baseId, nameMap, objectName);
-//        AbstractName repositoryName = kernel.getNaming().createChildName(rootName, "Repository", "Repository");
-//        AbstractName artifactManagerName = kernel.getNaming().createChildName(rootName, "ArtifactManager", "ArtifactManager");
-//        AbstractName artifactResolverName = kernel.getNaming().createChildName(rootName, "ArtifactResolver", "ArtifactResolver");
-//        AbstractName configStoreName = kernel.getNaming().createChildName(rootName, "PackageBuilderConfigStore", "ConfigurationStore");
-//        AbstractName configManagerName = kernel.getNaming().createChildName(rootName, "ConfigurationManager", "ConfigurationManager");
-//        AbstractName attributeStoreName = kernel.getNaming().createChildName(rootName, "ManagedAttributeStore", "ManagedAttributeStore");
-//
-//        GBeanInfo repoInfo = GBeanInfo.getGBeanInfo(repoClass, cl);
-//        GBeanData repoGBean = new GBeanData(repositoryName, repoInfo);
-//        URI repositoryURI = repository.toURI();
-//        repoGBean.setAttribute("root", repositoryURI);
-//        kernel.loadGBean(repoGBean, cl);
-//        kernel.startGBean(repositoryName);
-
-        //TODO parameterize these?
-//        GBeanData artifactManagerGBean = new GBeanData(artifactManagerName, DefaultArtifactManager.GBEAN_INFO);
-//        kernel.loadGBean(artifactManagerGBean, cl);
-//        kernel.startGBean(artifactManagerName);
-
-//        GBeanData artifactResolverGBean = new GBeanData(artifactResolverName, DefaultArtifactResolver.GBEAN_INFO);
-//        artifactResolverGBean.setReferencePattern("Repositories", repositoryName);
-//        artifactResolverGBean.setReferencePattern("ArtifactManager", artifactManagerName);
-//        kernel.loadGBean(artifactResolverGBean, cl);
-//        kernel.startGBean(artifactResolverName);
-
-//        GBeanInfo configStoreInfo = GBeanInfo.getGBeanInfo(configStoreClass, cl);
-//        GBeanData storeGBean = new GBeanData(configStoreName, configStoreInfo);
-//        Set refs = configStoreInfo.getReferences();
-//        for (Iterator iterator = refs.iterator(); iterator.hasNext();) {
-//            GReferenceInfo refInfo = (GReferenceInfo) iterator.next();
-//            if ("Repository".equals(refInfo.getName())) {
-//                storeGBean.setReferencePattern("Repository", repositoryName);
-//                break;
-//            }
-//        }
-//        kernel.loadGBean(storeGBean, cl);
-//        kernel.startGBean(configStoreName);
-
-//        GBeanData configManagerGBean = new GBeanData(configManagerName, KernelConfigurationManager.GBEAN_INFO);
-//        configManagerGBean.setReferencePattern("Stores", configStoreName);
-//        configManagerGBean.setReferencePattern("AttributeStore", attributeStoreName);
-//        configManagerGBean.setReferencePattern("ArtifactManager", artifactManagerName);
-//        configManagerGBean.setReferencePattern("ArtifactResolver", artifactResolverName);
-//        kernel.loadGBean(configManagerGBean, cl);
-//        kernel.startGBean(configManagerName);
-//
-//        GBeanData attrManagerGBean = new GBeanData(attributeStoreName, MavenAttributeStore.GBEAN_INFO);
-//        kernel.loadGBean(attrManagerGBean, cl);
-//        kernel.startGBean(attributeStoreName);
-
-
     }
 
     /**
@@ -419,9 +354,9 @@
         return deployer;
     }
 
-    private List invokeDeployer(Kernel kernel, AbstractName deployer) throws Exception {
+    private List invokeDeployer(Kernel kernel, AbstractName deployer, String targetConfigStore) throws Exception {
         boolean isExecutable = mainClass != null;
-        Object[] args = {Boolean.FALSE, planFile, moduleFile, isExecutable ? packageFile : null, Boolean.valueOf(!isExecutable), mainClass, classPath, endorsedDirs, extensionDirs};
+        Object[] args = {Boolean.FALSE, planFile, moduleFile, isExecutable ? packageFile : null, Boolean.valueOf(!isExecutable), mainClass, classPath, endorsedDirs, extensionDirs, targetConfigStore};
         return (List) kernel.invoke(deployer, "deploy", args, ARG_TYPES);
     }
 }