servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r597331 - in /servicemix/trunk/platforms/geronimo: deployer-service/src/main/java/org/apache/servicemix/geronimo/ servicemix-service/src/main/java/org/apache/servicemix/geronimo/
Date Thu, 22 Nov 2007 08:33:40 GMT
Author: gnodet
Date: Thu Nov 22 00:33:38 2007
New Revision: 597331

URL: http://svn.apache.org/viewvc?rev=597331&view=rev
Log:
SM-1131: Redeployment fails for Geronimo integration

Modified:
    servicemix/trunk/platforms/geronimo/deployer-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixConfigBuilder.java
    servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Component.java
    servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Container.java
    servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceAssembly.java
    servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixGBean.java

Modified: servicemix/trunk/platforms/geronimo/deployer-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixConfigBuilder.java
URL: http://svn.apache.org/viewvc/servicemix/trunk/platforms/geronimo/deployer-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixConfigBuilder.java?rev=597331&r1=597330&r2=597331&view=diff
==============================================================================
--- servicemix/trunk/platforms/geronimo/deployer-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixConfigBuilder.java
(original)
+++ servicemix/trunk/platforms/geronimo/deployer-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixConfigBuilder.java
Thu Nov 22 00:33:38 2007
@@ -23,6 +23,8 @@
 import java.util.Collection;
 import java.util.Enumeration;
 import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.jar.JarFile;
@@ -335,6 +337,8 @@
         unzip(context, module, new URI("install/"));
         // Unzip SUs
         ServiceUnit[] sus = descriptor.getServiceAssembly().getServiceUnits();
+        List<ServiceUnitReference> serviceUnitReferences = new LinkedList<ServiceUnitReference>();
+        
         for (int i = 0; i < sus.length; i++) {
             String name = sus[i].getIdentification().getName();
             String zip = sus[i].getTarget().getArtifactsZip();
@@ -355,6 +359,7 @@
              ServiceUnitManager serviceUnitManager = jbiServiceUnit.getServiceUnitManager();
              File installDir = new File(context.getBaseDir(), installUri.toString());
              String deploy = serviceUnitManager.deploy(name, installDir.getAbsolutePath());
 
+             serviceUnitReferences.add(new ServiceUnitReference(sl, name, installDir.getAbsolutePath()));
              log.debug(deploy);
         }
         // Create the JBI deployment managed object
@@ -364,6 +369,7 @@
         AbstractName name = new AbstractName(environment.getConfigId(), props);
         GBeanData gbeanData = new GBeanData(name, ServiceAssembly.GBEAN_INFO);
         gbeanData.setAttribute("name", descriptor.getServiceAssembly().getIdentification().getName());
+        gbeanData.setAttribute("serviceUnitReferences", serviceUnitReferences);
         gbeanData.setReferencePattern("container", containerName);
         for (int i = 0; i < sus.length; i++) {
             String comp = sus[i].getTarget().getComponentName();
@@ -382,13 +388,29 @@
      * @throws GBeanNotFoundException if the ServiceUnit cannot be found
      */
     private Component getAssociatedJbiServiceUnit(String compName, Artifact artifactName)
throws GBeanNotFoundException {
-        Properties props = new Properties();
+        org.apache.servicemix.geronimo.Component serviceUnit = getComponentGBean(
+				compName, artifactName);
+        Component jbiServiceUnit = serviceUnit.getComponent();
+        return jbiServiceUnit;
+    }
+
+    /**
+     * Returns the sm.ger.Component with the given name
+     * 
+     * @param compName
+     * @param artifactName
+     * @return
+     * @throws GBeanNotFoundException
+     */
+	private org.apache.servicemix.geronimo.Component getComponentGBean(
+			String compName, Artifact artifactName)
+			throws GBeanNotFoundException {
+		Properties props = new Properties();
         props.put("jbiType", "JBIComponent");
         props.put("name", compName);
-        org.apache.servicemix.geronimo.Component serviceUnit = 
+        org.apache.servicemix.geronimo.Component component = 
                 (org.apache.servicemix.geronimo.Component) kernel.getGBean(new AbstractName(artifactName,
props));
-        Component jbiServiceUnit = serviceUnit.getComponent();
-        return jbiServiceUnit;
+        return component;
     }
 
     protected void buildSharedLibrary(Descriptor descriptor, DeploymentContext context, JarFile
module)

Modified: servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Component.java
URL: http://svn.apache.org/viewvc/servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Component.java?rev=597331&r1=597330&r2=597331&view=diff
==============================================================================
--- servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Component.java
(original)
+++ servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Component.java
Thu Nov 22 00:33:38 2007
@@ -65,27 +65,28 @@
         this.installDir = rootDir.resolve("install/");
         this.workDir = rootDir.resolve("workspace/");
         this.classLoader = classLoader;
-        log.info("Created JBI component: " + name);
+        log.debug("Created JBI component: " + name);
     }
 
     public void doStart() throws Exception {
-        log.info("doStart called for JBI component: " + name);
+        log.debug("doStart called for JBI component: " + name);
         try {
             component = (javax.jbi.component.Component) classLoader.loadClass(className).newInstance();
             container.register(this);
         } catch (ClassNotFoundException e) {
             log.error(classLoader);
         }
+        log.info("Started servicemix JBI component: " + name);
     }
 
     public void doStop() throws Exception {
-        log.info("doStop called for JBI component: " + name);
+        log.debug("doStop called for JBI component: " + name);
         container.unregister(this);
         component = null;
     }
 
     public void doFail() {
-        log.info("doFail called for JBI component: " + name);
+        log.debug("doFail called for JBI component: " + name);
         component = null;
     }
 

Modified: servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Container.java
URL: http://svn.apache.org/viewvc/servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Container.java?rev=597331&r1=597330&r2=597331&view=diff
==============================================================================
--- servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Container.java
(original)
+++ servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/Container.java
Thu Nov 22 00:33:38 2007
@@ -16,6 +16,7 @@
  */
 package org.apache.servicemix.geronimo;
 
+import org.apache.servicemix.jbi.container.JBIContainer;
 
 public interface Container {
 
@@ -27,4 +28,5 @@
 
     public void unregister(ServiceAssembly assembly) throws Exception;
 
+    public JBIContainer getJBIContainer();
 }

Modified: servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceAssembly.java
URL: http://svn.apache.org/viewvc/servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceAssembly.java?rev=597331&r1=597330&r2=597331&view=diff
==============================================================================
--- servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceAssembly.java
(original)
+++ servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceAssembly.java
Thu Nov 22 00:33:38 2007
@@ -19,12 +19,20 @@
 import java.io.File;
 import java.net.URI;
 import java.net.URL;
+import java.util.List;
+import java.util.Properties;
+
+import javax.jbi.component.ServiceUnitManager;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.geronimo.gbean.AbstractName;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.kernel.GBeanNotFoundException;
+import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.servicemix.jbi.deployment.Descriptor;
 import org.apache.servicemix.jbi.deployment.DescriptorFactory;
 
@@ -33,47 +41,85 @@
     private static final Log log = LogFactory.getLog(ServiceAssembly.class);
     
     private String name;
-	private Container container;
-	private URI rootDir;
+    private Container container;
+    private URI rootDir;
+    private List<ServiceUnitReference> serviceUnitReferences;
+    private Kernel kernel;
     
 	public ServiceAssembly(String name, 
 			               Container container,
-			               URL configurationBaseUrl) throws Exception {
+			               URL configurationBaseUrl,
+                           List<ServiceUnitReference> serviceUnitReferences,
+                           Kernel kernel) throws Exception {
 		this.name = name;
 		this.container = container;
+        this.serviceUnitReferences = serviceUnitReferences;
+        this.kernel = kernel;
         //TODO is there a simpler way to do this?
         if (configurationBaseUrl.getProtocol().equalsIgnoreCase("file")) {
-        	this.rootDir = new URI("file", configurationBaseUrl.getPath(), null);
+            this.rootDir = new URI("file", configurationBaseUrl.getPath(), null);
         } else {
-        	this.rootDir = URI.create(configurationBaseUrl.toString());
+            this.rootDir = URI.create(configurationBaseUrl.toString());
         }
         log.info("Created JBI service assembly: " + name);
 	}
 	
-	public void doStart() throws Exception {
+    public void doStart() throws Exception {
         log.info("doStart called for JBI service assembly: " + name);
         container.register(this);
-	}
+    }
 
-	public void doStop() throws Exception {
+    public void doStop() throws Exception {
         log.info("doStop called for JBI service assembly: " + name);
         container.unregister(this);
-	}
+    }
 
-	public void doFail() {
+    public void doFail() {
         log.info("doFail called for JBI service assembly: " + name);
-	}
+    }
 	
-	public URI getRootDir() {
-		return rootDir;
-	}
+    public URI getRootDir() {
+        return rootDir;
+    }
 	
-	public String getName() {
-		return name;
-	}
+    public String getName() {
+        return name;
+    }
 	
-	public Descriptor getDescriptor() throws Exception {
-		return DescriptorFactory.buildDescriptor(new File(new File(rootDir), "install"));
+    public void undeploySus() {
+        for (ServiceUnitReference reference: serviceUnitReferences) {
+            undeploy(reference);
+        }       
+    }
+    
+    private void undeploy(ServiceUnitReference reference) {
+       try {
+            Component componentGBean = getComponentGBean(
+                    reference.getAssocialtedServiceUnitName().getArtifactId(), 
+                    reference.getAssocialtedServiceUnitName());
+            ServiceUnitManager serviceUnitManager = 
+                componentGBean.getComponent().getServiceUnitManager();
+            serviceUnitManager.undeploy(reference.getServiceUnitName(), 
+                    reference.getServiceUnitPath());
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private org.apache.servicemix.geronimo.Component getComponentGBean(
+            String compName, Artifact artifactName)
+            throws GBeanNotFoundException {
+        Properties props = new Properties();
+        props.put("jbiType", "JBIComponent");
+        props.put("name", compName);
+        org.apache.servicemix.geronimo.Component serviceUnit = 
+                (org.apache.servicemix.geronimo.Component) 
+                kernel.getGBean(new AbstractName(artifactName, props));
+        return serviceUnit;
+    }
+
+    public Descriptor getDescriptor() throws Exception {
+        return DescriptorFactory.buildDescriptor(new File(new File(rootDir), "install"));
 	}
 
     public static final GBeanInfo GBEAN_INFO;
@@ -81,9 +127,11 @@
     static {
         GBeanInfoBuilder infoFactory = new GBeanInfoBuilder("JBIServiceAssembly", ServiceAssembly.class,
"JBIServiceAssembly");
         infoFactory.addAttribute("name", String.class, true);
+        infoFactory.addAttribute("kernel", Kernel.class, false);
+        infoFactory.addAttribute("serviceUnitReferences", List.class, true);
         infoFactory.addReference("container", Container.class);
         infoFactory.addAttribute("configurationBaseUrl", URL.class, true);
-        infoFactory.setConstructor(new String[] {"name", "container", "configurationBaseUrl"
});
+        infoFactory.setConstructor(new String[] {"name", "container", "configurationBaseUrl",
"serviceUnitReferences" , "kernel"});
         GBEAN_INFO = infoFactory.getBeanInfo();
     }
 

Modified: servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixGBean.java
URL: http://svn.apache.org/viewvc/servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixGBean.java?rev=597331&r1=597330&r2=597331&view=diff
==============================================================================
--- servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixGBean.java
(original)
+++ servicemix/trunk/platforms/geronimo/servicemix-service/src/main/java/org/apache/servicemix/geronimo/ServiceMixGBean.java
Thu Nov 22 00:33:38 2007
@@ -30,7 +30,6 @@
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.kernel.GBeanNotFoundException;
-import org.apache.geronimo.kernel.InternalKernelException;
 import org.apache.geronimo.kernel.Kernel;
 import org.apache.geronimo.naming.java.RootContext;
 import org.apache.servicemix.jbi.container.ComponentEnvironment;
@@ -69,9 +68,9 @@
     }
 
     public ServiceMixGBean(String name, 
-    					   String directory, 
-    					   AbstractNameQuery transactionManagerName, 
-    					   Kernel kernel) {
+                           String directory, 
+                           AbstractNameQuery transactionManagerName, 
+                           Kernel kernel) {
         this.name = name;
         this.directory = directory;
         this.transactionManagerName = transactionManagerName;
@@ -145,8 +144,10 @@
 
     private JBIContainer createContainer() throws GBeanNotFoundException {
         JBIContainer container = new JBIContainer();
+        container.setUseShutdownHook(false);
         container.setName(name);
         container.setRootDir(directory);
+        container.setUseMBeanServer(true);
         TransactionManager tm = getTransactionManager();
         container.setTransactionManager(tm);
         container.setMonitorInstallationDirectory(false);
@@ -167,6 +168,15 @@
         return tm;
     }
 
+    /**
+     * Returns the JBIContainer
+     * 
+     * @return JBIContainer
+     */
+    public JBIContainer getJBIContainer() {
+        return container;
+    }
+    
     public void register(Component component) throws Exception {
         ComponentNameSpace cns = new ComponentNameSpace(container.getName(), component.getName());
         ComponentContextImpl context = new ComponentContextImpl(container, cns);
@@ -177,44 +187,45 @@
         context.setEnvironment(env);
         
         container.activateComponent(null,
-        							component.getComponent(),
-        							component.getDescription(),
-        							context,
-        							component.getType().equals("binding-component"),
-        							component.getType().equals("service-engine"),
+                                    component.getComponent(),
+                                    component.getDescription(),
+                                    context,
+                                    component.getType().equals("binding-component"),
+                                    component.getType().equals("service-engine"),
                                     null);
         ComponentMBeanImpl cmb = container.getComponent(component.getName());
         File stateFile = cmb.getContext().getEnvironment().getStateFile();
         if (stateFile.isFile()) {
-        	cmb.setInitialRunningState();
+            cmb.setInitialRunningState();
         } else {
-        	cmb.start();
+            cmb.start();
         }
     }
 
     public void unregister(Component component) throws Exception {
-    	container.deactivateComponent(component.getName());
+        container.deactivateComponent(component.getName());
     }
     
     public void register(ServiceAssembly assembly) throws Exception {
-    	File rootDir = new File(assembly.getRootDir());
-    	ServiceAssemblyEnvironment env = new ServiceAssemblyEnvironment();
-    	env.setRootDir(rootDir);
-    	env.setInstallDir(new File(rootDir, "install"));
-    	env.setSusDir(new File(rootDir, "sus"));
-    	env.setStateFile(new File(rootDir, "state.xml"));
-    	ServiceAssemblyLifeCycle salc = container.getRegistry().registerServiceAssembly(assembly.getDescriptor().getServiceAssembly(),
env);
-    	if (env.getStateFile().isFile()) {
-    		salc.restore();
-    	} else {
-    		salc.start();
-    	}
+        File rootDir = new File(assembly.getRootDir());
+        ServiceAssemblyEnvironment env = new ServiceAssemblyEnvironment();
+        env.setRootDir(rootDir);
+        env.setInstallDir(new File(rootDir, "install"));
+        env.setSusDir(new File(rootDir, "sus"));
+        env.setStateFile(new File(rootDir, "state.xml"));
+        ServiceAssemblyLifeCycle salc = container.getRegistry().registerServiceAssembly(assembly.getDescriptor().getServiceAssembly(),
env);
+        if (env.getStateFile().isFile()) {
+            salc.restore();
+        } else {
+            salc.start();
+        }
     }
     
     public void unregister(ServiceAssembly assembly) throws Exception {
-    	ServiceAssemblyLifeCycle salc = container.getRegistry().getServiceAssembly(assembly.getName());
-    	salc.shutDown(false);
-    	container.getRegistry().unregisterServiceAssembly(assembly.getName());
+        ServiceAssemblyLifeCycle salc = container.getRegistry().getServiceAssembly(assembly.getName());
+        salc.shutDown(false);
+        assembly.undeploySus();
+        container.getRegistry().unregisterServiceAssembly(assembly.getName());
     }
 
 }



Mime
View raw message