Search in sources :

Example 1 with UpdateException

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);
            }
        }
    }
}
Also used : BundleFrameworkManager(org.apache.aries.application.management.spi.framework.BundleFrameworkManager) BundleException(org.osgi.framework.BundleException) UpdateException(org.apache.aries.application.management.UpdateException) Map(java.util.Map) DeploymentContent(org.apache.aries.application.DeploymentContent)

Example 2 with UpdateException

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;
    }
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) UpdateException(org.apache.aries.application.management.UpdateException)

Example 3 with UpdateException

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);
    }
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) AriesApplicationContextManager(org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplication(org.apache.aries.application.management.AriesApplication) UpdateException(org.apache.aries.application.management.UpdateException) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Test(org.junit.Test)

Example 4 with UpdateException

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);
    }
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) AriesApplicationContextManager(org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplication(org.apache.aries.application.management.AriesApplication) UpdateException(org.apache.aries.application.management.UpdateException) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Test(org.junit.Test)

Example 5 with UpdateException

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);
    }
}
Also used : ManagementException(org.apache.aries.application.management.ManagementException) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) BundleException(org.osgi.framework.BundleException) UpdateException(org.apache.aries.application.management.UpdateException)

Aggregations

UpdateException (org.apache.aries.application.management.UpdateException)5 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)4 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)3 AriesApplication (org.apache.aries.application.management.AriesApplication)2 AriesApplicationContextManager (org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager)2 MethodCall (org.apache.aries.unittest.mocks.MethodCall)2 Test (org.junit.Test)2 BundleException (org.osgi.framework.BundleException)2 Map (java.util.Map)1 DeploymentContent (org.apache.aries.application.DeploymentContent)1 ManagementException (org.apache.aries.application.management.ManagementException)1 BundleFrameworkManager (org.apache.aries.application.management.spi.framework.BundleFrameworkManager)1