use of org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion in project aries by apache.
the class ApplicationRepositoryTest method testBundleNotInApp.
@Test
public void testBundleNotInApp() {
AriesApplication app = Skeleton.newMock(AriesApplication.class);
BundleInfo bi = Skeleton.newMock(BundleInfo.class);
Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getSymbolicName"), "test.bundle");
Skeleton.getSkeleton(bi).setReturnValue(new MethodCall(BundleInfo.class, "getVersion"), new Version("1.0.0"));
Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getBundleInfo"), new HashSet<BundleInfo>());
ApplicationRepository rep = new ApplicationRepository(app);
BundleSuggestion sug = rep.suggestBundleToUse(new DeploymentContentImpl("test.bundle", new Version("2.0.0")));
assertNull("We have apparently found a bundle that is not in the application in the ApplicationRepository", sug);
}
use of org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion 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.repository.BundleRepository.BundleSuggestion in project aries by apache.
the class BundleRepositoryManagerImpl method getBundleSuggestions.
public Map<DeploymentContent, BundleSuggestion> getBundleSuggestions(Collection<BundleRepository> providers, Collection<DeploymentContent> content) throws ContextException {
LOGGER.debug(LOG_ENTRY, "getBundleSuggestions", new Object[] { content, providers });
Map<DeploymentContent, BundleSuggestion> urlToBeInstalled = new HashMap<DeploymentContent, BundleSuggestion>();
Iterator<DeploymentContent> it = content.iterator();
while (it.hasNext()) {
DeploymentContent bundleToFind = it.next();
Map<Version, List<BundleSuggestion>> bundlesuggestions = new HashMap<Version, List<BundleSuggestion>>();
for (BundleRepository obj : providers) {
BundleSuggestion suggestion = obj.suggestBundleToUse(bundleToFind);
if (suggestion != null) {
List<BundleSuggestion> suggestions = bundlesuggestions.get(suggestion.getVersion());
if (suggestions == null) {
suggestions = new ArrayList<BundleSuggestion>();
bundlesuggestions.put(suggestion.getVersion(), suggestions);
}
suggestions.add(suggestion);
}
}
BundleSuggestion suggestion = null;
if (!!!bundlesuggestions.isEmpty()) {
List<BundleSuggestion> thoughts = bundlesuggestions.get(bundleToFind.getExactVersion());
if (thoughts != null) {
Collections.sort(thoughts, new Comparator<BundleSuggestion>() {
public int compare(BundleSuggestion o1, BundleSuggestion o2) {
return o1.getCost() - o2.getCost();
}
});
suggestion = thoughts.get(0);
}
}
// add the suggestion to the list
if (suggestion != null) {
urlToBeInstalled.put(bundleToFind, suggestion);
} else {
throw new ContextException("Unable to find bundle " + bundleToFind.getContentName() + "/" + bundleToFind.getExactVersion());
}
}
LOGGER.debug(LOG_EXIT, "getBundleSuggestions", new Object[] { urlToBeInstalled });
return urlToBeInstalled;
}
use of org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion 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;
}
use of org.apache.aries.application.management.spi.repository.BundleRepository.BundleSuggestion in project aries by apache.
the class ApplicationContextImpl method installBundles.
/**
* This method finds bundles matching the list of content passed in
* @param bundlesToFind bundles to find and start if the bundle is shared. If isolated, install it.
* @param shared whether the bundles will be shared or isolated
* @return the result of execution
*/
private void installBundles(List<DeploymentContent> bundlesToFind, boolean shared) throws BundleException {
LOGGER.debug(LOG_ENTRY, "install", new Object[] { bundlesToFind, Boolean.valueOf(shared) });
if (!bundlesToFind.isEmpty() || !shared) {
Iterator<DeploymentContent> it = bundlesToFind.iterator();
/**
* Dont install any bundles from the list which are already
* installed
*/
Bundle[] sharedBundles = _bundleFrameworkManager.getSharedBundleFramework().getIsolatedBundleContext().getBundles();
if (shared) {
if (sharedBundles.length > 0) {
while (it.hasNext()) {
DeploymentContent bundleToFind = it.next();
for (Bundle b : sharedBundles) {
if (bundleToFind.getContentName().equals(b.getSymbolicName()) && bundleToFind.getExactVersion().equals(b.getVersion())) {
it.remove();
_bundles.add(b);
break;
}
}
}
}
}
/**
* Ask the repository manager to find us a list of suggested bundles
* to install based on our content list
*/
Map<DeploymentContent, BundleSuggestion> bundlesToBeInstalled = findBundleSuggestions(bundlesToFind);
/**
* Perform the install of the bundles
*/
try {
if (shared)
_bundles.addAll(_bundleFrameworkManager.installSharedBundles(new ArrayList<BundleSuggestion>(bundlesToBeInstalled.values()), makeAppProxy()));
else
_bundles.add(_bundleFrameworkManager.installIsolatedBundles(new ArrayList<BundleSuggestion>(bundlesToBeInstalled.values()), makeAppProxy()));
} catch (BundleException e) {
LOGGER.debug(LOG_EXCEPTION, e);
throw e;
}
}
LOGGER.debug(LOG_EXIT, "install");
}
Aggregations