You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@aries.apache.org by ma...@apache.org on 2010/12/31 09:34:09 UTC

svn commit: r1054061 - in /incubator/aries/trunk/application: application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/ application-runtime-framework-management/src/test/ application-runtime-frame...

Author: mahrwald
Date: Fri Dec 31 08:34:09 2010
New Revision: 1054061

URL: http://svn.apache.org/viewvc?rev=1054061&view=rev
Log:
ARIES-528: Fixes for rolling back bad updates

Added:
    incubator/aries/trunk/application/application-runtime-framework-management/src/test/
    incubator/aries/trunk/application/application-runtime-framework-management/src/test/java/
Modified:
    incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java
    incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java

Modified: incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java?rev=1054061&r1=1054060&r2=1054061&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java (original)
+++ incubator/aries/trunk/application/application-runtime-framework-management/src/main/java/org/apache/aries/application/runtime/framework/management/BundleFrameworkManagerImpl.java Fri Dec 31 08:34:09 2010
@@ -27,6 +27,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -58,7 +59,7 @@ public class BundleFrameworkManagerImpl 
   BundleFrameworkFactory _bundleFrameworkFactory;
   BundleFrameworkConfigurationFactory _bundleFrameworkConfigurationFactory;
   Map<Bundle, BundleFramework> _frameworks = new HashMap<Bundle, BundleFramework>();
-  Map<AriesApplication, BundleFramework> _frameworksByApp = new HashMap<AriesApplication, BundleFramework>();
+  Map<String, BundleFramework> _frameworksByAppScope = new HashMap<String, BundleFramework>();
   private List<UpdateStrategy> _updateStrategies = Collections.emptyList();
 
   public void setUpdateStrategies(List<UpdateStrategy> updateStrategies)
@@ -116,7 +117,7 @@ public class BundleFrameworkManagerImpl 
           .getIsolatedBundleContext(), app);
 
       _frameworks.put(isolatedFramework.getFrameworkBundle(), isolatedFramework);
-      _frameworksByApp.put(app, isolatedFramework);
+      _frameworksByAppScope.put(app.getApplicationMetadata().getApplicationScope(), isolatedFramework);
 
       frameworkBundle = isolatedFramework.getFrameworkBundle();
     }
@@ -172,16 +173,24 @@ public class BundleFrameworkManagerImpl 
        * Install the bundles into the new framework
        */
       
-      List<Bundle> installedBundles = new ArrayList<Bundle>();
-      BundleContext frameworkBundleContext = bundleFramework.getIsolatedBundleContext();
-      if (frameworkBundleContext != null) {
-        for (BundleSuggestion suggestion : bundlesToBeInstalled)
-          installedBundles.add(bundleFramework.install(suggestion, app));
+      try {
+        List<Bundle> installedBundles = new ArrayList<Bundle>();
+        BundleContext frameworkBundleContext = bundleFramework.getIsolatedBundleContext();
+        if (frameworkBundleContext != null) {
+          for (BundleSuggestion suggestion : bundlesToBeInstalled)
+            installedBundles.add(bundleFramework.install(suggestion, app));
+        }
+        
+        // Finally, start the whole lot
+        if (!frameworkStarted)
+          bundleFramework.start();
+      } catch (BundleException be) {
+        bundleFramework.close();
+        throw be;
+      } catch (RuntimeException re) {
+        bundleFramework.close();
+        throw re;
       }
-      
-      // Finally, start the whole lot
-      if (!frameworkStarted)
-        bundleFramework.start();
     }
 
     LOGGER.debug(LOG_EXIT, "isolatedInstall", bundleFramework);
@@ -200,7 +209,16 @@ public class BundleFrameworkManagerImpl 
   {
     synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
       BundleFramework framework = getBundleFramework(b);
-      if (framework != null) framework.close();
+      if (framework != null) {
+        framework.close();
+        
+        // clean up our maps so we don't leak memory
+        _frameworks.remove(b);
+        Iterator<BundleFramework> it = _frameworksByAppScope.values().iterator();
+        while (it.hasNext()) {
+          if (it.next().equals(framework)) it.remove();
+        }
+      }
     }
   }
 
@@ -260,7 +278,7 @@ public class BundleFrameworkManagerImpl 
           "No UpdateStrategy supports the supplied DeploymentMetadata changes.");
 
     synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
-      final BundleFramework appFwk = _frameworksByApp.get(app);
+      final BundleFramework appFwk = _frameworksByAppScope.get(app.getApplicationMetadata().getApplicationScope());
 
       strategy.update(new UpdateStrategy.UpdateInfo() {
 

Modified: incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java?rev=1054061&r1=1054060&r2=1054061&view=diff
==============================================================================
--- incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java (original)
+++ incubator/aries/trunk/application/application-runtime-isolated/src/main/java/org/apache/aries/application/runtime/isolated/impl/ApplicationContextImpl.java Fri Dec 31 08:34:09 2010
@@ -23,6 +23,10 @@ import static org.apache.aries.applicati
 import static org.apache.aries.application.utils.AppConstants.LOG_EXCEPTION;
 import static org.apache.aries.application.utils.AppConstants.LOG_EXIT;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -31,10 +35,12 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.aries.application.ApplicationMetadata;
 import org.apache.aries.application.DeploymentContent;
 import org.apache.aries.application.DeploymentMetadata;
 import org.apache.aries.application.management.AriesApplication;
 import org.apache.aries.application.management.AriesApplicationContext;
+import org.apache.aries.application.management.BundleInfo;
 import org.apache.aries.application.management.UpdateException;
 import org.apache.aries.application.management.spi.framework.BundleFrameworkManager;
 import org.apache.aries.application.management.spi.repository.BundleRepositoryManager;
@@ -49,11 +55,11 @@ public class ApplicationContextImpl impl
 {
   private static final Logger LOGGER = LoggerFactory.getLogger(ApplicationContextImpl.class);
 
-  private AriesApplication _application;
-  private Set<Bundle> _bundles;
+  private final AriesApplication _application;
+  private final Set<Bundle> _bundles;
   private ApplicationState _state = ApplicationState.UNINSTALLED;
-  private BundleRepositoryManager _bundleRepositoryManager;
-  private BundleFrameworkManager _bundleFrameworkManager;
+  private final BundleRepositoryManager _bundleRepositoryManager;
+  private final BundleFrameworkManager _bundleFrameworkManager;
 
   /** deployment metadata associated with aries application */
   private DeploymentMetadata _deploymentMF;
@@ -202,9 +208,9 @@ public class ApplicationContextImpl impl
        */
       try {
         if (shared) _bundles.addAll(_bundleFrameworkManager.installSharedBundles(
-            new ArrayList<BundleSuggestion>(bundlesToBeInstalled.values()), _application));
+            new ArrayList<BundleSuggestion>(bundlesToBeInstalled.values()), makeAppProxy()));
         else _bundles.add(_bundleFrameworkManager.installIsolatedBundles(
-            new ArrayList<BundleSuggestion>(bundlesToBeInstalled.values()), _application));
+            new ArrayList<BundleSuggestion>(bundlesToBeInstalled.values()), makeAppProxy()));
 
       } catch (BundleException e) {
         LOGGER.debug(LOG_EXCEPTION, e);
@@ -212,7 +218,38 @@ public class ApplicationContextImpl impl
       }
     }
     LOGGER.debug(LOG_EXIT, "install");
-
+  }
+  
+  /**
+   * Create a proxy for the AriesApplication we pass on so as to respect the correct current deployment metadata.
+   */
+  private AriesApplication makeAppProxy() {
+    return new AriesApplication() {
+      
+      public void store(OutputStream out) throws FileNotFoundException, IOException {
+        throw new UnsupportedOperationException();
+      }
+      
+      public void store(File f) throws FileNotFoundException, IOException {
+        throw new UnsupportedOperationException();
+      }
+      
+      public boolean isResolved() {
+        return true;
+      }
+      
+      public DeploymentMetadata getDeploymentMetadata() {
+        return _deploymentMF;
+      }
+      
+      public Set<BundleInfo> getBundleInfo() {
+        return _application.getBundleInfo();
+      }
+      
+      public ApplicationMetadata getApplicationMetadata() {
+        return _application.getApplicationMetadata();
+      }
+    };
   }
 
   private Map<DeploymentContent, BundleSuggestion> findBundleSuggestions(