Search in sources :

Example 21 with BundleException

use of org.osgi.framework.BundleException in project aries by apache.

the class FrameworkTest method testUpdateBundles.

@Test
public void testUpdateBundles() throws Exception {
    Bundle bundle = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundle(5)).thenReturn(bundle);
    CompositeData data = mbean.updateBundles(new long[] { 5 });
    Mockito.verify(bundle).update();
    BatchActionResult batch = BatchActionResult.from(data);
    Assert.assertEquals(5, batch.getCompleted()[0]);
    Assert.assertTrue(batch.isSuccess());
    Assert.assertNull(batch.getError());
    Assert.assertNull(batch.getRemainingItems());
    CompositeData data2 = mbean.updateBundles(null);
    BatchActionResult batch2 = BatchActionResult.from(data2);
    Assert.assertNull(batch2.getCompleted());
    Assert.assertFalse(batch2.isSuccess());
    Assert.assertNotNull(batch2.getError());
    Assert.assertNull(batch2.getRemainingItems());
    Mockito.reset(bundle);
    CompositeData data3 = mbean.updateBundles(new long[] { 6 });
    Mockito.when(context.getBundle(6)).thenReturn(bundle);
    Mockito.doThrow(new BundleException("")).when(bundle).update();
    BatchActionResult batch3 = BatchActionResult.from(data3);
    Assert.assertEquals(0, batch3.getCompleted().length);
    Assert.assertFalse(batch3.isSuccess());
    Assert.assertNotNull(batch3.getError());
    Assert.assertEquals(6, batch3.getBundleInError());
    Bundle bundle6 = Mockito.mock(Bundle.class);
    Bundle bundle8 = Mockito.mock(Bundle.class);
    Bundle bundle7 = Mockito.mock(Bundle.class);
    Mockito.when(context.getBundle(6)).thenReturn(bundle6);
    Mockito.when(context.getBundle(8)).thenReturn(bundle8);
    Mockito.when(context.getBundle(7)).thenReturn(bundle7);
    Mockito.doThrow(new BundleException("")).when(bundle8).update();
    CompositeData data4 = mbean.updateBundles(new long[] { 6, 8, 7 });
    BatchActionResult batch4 = BatchActionResult.from(data4);
    Mockito.verify(bundle6).update();
    Assert.assertEquals(1, batch4.getCompleted().length);
    // should contain only bundleid 6
    Assert.assertEquals(6, batch4.getCompleted()[0]);
    Assert.assertFalse(batch4.isSuccess());
    Assert.assertNotNull(batch4.getError());
    Assert.assertEquals(8, batch4.getBundleInError());
    Assert.assertEquals(1, batch4.getRemainingItems().length);
    // should contain only bundleid 7
    Assert.assertEquals(7, batch4.getRemainingItems()[0]);
}
Also used : Bundle(org.osgi.framework.Bundle) CompositeData(javax.management.openmbean.CompositeData) BundleException(org.osgi.framework.BundleException) BatchActionResult(org.apache.aries.jmx.codec.BatchActionResult) Test(org.junit.Test)

Example 22 with BundleException

use of org.osgi.framework.BundleException in project aries by apache.

the class BundleFrameworkManagerImpl method updateBundles.

public void updateBundles(final DeploymentMetadata newMetadata, final DeploymentMetadata oldMetadata, final AriesApplication app, final BundleLocator locator, final Set<Bundle> bundles, final boolean startBundles) throws UpdateException {
    UpdateStrategy strategy = null;
    for (UpdateStrategy us : _updateStrategies) {
        if (us.allowsUpdate(newMetadata, oldMetadata)) {
            strategy = us;
            break;
        }
    }
    if (strategy == null)
        throw new IllegalArgumentException("No UpdateStrategy supports the supplied DeploymentMetadata changes.");
    synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
        final BundleFramework appFwk = _frameworksByAppScope.get(app.getApplicationMetadata().getApplicationScope());
        strategy.update(new UpdateStrategy.UpdateInfo() {

            public void register(Bundle bundle) {
                bundles.add(bundle);
            }

            public void unregister(Bundle bundle) {
                bundles.remove(bundle);
            }

            public Map<DeploymentContent, BundleSuggestion> suggestBundle(Collection<DeploymentContent> bundles) throws BundleException {
                return locator.suggestBundle(bundles);
            }

            public boolean startBundles() {
                return startBundles;
            }

            public BundleFramework getSharedFramework() {
                return _sharedBundleFramework;
            }

            public DeploymentMetadata getOldMetadata() {
                return oldMetadata;
            }

            public DeploymentMetadata getNewMetadata() {
                return newMetadata;
            }

            public AriesApplication getApplication() {
                return app;
            }

            public BundleFramework getAppFramework() {
                return appFwk;
            }
        });
    }
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) Bundle(org.osgi.framework.Bundle) UpdateStrategy(org.apache.aries.application.management.spi.update.UpdateStrategy) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleException(org.osgi.framework.BundleException) HashMap(java.util.HashMap) Map(java.util.Map) DeploymentContent(org.apache.aries.application.DeploymentContent)

Example 23 with BundleException

use of org.osgi.framework.BundleException in project aries by apache.

the class SharedBundleFramework method createSharedBundleFramework.

/**
   * create using any bundle context in EBA App framework as we want to create
   * a child framework under EBA App framework
   * 
   * @param bc
   * @throws BundleException
   * @throws InvalidSyntaxException
   */
private static void createSharedBundleFramework(BundleContext bc, BundleFrameworkConfigurationFactory bundleFrameworkConfigFactory, BundleFrameworkFactory bundleFrameworkFactory) throws ContextException {
    LOGGER.debug(LOG_ENTRY, "createSharedBundleFramework", new Object[] { bc, bundleFrameworkFactory });
    try {
        BundleFrameworkConfiguration config = new SharedBundleFrameworkConfiguration(bundleFrameworkConfigFactory.createBundleFrameworkConfig(BundleFramework.SHARED_BUNDLE_FRAMEWORK, bc));
        sharedFramework = bundleFrameworkFactory.createBundleFramework(bc, config);
        sharedFramework.start();
    } catch (BundleException e) {
        LOGGER.debug(LOG_EXIT, "createSharedBundleFramework", e);
        throw new ContextException("Unable to create or start the shared framework composite bundle " + sharedFramework, e);
    }
    LOGGER.debug(LOG_EXIT, "createSharedBundleFramework");
}
Also used : BundleException(org.osgi.framework.BundleException) ContextException(org.apache.aries.application.management.spi.repository.ContextException) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)

Example 24 with BundleException

use of org.osgi.framework.BundleException in project aries by apache.

the class BundleFrameworkManagerTest method testFailedInstall.

@Test
public void testFailedInstall() throws Exception {
    /*
     * Mock up a failing framework install
     */
    BundleFramework fwk = Skeleton.newMock(new Object() {

        public Bundle install(BundleSuggestion suggestion, AriesApplication app) throws BundleException {
            throw new BundleException("Expected failure");
        }
    }, BundleFramework.class);
    frameworkFactory.setReturnValue(new MethodCall(BundleFrameworkFactory.class, "createBundleFramework", BundleContext.class, BundleFrameworkConfiguration.class), fwk);
    try {
        sut.installIsolatedBundles(Arrays.asList(Skeleton.newMock(BundleSuggestion.class)), Skeleton.newMock(AriesApplication.class));
        fail("Expected a BundleException");
    } catch (BundleException be) {
        // when a failure occurred we need to have cleaned up the new framework, otherwise it is
        // left as floating debris
        Skeleton.getSkeleton(fwk).assertCalled(new MethodCall(BundleFramework.class, "close"));
    }
}
Also used : BundleFrameworkFactory(org.apache.aries.application.management.spi.framework.BundleFrameworkFactory) Bundle(org.osgi.framework.Bundle) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleSuggestion(org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion) BundleException(org.osgi.framework.BundleException) MethodCall(org.apache.aries.unittest.mocks.MethodCall) BundleContext(org.osgi.framework.BundleContext) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration) Test(org.junit.Test)

Example 25 with BundleException

use of org.osgi.framework.BundleException in project aries by apache.

the class ApplicationContextImpl method start.

public void start() throws BundleException {
    _state = ApplicationState.STARTING;
    List<Bundle> bundlesWeStarted = new ArrayList<Bundle>();
    try {
        for (Bundle b : _bundles.values()) {
            if (b.getState() != Bundle.ACTIVE) {
                b.start(Bundle.START_ACTIVATION_POLICY);
                bundlesWeStarted.add(b);
            }
        }
    } catch (BundleException be) {
        for (Bundle b : bundlesWeStarted) {
            try {
                b.stop();
            } catch (BundleException be2) {
            // we are doing tidyup here, so we don't want to replace the bundle exception
            // that occurred during start with one from stop. We also want to try to stop
            // all the bundles we started even if some bundles wouldn't stop.
            }
        }
        _state = ApplicationState.INSTALLED;
        throw be;
    }
    _state = ApplicationState.ACTIVE;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) BundleException(org.osgi.framework.BundleException)

Aggregations

BundleException (org.osgi.framework.BundleException)99 Bundle (org.osgi.framework.Bundle)54 IOException (java.io.IOException)31 Test (org.junit.Test)19 File (java.io.File)15 ArrayList (java.util.ArrayList)13 InputStream (java.io.InputStream)10 FileInputStream (java.io.FileInputStream)9 BundleContext (org.osgi.framework.BundleContext)9 HashMap (java.util.HashMap)8 Map (java.util.Map)7 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)7 Hashtable (java.util.Hashtable)5 Manifest (java.util.jar.Manifest)5 ServiceReference (org.osgi.framework.ServiceReference)5 Version (org.osgi.framework.Version)5 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)5 LowDiskException (android.taobao.atlas.runtime.LowDiskException)4 TimeoutException (java.util.concurrent.TimeoutException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4