You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2009/03/09 18:18:52 UTC

svn commit: r751770 - in /servicemix/smx4/nmr/trunk/jbi: deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ itests/src/test/java/org/apache/servicemix/jbi/itests/

Author: gnodet
Date: Mon Mar  9 17:18:52 2009
New Revision: 751770

URL: http://svn.apache.org/viewvc?rev=751770&view=rev
Log:
Make sure SA is correctly undeployed before redeployment when the bundle is updated for example

Modified:
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java
    servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java
    servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java?rev=751770&r1=751769&r2=751770&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/AbstractInstaller.java Mon Mar  9 17:18:52 2009
@@ -59,6 +59,7 @@
     protected File jbiArtifact;
     protected File installRoot;
     protected boolean uninstallFromOsgi;
+    protected boolean isFirstInstall;
     protected boolean isModified;
 
     protected AbstractInstaller(Deployer deployer, Descriptor descriptor, File jbiArtifact, boolean autoStart) {
@@ -85,6 +86,7 @@
     public void init() throws Exception {
         Preferences prefs = getPreferences();
         long lastInstall = prefs.getLong(LAST_INSTALL, 0);
+        isFirstInstall = lastInstall == 0; 
         isModified = lastInstall == 0 || getBundle().getLastModified() > lastInstall;
         if (isModified) {
             extractBundle(installRoot, getBundle(), "/");

Modified: servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java?rev=751770&r1=751769&r2=751770&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/deployer/src/main/java/org/apache/servicemix/jbi/deployer/impl/ServiceAssemblyInstaller.java Mon Mar  9 17:18:52 2009
@@ -27,10 +27,9 @@
 
 import org.apache.servicemix.jbi.deployer.Component;
 import org.apache.servicemix.jbi.deployer.ServiceAssembly;
-import org.apache.servicemix.jbi.deployer.ServiceUnit;
 import org.apache.servicemix.jbi.deployer.artifacts.ComponentImpl;
-import org.apache.servicemix.jbi.deployer.artifacts.ServiceUnitImpl;
 import org.apache.servicemix.jbi.deployer.artifacts.ServiceAssemblyImpl;
+import org.apache.servicemix.jbi.deployer.artifacts.ServiceUnitImpl;
 import org.apache.servicemix.jbi.deployer.descriptor.Descriptor;
 import org.apache.servicemix.jbi.deployer.descriptor.ServiceUnitDesc;
 import org.apache.servicemix.jbi.deployer.utils.FileUtil;
@@ -94,6 +93,9 @@
             if (LifeCycleMBean.STOPPED.equals(assembly.getCurrentState())) {
                 assembly.shutDown(false, force);
             }
+            for (ServiceUnitImpl su : assembly.getServiceUnitsList()) {
+                su.getComponentImpl().removeServiceUnit(su);
+            }
         }
     }
 
@@ -126,6 +128,22 @@
     protected List<ServiceUnitImpl> deploySUs() throws Exception {
         // Create the SA directory
         File saDir = new File(installRoot.getParent(), "sus");
+        // Quickly undeploy the SA if it has changed
+        if (isModified && !isFirstInstall) {
+            for (ServiceUnitDesc sud : descriptor.getServiceAssembly().getServiceUnits()) {
+                File suRootDir = new File(saDir, sud.getIdentification().getName());
+                String componentName = sud.getTarget().getComponentName();
+                ComponentImpl component = deployer.getComponent(componentName);
+                ServiceUnitImpl su = deployer.createServiceUnit(sud, suRootDir, component);
+                try {
+                    su.undeploy();
+                } catch (Exception e) {
+                    LOGGER.warn("Problem undeploying SU " + su.getName());
+                }
+            }
+        }
+
+        // Wipe out the SA dir
         if (isModified) {
             FileUtil.deleteFile(saDir);
             FileUtil.buildDirectory(saDir);

Modified: servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java
URL: http://svn.apache.org/viewvc/servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java?rev=751770&r1=751769&r2=751770&view=diff
==============================================================================
--- servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java (original)
+++ servicemix/smx4/nmr/trunk/jbi/itests/src/test/java/org/apache/servicemix/jbi/itests/IntegrationTest.java Mon Mar  9 17:18:52 2009
@@ -17,22 +17,20 @@
 package org.apache.servicemix.jbi.itests;
 
 import java.io.File;
-import java.util.Properties;
+import java.net.URL;
+import java.net.URLConnection;
 import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
-import java.util.concurrent.CopyOnWriteArrayList;
-import java.net.URL;
-import java.net.URLConnection;
-import java.net.HttpURLConnection;
 
 import javax.jbi.component.Component;
 import javax.jbi.management.LifeCycleMBean;
 
-import org.apache.servicemix.nmr.api.NMR;
-import org.apache.servicemix.kernel.testing.support.AbstractIntegrationTest;
 import org.apache.servicemix.jbi.deployer.ServiceAssembly;
 import org.apache.servicemix.jbi.deployer.handler.JBIDeploymentListener;
+import org.apache.servicemix.kernel.testing.support.AbstractIntegrationTest;
+import org.apache.servicemix.nmr.api.NMR;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 
@@ -187,6 +185,11 @@
         assertNotNull(sa);
         assertEquals(LifeCycleMBean.STARTED, sa.getCurrentState());
 
+        saBundle.update();
+        sa = getOsgiService(ServiceAssembly.class);
+        assertNotNull(sa);
+        assertEquals(LifeCycleMBean.STARTED, sa.getCurrentState());
+
         smxHttp.stop();
         try {
             getOsgiService(ServiceAssembly.class, 1);