use of org.apache.aries.application.management.spi.framework.BundleFramework 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.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.
the class BundleFrameworkManagerImpl method installIsolatedBundles.
public Bundle installIsolatedBundles(Collection<BundleSuggestion> bundlesToInstall, AriesApplication app) throws BundleException {
Bundle frameworkBundle = null;
synchronized (BundleFrameworkManager.SHARED_FRAMEWORK_LOCK) {
// We need to create a new isolated framework for this content and install
// the bundles to it
BundleFramework isolatedFramework = isolatedInstall(bundlesToInstall, _sharedBundleFramework.getIsolatedBundleContext(), app);
_frameworks.put(isolatedFramework.getFrameworkBundle(), isolatedFramework);
_frameworksByAppScope.put(app.getApplicationMetadata().getApplicationScope(), isolatedFramework);
frameworkBundle = isolatedFramework.getFrameworkBundle();
}
return frameworkBundle;
}
use of org.apache.aries.application.management.spi.framework.BundleFramework 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.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.
the class IsolationTestUtils method prepareSampleBundleV2.
/**
* Set up the necessary resources for installing version 2 of the org.apache.aries.isolated.sample sample bundle,
* which returns the message "hello brave new world" rather than "hello world"
*
* This means setting up a global bundle repository as well as a global OBR repository
*/
public static void prepareSampleBundleV2(BundleContext runtimeCtx, RepositoryGenerator repoGen, RepositoryAdmin repoAdmin, ModellingManager modellingManager) throws Exception {
BundleRepository repo = new BundleRepository() {
public int getCost() {
return 1;
}
public BundleSuggestion suggestBundleToUse(DeploymentContent content) {
if (content.getContentName().equals("org.apache.aries.isolated.sample")) {
return new BundleSuggestion() {
public Bundle install(BundleFramework framework, AriesApplication app) throws BundleException {
File f = new File("sample_2.0.0.jar");
try {
return framework.getIsolatedBundleContext().installBundle(f.toURL().toString());
} catch (MalformedURLException mue) {
throw new RuntimeException(mue);
}
}
public Version getVersion() {
return new Version("2.0.0");
}
public Set<Content> getImportPackage() {
return Collections.emptySet();
}
public Set<Content> getExportPackage() {
return Collections.emptySet();
}
public int getCost() {
return 1;
}
};
} else {
return null;
}
}
};
Hashtable<String, String> props = new Hashtable<String, String>();
props.put(BundleRepository.REPOSITORY_SCOPE, BundleRepository.GLOBAL_SCOPE);
runtimeCtx.registerService(BundleRepository.class.getName(), repo, props);
Attributes attrs = new Attributes();
attrs.putValue("Bundle-ManifestVersion", "2");
attrs.putValue("Bundle-Version", "2.0.0");
attrs.putValue("Bundle-SymbolicName", "org.apache.aries.isolated.sample");
attrs.putValue("Manifest-Version", "1");
ModelledResource res = modellingManager.getModelledResource(new File("sample_2.0.0.jar").toURI().toString(), attrs, Collections.EMPTY_LIST, Collections.EMPTY_LIST);
repoGen.generateRepository("repo.xml", Arrays.asList(res), new FileOutputStream("repo.xml"));
repoAdmin.addRepository(new File("repo.xml").toURI().toString());
}
use of org.apache.aries.application.management.spi.framework.BundleFramework in project aries by apache.
the class BundleFrameworkManagerImpl method isolatedInstall.
private BundleFramework isolatedInstall(Collection<BundleSuggestion> bundlesToBeInstalled, BundleContext parentCtx, AriesApplication app) throws BundleException {
LOGGER.debug(LOG_ENTRY, "isolatedInstall", new Object[] { bundlesToBeInstalled, app });
/**
* Build the configuration information for this application framework
*/
BundleFrameworkConfiguration config = _bundleFrameworkConfigurationFactory.createBundleFrameworkConfig(app.getApplicationMetadata().getApplicationScope(), parentCtx, app);
/**
* Install and start the new isolated bundle framework
*/
BundleFramework bundleFramework = _bundleFrameworkFactory.createBundleFramework(parentCtx, config);
// We should now have a bundleFramework
if (bundleFramework != null) {
try {
bundleFramework.init();
/**
* Install the bundles into the new framework
*/
BundleContext frameworkBundleContext = bundleFramework.getIsolatedBundleContext();
if (frameworkBundleContext != null) {
for (BundleSuggestion suggestion : bundlesToBeInstalled) bundleFramework.install(suggestion, app);
}
} catch (BundleException be) {
bundleFramework.close();
throw be;
} catch (RuntimeException re) {
bundleFramework.close();
throw re;
}
}
LOGGER.debug(LOG_EXIT, "isolatedInstall", bundleFramework);
return bundleFramework;
}
Aggregations