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]);
}
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;
}
});
}
}
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");
}
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"));
}
}
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;
}
Aggregations