dain 2004/02/25 00:03:53
Modified: modules/deployment/src/java/org/apache/geronimo/deployment Bootstrap.java DeploymentContext.java ModuleDeployer.java modules/deployment/src/java/org/apache/geronimo/deployment/service ServiceConfigBuilder.java modules/kernel/src/java/org/apache/geronimo/kernel/config Configuration.java modules/system/src/java/org/apache/geronimo/system/repository ReadOnlyRepository.java Log: Simplified Bootstrap construction of the deployer The deployer.jar is built from the deployer-system-plan.xml file and the j2ee deployer is built from the j2ee-deployer-plan.xml. This eliminates all of the hard coded plans from Bootstrap. Revision Changes Path 1.10 +61 -167 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/Bootstrap.java Index: Bootstrap.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/Bootstrap.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- Bootstrap.java 24 Feb 2004 07:36:20 -0000 1.9 +++ Bootstrap.java 25 Feb 2004 08:03:53 -0000 1.10 @@ -58,34 +58,20 @@ import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; -import java.io.ObjectOutputStream; -import java.net.URI; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; import java.util.jar.Attributes; import java.util.jar.JarInputStream; import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import java.util.zip.ZipEntry; -import javax.management.ObjectName; import org.apache.geronimo.deployment.service.ServiceConfigBuilder; -import org.apache.geronimo.gbean.jmx.GBeanMBean; -import org.apache.geronimo.kernel.Kernel; -import org.apache.geronimo.kernel.config.Configuration; -import org.apache.geronimo.kernel.config.ConfigurationManager; -import org.apache.geronimo.kernel.jmx.JMXUtil; +import org.apache.geronimo.deployment.xbeans.ConfigurationDocument; +import org.apache.geronimo.deployment.xbeans.ConfigurationType; import org.apache.geronimo.system.configuration.LocalConfigStore; import org.apache.geronimo.system.main.CommandLine; import org.apache.geronimo.system.repository.ReadOnlyRepository; -import org.apache.geronimo.system.serverinfo.ServerInfo; import org.apache.xmlbeans.XmlBeans; import org.apache.xmlbeans.XmlObject; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; /** * Helper class to bootstrap the Geronimo deployer. @@ -93,212 +79,120 @@ * @version $Revision$ $Date$ */ public class Bootstrap { - public static final URI CONFIG_ID = URI.create("org/apache/geronimo/DeployerSystem"); - private static final ObjectName REPOSITORY_NAME = JMXUtil.getObjectName("geronimo.deployer:role=Repository,root=repository"); - private static final ObjectName SERVICE_BUILDER_NAME = JMXUtil.getObjectName("geronimo.deployer:role=Builder,type=Service,id=" + CONFIG_ID.toString()); + private String deployerJar; + private String storeDir; + private String repositoryDir; + private String deployerSystemPlan; + private String j2eeDeployerPlan; + private String deployerClassPath; + private String deployerGBean; - private String outputFile; - private String baseDir; - private String store; - private String deploymentPlan; - private String classPath; - private String mainGBean; - private String mainMethod; - private String configurations; - - public String getOutputFile() { - return outputFile; - } - - public void setOutputFile(String outputFile) { - this.outputFile = outputFile; + public String getDeployerJar() { + return deployerJar; } - public String getBaseDir() { - return baseDir; + public void setDeployerJar(String deployerJar) { + this.deployerJar = deployerJar; } - public void setBaseDir(String baseDir) { - this.baseDir = baseDir; + public String getStoreDir() { + return storeDir; } - public String getStore() { - return store; + public void setStoreDir(String storeDir) { + this.storeDir = storeDir; } - public void setStore(String store) { - this.store = store; + public String getRepositoryDir() { + return repositoryDir; } - public String getDeploymentPlan() { - return deploymentPlan; + public void setRepositoryDir(String repositoryDir) { + this.repositoryDir = repositoryDir; } - public void setDeploymentPlan(String deploymentPlan) { - this.deploymentPlan = deploymentPlan; + public String getDeployerSystemPlan() { + return deployerSystemPlan; } - public String getClassPath() { - return classPath; + public void setDeployerSystemPlan(String deployerSystemPlan) { + this.deployerSystemPlan = deployerSystemPlan; } - public void setClassPath(String classPath) { - this.classPath = classPath; + public String getJ2eeDeployerPlan() { + return j2eeDeployerPlan; } - public String getMainGBean() { - return mainGBean; + public void setJ2eeDeployerPlan(String j2eeDeployerPlan) { + this.j2eeDeployerPlan = j2eeDeployerPlan; } - public void setMainGBean(String mainGBean) { - this.mainGBean = mainGBean; + public String getDeployerClassPath() { + return deployerClassPath; } - public String getMainMethod() { - return mainMethod; + public void setDeployerClassPath(String deployerClassPath) { + this.deployerClassPath = deployerClassPath; } - public void setMainMethod(String mainMethod) { - this.mainMethod = mainMethod; + public String getDeployerGBean() { + return deployerGBean; } - public String getConfigurations() { - return configurations; + public void setDeployerGBean(String deployerGBean) { + this.deployerGBean = deployerGBean; } - public void setConfigurations(String configurations) { - this.configurations = configurations; - } - - public void bootstrap() { - File file = new File(outputFile); - File storeDir = new File(baseDir, store); - + public void bootstrap() throws Exception { ClassLoader oldCL = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(Bootstrap.class.getClassLoader()); try { - GBeanMBean deploymentSystemConfig = getDeploymentSystemConfig(new URI(store)); + // parse the deployment-system and j2ee-deployer plans + XmlObject deployerSystemXML = XmlBeans.getContextTypeLoader().parse(new File(deployerSystemPlan), null, null); + XmlObject j2eeDeployerXML = XmlBeans.getContextTypeLoader().parse(new File(j2eeDeployerPlan), null, null); + ConfigurationType j2eeDeployerConfig = ((ConfigurationDocument) j2eeDeployerXML).getConfiguration(); + + // create the service builder, repository and config store objects + LocalConfigStore configStore = new LocalConfigStore(new File(storeDir)); + ReadOnlyRepository repository = new ReadOnlyRepository(new File(repositoryDir)); + ServiceConfigBuilder builder = new ServiceConfigBuilder(repository); // create the manifext Manifest manifest = new Manifest(); Attributes mainAttributes = manifest.getMainAttributes(); mainAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); mainAttributes.putValue(Attributes.Name.MAIN_CLASS.toString(), CommandLine.class.getName()); - mainAttributes.putValue(Attributes.Name.CLASS_PATH.toString(), classPath); - mainAttributes.putValue(CommandLine.MAIN_GBEAN.toString(), mainGBean); - mainAttributes.putValue(CommandLine.MAIN_METHOD.toString(), mainMethod); - mainAttributes.putValue(CommandLine.CONFIGURATIONS.toString(), configurations); + mainAttributes.putValue(Attributes.Name.CLASS_PATH.toString(), deployerClassPath); + mainAttributes.putValue(CommandLine.MAIN_GBEAN.toString(), deployerGBean); + mainAttributes.putValue(CommandLine.MAIN_METHOD.toString(), "deploy"); + mainAttributes.putValue(CommandLine.CONFIGURATIONS.toString(), j2eeDeployerConfig.getConfigId()); + // build and install the deployer-system configuration // write the deployer system out to a jar - JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(file)), manifest); + File outputFile = new File(deployerJar); + JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)), manifest); try { // add the startup jar entry which allows us to locat the startup directory jos.putNextEntry(new ZipEntry("META-INF/startup-jar")); jos.closeEntry(); - // write the configuration to the jar - jos.putNextEntry(new ZipEntry("META-INF/config.ser")); - ObjectOutputStream ois = new ObjectOutputStream(jos); - Configuration.storeGMBeanState(deploymentSystemConfig, ois); - ois.flush(); - jos.closeEntry(); + // add the deployment system configuration to the jar + builder.buildConfiguration(jos, deployerSystemXML); } finally { jos.close(); } + configStore.install(outputFile.toURL()); - // install the deployer systen in to the config store - LocalConfigStore configStore = new LocalConfigStore(storeDir); - configStore.install(file.toURL()); - - System.setProperty("geronimo.base.dir", baseDir); - Kernel kernel = new Kernel("geronimo.bootstrap"); - kernel.boot(); - - ConfigurationManager configurationManager = kernel.getConfigurationManager(); - ObjectName deploymentSystemName = configurationManager.load(deploymentSystemConfig, file.toURL()); - kernel.startRecursiveGBean(deploymentSystemName); - - GBeanMBean serviceDeployerConfig = getServiceDeployerConfig(); - serviceDeployerConfig.setReferencePatterns("Parent", Collections.singleton(deploymentSystemName)); - ObjectName serviceDeployerName = configurationManager.load(serviceDeployerConfig, file.toURL()); - kernel.startRecursiveGBean(serviceDeployerName); - - File tempFile = File.createTempFile("deployer", ".car"); + // build and install the j2ee-deployer configuration + File tempFile = File.createTempFile("j2ee-deployer", ".car"); try { - URL planURL = new File(deploymentPlan).toURL(); - XmlObject plan = XmlBeans.getContextTypeLoader().parse(planURL, null, null); - kernel.getMBeanServer().invoke( - SERVICE_BUILDER_NAME, - "buildConfiguration", - new Object[]{tempFile, null, plan}, - new String[]{File.class.getName(), JarInputStream.class.getName(), XmlObject.class.getName()}); + builder.buildConfiguration(tempFile, (JarInputStream)null, j2eeDeployerXML); configStore.install(tempFile.toURL()); } finally { tempFile.delete(); } - - kernel.stopGBean(deploymentSystemName); - kernel.shutdown(); - } catch (Exception e) { - e.printStackTrace(); - System.exit(2); - throw new AssertionError(); } finally { Thread.currentThread().setContextClassLoader(oldCL); } - } - - private static GBeanMBean getDeploymentSystemConfig(URI storeDir) throws Exception { - Map gbeans = new HashMap(); - - // Install ServerInfo GBean - ObjectName serverInfoName = new ObjectName("geronimo.deployer:role=ServerInfo"); - GBeanMBean serverInfo = new GBeanMBean(ServerInfo.getGBeanInfo()); - gbeans.put(serverInfoName, serverInfo); - - // Install LocalConfigStore - GBeanMBean storeGBean = new GBeanMBean(LocalConfigStore.getGBeanInfo()); - storeGBean.setAttribute("root", storeDir); - storeGBean.setReferencePatterns("ServerInfo", Collections.singleton(serverInfoName)); - gbeans.put(new ObjectName("geronimo.boot:role=ConfigurationStore"), storeGBean); - - // Install default local Repository - GBeanMBean localRepo = new GBeanMBean(ReadOnlyRepository.GBEAN_INFO); - localRepo.setAttribute("Root", URI.create("repository/")); - localRepo.setReferencePatterns("ServerInfo", Collections.singleton(serverInfoName)); - gbeans.put(REPOSITORY_NAME, localRepo); - - // assemble the deployer system configuration - GBeanMBean config = new GBeanMBean(Configuration.GBEAN_INFO); - config.setAttribute("ID", CONFIG_ID); - config.setReferencePatterns("Parent", null); - config.setAttribute("ClassPath", new ArrayList()); - config.setAttribute("GBeanState", Configuration.storeGBeans(gbeans)); - config.setAttribute("Dependencies", Collections.EMPTY_LIST); - return config; - } - - private static GBeanMBean getServiceDeployerConfig() throws Exception { - Map gbeans = new HashMap(); - - // Install ServiceConfigBuilder - GBeanMBean serviceBuilder = new GBeanMBean(ServiceConfigBuilder.GBEAN_INFO); - serviceBuilder.setReferencePatterns("Repository", Collections.singleton(REPOSITORY_NAME)); - serviceBuilder.setReferencePatterns("Kernel", Collections.singleton(Kernel.KERNEL)); - gbeans.put(SERVICE_BUILDER_NAME, serviceBuilder); - - // Install Deployer - ObjectName deployerName = Deployer.getDeployerName(CONFIG_ID); - GBeanMBean deployer = new GBeanMBean(Deployer.GBEAN_INFO); - deployer.setReferencePatterns("Builders", Collections.singleton(SERVICE_BUILDER_NAME)); - gbeans.put(deployerName, deployer); - - GBeanMBean config = new GBeanMBean(Configuration.GBEAN_INFO); - config.setAttribute("ID", new URI("temp/deployment/ServiceDeployer")); - config.setAttribute("ClassPath", new ArrayList()); - config.setAttribute("GBeanState", Configuration.storeGBeans(gbeans)); - config.setAttribute("Dependencies", Collections.EMPTY_LIST); - - return config; } } 1.5 +10 -8 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java Index: DeploymentContext.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- DeploymentContext.java 24 Feb 2004 06:05:36 -0000 1.4 +++ DeploymentContext.java 25 Feb 2004 08:03:53 -0000 1.5 @@ -115,7 +115,7 @@ throw new AssertionError(); } - if (parentID != null) { + if (kernel != null && parentID != null) { ObjectName parentName = ConfigurationManager.getConfigObjectName(parentID); config.setReferencePatterns("Parent", Collections.singleton(parentName)); try { @@ -141,9 +141,11 @@ } } else { ancestors = null; - parentCL = ClassLoader.getSystemClassLoader(); + // no explicit parent set, so use the class loader of this class as + // the parent... this class should be in the root geronimo classloader, + // which is normally the system class loader but not always, so be safe + parentCL = getClass().getClassLoader(); } - } public URI getConfigID() { @@ -228,12 +230,12 @@ jos.flush(); jos.close(); - try { - if (ancestors != null && ancestors.size() > 0) { + if (kernel != null && ancestors != null && ancestors.size() > 0) { + try { kernel.stopGBean((ObjectName) ancestors.get(0)); + } catch (Exception e) { + throw new DeploymentException(e); } - } catch (Exception e) { - throw new DeploymentException(e); } } 1.5 +7 -12 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/ModuleDeployer.java Index: ModuleDeployer.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/ModuleDeployer.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ModuleDeployer.java 10 Feb 2004 22:34:04 -0000 1.4 +++ ModuleDeployer.java 25 Feb 2004 08:03:53 -0000 1.5 @@ -67,25 +67,22 @@ import java.net.URL; import java.net.URLClassLoader; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Collections; import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; import javax.management.ObjectName; -import javax.management.AttributeNotFoundException; -import javax.management.InvalidAttributeValueException; -import javax.management.MBeanException; -import javax.management.ReflectionException; import org.apache.geronimo.gbean.InvalidConfigurationException; import org.apache.geronimo.gbean.jmx.GBeanMBean; import org.apache.geronimo.kernel.config.Configuration; import org.apache.geronimo.kernel.config.ConfigurationParent; +import org.apache.geronimo.kernel.Kernel; /** * @@ -161,12 +158,10 @@ } ClassLoader cl; if (parent == null) { - //Use in maven plugin seems to require access to the classloader used to load this class, - //not just the SystemClassLoader. DeployCommand sets the thread context classloader. - // If I understand Maven correctly it will load using a classloader including the - //dependencies specified in the plugins project.xml file. - //cl = new URLClassLoader(urls); - cl = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); + // no explicit parent set, so use the class loader of Kernel as the + // parent... the Kernel class should be in the root geronimo classloader, + // which is normally the system class loader but not always, so be safe + cl = new URLClassLoader(urls, Kernel.class.getClassLoader()); } else { cl = new URLClassLoader(urls, parent.getClassLoader()); } 1.8 +41 -31 incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java Index: ServiceConfigBuilder.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- ServiceConfigBuilder.java 24 Feb 2004 06:05:37 -0000 1.7 +++ ServiceConfigBuilder.java 25 Feb 2004 08:03:53 -0000 1.8 @@ -103,6 +103,10 @@ private final Repository repository; private final Kernel kernel; + public ServiceConfigBuilder(Repository repository) { + this(repository, null); + } + public ServiceConfigBuilder(Repository repository, Kernel kernel) { this.repository = repository; this.kernel = kernel; @@ -125,30 +129,13 @@ } public void buildConfiguration(File outfile, JarInputStream module, XmlObject plan) throws IOException, DeploymentException { - ConfigurationType configType = ((ConfigurationDocument) plan).getConfiguration(); - URI configID; - try { - configID = new URI(configType.getConfigId()); - } catch (URISyntaxException e) { - throw new DeploymentException("Invalid configId " + configType.getConfigId(), e); - } - URI parentID; - if (configType.isSetParentId()) { - try { - parentID = new URI(configType.getParentId()); - } catch (URISyntaxException e) { - throw new DeploymentException("Invalid parentId " + configType.getParentId(), e); - } - } else { - parentID = null; - } - // create the manifext Manifest manifest = new Manifest(); Attributes mainAttributes = manifest.getMainAttributes(); mainAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); // add the manifest entries to make the archive executable + ConfigurationType configType = ((ConfigurationDocument) plan).getConfiguration(); ExecutableType executable = configType.getExecutable(); if(executable != null) { mainAttributes.putValue(Attributes.Name.MAIN_CLASS.toString(), executable.getMainClass()); @@ -167,22 +154,45 @@ os.closeEntry(); } - DeploymentContext context = null; - try { - context = new DeploymentContext(os, configID, parentID, kernel); - } catch (MalformedObjectNameException e) { - throw new DeploymentException(e); - } - addIncludes(context, configType); - addDependencies(context, configType.getDependencyArray()); - ClassLoader cl = context.getClassLoader(repository); - addGBeans(context, configType.getGbeanArray(), cl); - context.close(); - os.flush(); + buildConfiguration(os, plan); + } finally { fos.close(); } + } + + public void buildConfiguration(JarOutputStream os, XmlObject plan) throws DeploymentException, IOException { + ConfigurationType configType = ((ConfigurationDocument) plan).getConfiguration(); + URI configID; + try { + configID = new URI(configType.getConfigId()); + } catch (URISyntaxException e) { + throw new DeploymentException("Invalid configId " + configType.getConfigId(), e); + } + URI parentID; + if (configType.isSetParentId()) { + try { + parentID = new URI(configType.getParentId()); + } catch (URISyntaxException e) { + throw new DeploymentException("Invalid parentId " + configType.getParentId(), e); + } + } else { + parentID = null; + } + + DeploymentContext context = null; + try { + context = new DeploymentContext(os, configID, parentID, kernel); + } catch (MalformedObjectNameException e) { + throw new DeploymentException(e); + } + addIncludes(context, configType); + addDependencies(context, configType.getDependencyArray()); + ClassLoader cl = context.getClassLoader(repository); + addGBeans(context, configType.getGbeanArray(), cl); + context.close(); + os.flush(); } private void addIncludes(DeploymentContext context, ConfigurationType configType) throws DeploymentException { 1.15 +5 -2 incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java Index: Configuration.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java,v retrieving revision 1.14 retrieving revision 1.15 diff -u -r1.14 -r1.15 --- Configuration.java 24 Feb 2004 18:41:45 -0000 1.14 +++ Configuration.java 25 Feb 2004 08:03:53 -0000 1.15 @@ -193,7 +193,10 @@ log.debug("ClassPath for " + id + " resolved to " + Arrays.asList(urls)); if (parent == null) { - classLoader = new URLClassLoader(urls, Thread.currentThread().getContextClassLoader()); + // no explicit parent set, so use the class loader of this class as + // the parent... this class should be in the root geronimo classloader, + // which is normally the system class loader but not always, so be safe + classLoader = new URLClassLoader(urls, getClass().getClassLoader()); } else { classLoader = new URLClassLoader(urls, parent.getClassLoader()); } 1.3 +14 -4 incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/repository/ReadOnlyRepository.java Index: ReadOnlyRepository.java =================================================================== RCS file: /home/cvs/incubator-geronimo/modules/system/src/java/org/apache/geronimo/system/repository/ReadOnlyRepository.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ReadOnlyRepository.java 13 Feb 2004 07:22:22 -0000 1.2 +++ ReadOnlyRepository.java 25 Feb 2004 08:03:53 -0000 1.3 @@ -85,6 +85,16 @@ private final ServerInfo serverInfo; private URI rootURI; + public ReadOnlyRepository(File root) { + this(root.toURI()); + } + + public ReadOnlyRepository(URI rootURI) { + this.root = null; + this.serverInfo = null; + this.rootURI = rootURI; + } + public ReadOnlyRepository(URI root, ServerInfo serverInfo) { this.root = root; this.serverInfo = serverInfo; @@ -113,16 +123,16 @@ } public void doStart() throws WaitingException, Exception { - rootURI = serverInfo.resolve(root); + if(rootURI == null) { + rootURI = serverInfo.resolve(root); + } log.info("Repository root is "+rootURI); } public void doStop() throws WaitingException, Exception { - rootURI = null; } public void doFail() { - rootURI = null; } public static final GBeanInfo GBEAN_INFO;