use of org.apache.aries.application.management.UpdateException in project aries by apache.
the class ApplicationContextImpl method update.
public synchronized void update(final DeploymentMetadata newMetadata, final DeploymentMetadata oldMetadata) throws UpdateException {
final boolean toStart = getApplicationState() == ApplicationState.ACTIVE;
if (_bundleFrameworkManager.allowsUpdate(newMetadata, oldMetadata)) {
_bundleFrameworkManager.updateBundles(newMetadata, oldMetadata, _application, new BundleFrameworkManager.BundleLocator() {
public Map<DeploymentContent, BundleSuggestion> suggestBundle(Collection<DeploymentContent> bundles) throws BundleException {
return findBundleSuggestions(bundles);
}
}, _bundles, toStart);
} else {
// fallback do a uninstall, followed by a reinstall
try {
uninstall();
_deploymentMF = newMetadata;
try {
install();
if (toStart)
start();
} catch (BundleException e) {
try {
uninstall();
_deploymentMF = oldMetadata;
install();
if (toStart)
start();
throw new UpdateException("Could not install updated application", e, true, null);
} catch (BundleException e2) {
throw new UpdateException("Could not install updated application", e, false, e2);
}
}
} catch (BundleException e) {
try {
_deploymentMF = oldMetadata;
install();
if (toStart)
start();
throw new UpdateException("Could not install updated application", e, true, null);
} catch (BundleException e2) {
throw new UpdateException("Could not install updated application", e, false, e2);
}
}
}
}
use of org.apache.aries.application.management.UpdateException 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.management.UpdateException 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.management.UpdateException in project aries by apache.
the class AriesApplicationManagerImplTest method testFailedUpdate.
@Test
public void testFailedUpdate() throws Exception {
AriesApplication app = createApplication(TEST_EBA);
DeploymentMetadata depMf = createUpdateDepMf();
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, false, null));
_appMgr.setApplicationContextManager(ctxMgr);
try {
_appMgr.update(app, depMf);
fail("Update should have failed.");
} catch (UpdateException e) {
assertTrue("Deployment.mf should have been updated", app.getDeploymentMetadata() == depMf);
}
}
use of org.apache.aries.application.management.UpdateException in project aries by apache.
the class ApplicationContextManagerImpl method update.
public AriesApplicationContext update(AriesApplication app, DeploymentMetadata oldMetadata) throws UpdateException {
ApplicationContextImpl oldCtx = _appToContextMap.get(app);
if (oldCtx == null) {
throw new IllegalArgumentException("AriesApplication " + app.getApplicationMetadata().getApplicationSymbolicName() + "/" + app.getApplicationMetadata().getApplicationVersion() + " cannot be updated because it is not installed");
}
uninstall(oldCtx);
try {
AriesApplicationContext newCtx = getApplicationContext(app);
if (oldCtx.getApplicationState() == ApplicationState.ACTIVE) {
newCtx.start();
}
return newCtx;
} catch (BundleException e) {
throw new UpdateException("Update failed: " + e.getMessage(), e, false, null);
} catch (ManagementException e) {
throw new UpdateException("Update failed: " + e.getMessage(), e, false, null);
}
}
Aggregations