use of org.apache.aries.application.DeploymentMetadata 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.DeploymentMetadata in project aries by apache.
the class AriesApplicationManagerImpl method update.
public AriesApplicationContext update(AriesApplication app, DeploymentMetadata depMf) throws UpdateException {
if (!(app instanceof AriesApplicationImpl))
throw new IllegalArgumentException("Argument is not AriesApplication created by this manager");
if (!!!app.getApplicationMetadata().getApplicationSymbolicName().equals(depMf.getApplicationSymbolicName()) || !!!app.getApplicationMetadata().getApplicationVersion().equals(depMf.getApplicationVersion())) {
throw new IllegalArgumentException("The deployment metadata does not match the application.");
}
DeploymentMetadata oldMetadata = app.getDeploymentMetadata();
AriesApplicationContext foundCtx = null;
for (AriesApplicationContext ctx : _applicationContextManager.getApplicationContexts()) {
if (ctx.getApplication().equals(app)) {
foundCtx = ctx;
break;
}
}
((AriesApplicationImpl) app).setDeploymentMetadata(depMf);
if (foundCtx != null) {
try {
return _applicationContextManager.update(app, oldMetadata);
} catch (UpdateException ue) {
if (ue.hasRolledBack()) {
((AriesApplicationImpl) app).setDeploymentMetadata(oldMetadata);
}
throw ue;
}
} else {
return null;
}
}
use of org.apache.aries.application.DeploymentMetadata in project aries by apache.
the class AriesApplicationManagerImplTest method testUpdate.
@Test
public void testUpdate() throws Exception {
AriesApplication app = createApplication(TEST_EBA);
DeploymentMetadata depMf = createUpdateDepMf();
AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
_appMgr.setApplicationContextManager(ctxMgr);
_appMgr.update(app, depMf);
assertTrue("Deployment.mf should have been updated", app.getDeploymentMetadata() == depMf);
}
use of org.apache.aries.application.DeploymentMetadata in project aries by apache.
the class AriesApplicationManagerImplTest method testRolledbackUpdate.
@Test
public void testRolledbackUpdate() throws Exception {
AriesApplication app = createApplication(TEST_EBA);
DeploymentMetadata depMf = createUpdateDepMf();
DeploymentMetadata oldMf = app.getDeploymentMetadata();
AriesApplicationContext ctx = Skeleton.newMock(AriesApplicationContext.class);
Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(AriesApplicationContext.class, "getApplication"), app);
AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
Skeleton.getSkeleton(ctxMgr).setReturnValue(new MethodCall(AriesApplicationContextManager.class, "getApplicationContexts"), Collections.singleton(ctx));
Skeleton.getSkeleton(ctxMgr).setThrows(new MethodCall(AriesApplicationContextManager.class, "update", AriesApplication.class, DeploymentMetadata.class), new UpdateException("", null, true, null));
_appMgr.setApplicationContextManager(ctxMgr);
try {
_appMgr.update(app, depMf);
fail("Update should have failed.");
} catch (UpdateException e) {
assertTrue("Deployment.mf should have been rolled back to the old", app.getDeploymentMetadata() == oldMf);
}
}
use of org.apache.aries.application.DeploymentMetadata in project aries by apache.
the class AriesApplicationManagerImplTest method createUpdateDepMf.
private DeploymentMetadata createUpdateDepMf() {
DeploymentMetadata depMf = Skeleton.newMock(DeploymentMetadata.class);
Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationSymbolicName"), "org.apache.aries.application.management.test");
Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationVersion"), new Version("1.0.0"));
return depMf;
}
Aggregations