Search in sources :

Example 6 with DeploymentMetadata

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;
            }
        });
    }
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) Bundle(org.osgi.framework.Bundle) UpdateStrategy(org.apache.aries.application.management.spi.update.UpdateStrategy) AriesApplication(org.apache.aries.application.management.AriesApplication) BundleFramework(org.apache.aries.application.management.spi.framework.BundleFramework) BundleException(org.osgi.framework.BundleException) HashMap(java.util.HashMap) Map(java.util.Map) DeploymentContent(org.apache.aries.application.DeploymentContent)

Example 7 with DeploymentMetadata

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

Example 8 with DeploymentMetadata

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

Example 9 with DeploymentMetadata

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);
    }
}
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 10 with DeploymentMetadata

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;
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) Version(org.osgi.framework.Version) MethodCall(org.apache.aries.unittest.mocks.MethodCall)

Aggregations

DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)15 AriesApplication (org.apache.aries.application.management.AriesApplication)11 Test (org.junit.Test)10 DeploymentContent (org.apache.aries.application.DeploymentContent)6 AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)6 Content (org.apache.aries.application.Content)4 AriesApplicationContextManager (org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager)4 MethodCall (org.apache.aries.unittest.mocks.MethodCall)4 Version (org.osgi.framework.Version)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)3 UpdateException (org.apache.aries.application.management.UpdateException)3 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)3 Bundle (org.osgi.framework.Bundle)3 ContentImpl (org.apache.aries.application.impl.ContentImpl)2 DeploymentContentImpl (org.apache.aries.application.impl.DeploymentContentImpl)2 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)2 BundleInfo (org.apache.aries.application.management.BundleInfo)2