Author: jwross
Date: Wed Oct 17 00:13:08 2012
New Revision: 1399053

URL: http://svn.apache.org/viewvc?rev=1399053&view=rev
Log:
Set start level of managed bundles to 1.

The start level of all managed bundles is now explicitly set to 1. A managed 
bundle is a bundle installed by the subsystems implementation. This includes 
both content and dependencies. Setting the start level to 1 avoids start 
failures when the framework's initial bundle start level is set to a higher 
value than the start level under which a subsystem is being started. For 
example, a management agent starting at level 2 might call 
FrameworkStartLevel.setInitialBundleStartLevel(5) then proceed to install and 
start a subsystem. If the bundles installed as part of the subsystem 
installation inherited the initial level of 5, the subsystem would fail to 
start since all bundles (except for the region context bundle) are started 
transiently.

A new test was also added.

Modified:
    
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java
    
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
    
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
    
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
    
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
    
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java

Modified: 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java?rev=1399053&r1=1399052&r2=1399053&view=diff
==============================================================================
--- 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java
 (original)
+++ 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/BundleResourceInstaller.java
 Wed Oct 17 00:13:08 2012
@@ -22,6 +22,7 @@ import org.apache.aries.util.io.IOUtils;
 import org.osgi.framework.Bundle;
 import org.osgi.framework.BundleException;
 import org.osgi.framework.Version;
+import org.osgi.framework.startlevel.BundleStartLevel;
 import org.osgi.framework.wiring.BundleCapability;
 import org.osgi.framework.wiring.BundleRequirement;
 import org.osgi.framework.wiring.BundleRevision;
@@ -186,6 +187,13 @@ public class BundleResourceInstaller ext
                                provisionTo.getRegion().removeBundle(bundle);
                        }
                });
+               // Set the start level of all bundles managed (i.e. installed) 
by the
+               // subsystems implementation to 1 in case the framework's 
default bundle
+               // start level has been changed. Otherwise, start failures will 
occur
+               // if a subsystem is started at a lower start level than the 
default.
+               // Setting the start level does no harm since all managed 
bundles are 
+               // started transiently anyway.
+               bundle.adapt(BundleStartLevel.class).setStartLevel(1);
                return bundle.adapt(BundleRevision.class);
        }
 }

Modified: 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java?rev=1399053&r1=1399052&r2=1399053&view=diff
==============================================================================
--- 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
 (original)
+++ 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StartAction.java
 Wed Oct 17 00:13:08 2012
@@ -240,6 +240,9 @@ public class StartAction extends Abstrac
                        // Starting the root subsystem should not affect 
bundles within the
                        // root region.
                        return;
+               if (Utils.isRegionContextBundle(resource))
+                       // The region context bundle was persistently started 
elsewhere.
+                       return;
                final Bundle bundle = ((BundleRevision)resource).getBundle();
                if ((bundle.getState() & (Bundle.STARTING | Bundle.ACTIVE)) != 
0)
                        return;

Modified: 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java?rev=1399053&r1=1399052&r2=1399053&view=diff
==============================================================================
--- 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
 (original)
+++ 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/StopAction.java
 Wed Oct 17 00:13:08 2012
@@ -59,7 +59,7 @@ public class StopAction extends Abstract
                }
                for (Resource resource : resources) {
                        // Don't stop the region context bundle.
-                       if 
(ResourceHelper.getSymbolicNameAttribute(resource).startsWith(RegionContextBundleHelper.SYMBOLICNAME_PREFIX))
+                       if (Utils.isRegionContextBundle(resource))
                                continue;
                        try {
                                stopResource(resource);

Modified: 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java?rev=1399053&r1=1399052&r2=1399053&view=diff
==============================================================================
--- 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
 (original)
+++ 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/SubsystemResourceUninstaller.java
 Wed Oct 17 00:13:08 2012
@@ -86,8 +86,7 @@ public class SubsystemResourceUninstalle
                        for (Resource resource : 
Activator.getInstance().getSubsystems()
                                        .getResourcesReferencedBy(subsystem)) {
                                // Don't uninstall the region context bundle 
here.
-                               if 
(ResourceHelper.getSymbolicNameAttribute(resource).startsWith(
-                                               
RegionContextBundleHelper.SYMBOLICNAME_PREFIX))
+                               if (Utils.isRegionContextBundle(resource))
                                        continue;
                                try {
                                        
ResourceUninstaller.newInstance(resource, subsystem)

Modified: 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java?rev=1399053&r1=1399052&r2=1399053&view=diff
==============================================================================
--- 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
 (original)
+++ 
aries/trunk/subsystem/subsystem-core/src/main/java/org/apache/aries/subsystem/core/internal/Utils.java
 Wed Oct 17 00:13:08 2012
@@ -127,6 +127,11 @@ public class Utils {
                return !isSharedResource(resource);
        }
        
+       public static boolean isRegionContextBundle(Resource resource) {
+               return 
ResourceHelper.getSymbolicNameAttribute(resource).startsWith(
+                               RegionContextBundleHelper.SYMBOLICNAME_PREFIX);
+       }
+       
        public static boolean isSharedResource(Resource resource) {
                return resource instanceof AriesSubsystem || resource 
instanceof BundleRevision;
        }

Modified: 
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java
URL: 
http://svn.apache.org/viewvc/aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java?rev=1399053&r1=1399052&r2=1399053&view=diff
==============================================================================
--- 
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java
 (original)
+++ 
aries/trunk/subsystem/subsystem-itests/src/test/java/org/apache/aries/subsystem/itests/InstallTest.java
 Wed Oct 17 00:13:08 2012
@@ -18,6 +18,7 @@
  */
 package org.apache.aries.subsystem.itests;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.fail;
 
@@ -30,6 +31,9 @@ import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.ops4j.pax.exam.junit.MavenConfiguredJUnit4TestRunner;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.startlevel.BundleStartLevel;
+import org.osgi.framework.startlevel.FrameworkStartLevel;
 import org.osgi.service.subsystem.Subsystem;
 
 @RunWith(MavenConfiguredJUnit4TestRunner.class)
@@ -41,6 +45,7 @@ public class InstallTest extends Subsyst
                }
                createApplication("emptySubsystem", new String[0]);
                createApplication("feature3", new String[]{"tb3.jar"});
+               createApplication("feature2", new String[]{"tb3.jar", 
"tb2.jar"});
                createdApplications = true;
        }
        
@@ -87,4 +92,30 @@ public class InstallTest extends Subsyst
                fail("Subsystem installation using directory URL as location 
failed");
        }
     }
+    
+    @Test
+    public void testManagedBundleStartLevel() throws Exception {
+       
bundleContext.getBundle(0).adapt(FrameworkStartLevel.class).setInitialBundleStartLevel(5);
+       Bundle tb1 = bundleContext.installBundle("tb1.jar", 
SubsystemTest.class.getClassLoader().getResourceAsStream("feature1/tb1.jar"));
+       try {
+               Subsystem feature2 = installSubsystemFromFile("feature2.esa");
+               try {
+                       startSubsystem(feature2);
+                       try {
+                               assertEquals("Wrong start level for unmanaged 
bundle", 5, tb1.adapt(BundleStartLevel.class).getStartLevel());
+                               assertEquals("Wrong start level for managed 
bundle", 1, getBundle(feature2, 
"org.apache.aries.subsystem.itests.tb2").adapt(BundleStartLevel.class).getStartLevel());
+                               assertEquals("Wrong start level for managed 
bundle", 1, getBundle(feature2, 
"org.apache.aries.subsystem.itests.tb3").adapt(BundleStartLevel.class).getStartLevel());
+                       }
+                       finally {
+                               stopSubsystemSilently(feature2);
+                       }
+               }
+               finally {
+                       uninstallSubsystemSilently(feature2);
+               }
+       }
+       finally {
+               uninstallSilently(tb1);
+       }
+    }
 }


Reply via email to