Search in sources :

Example 26 with AriesApplicationContext

use of org.apache.aries.application.management.AriesApplicationContext 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 27 with AriesApplicationContext

use of org.apache.aries.application.management.AriesApplicationContext in project aries by apache.

the class IsolatedRuntimeTest method testUninstallReinstall.

@Test
@Ignore
public void testUninstallReinstall() throws Exception {
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba")));
    AriesApplicationContext ctx = manager.install(app);
    app = ctx.getApplication();
    ctx.start();
    assertHelloWorldService("org.apache.aries.sample2");
    ctx.stop();
    manager.uninstall(ctx);
    assertNull(IsolationTestUtils.findIsolatedAppBundleContext(bundleContext, "org.apache.aries.sample2"));
    ctx = manager.install(app);
    ctx.start();
    assertHelloWorldService("org.apache.aries.sample2");
    manager.uninstall(ctx);
}
Also used : AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) File(java.io.File) Ignore(org.junit.Ignore) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 28 with AriesApplicationContext

use of org.apache.aries.application.management.AriesApplicationContext in project aries by apache.

the class MinimumImportsTest method testAppUsingAriesApplicationManager.

@Test
public void testAppUsingAriesApplicationManager() throws Exception {
    // Register a BlueprintListener to listen for the events from the BlueprintContainer for the bundle in the appmgrclienttest.eba
    AppMgrClientBlueprintListener acbl = new AppMgrClientBlueprintListener();
    ServiceRegistration sr = bundleContext.registerService("org.osgi.service.blueprint.container.BlueprintListener", acbl, null);
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("appmgrclienttest.eba")));
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        repositoryAdmin.removeRepository(repo.getURI());
    }
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    int sleepfor = 3000;
    while ((acbl.success == null || acbl.success == false) && sleepfor > 0) {
        Thread.sleep(100);
        sleepfor -= 100;
    }
    assertNotNull("Timed out - didn't receive Blueprint CREATED or FAILURE event", acbl.success);
    assertTrue("Received Blueprint FAILURE event", acbl.success);
    ctx.stop();
    manager.uninstall(ctx);
    sr.unregister();
}
Also used : Repository(org.apache.felix.bundlerepository.Repository) RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication) File(java.io.File) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 29 with AriesApplicationContext

use of org.apache.aries.application.management.AriesApplicationContext in project aries by apache.

the class OBRAppManagerTest method testAppWithApplicationManifest.

@Test
public void testAppWithApplicationManifest() throws Exception {
    RepositoryAdmin repositoryAdmin = context().getService(RepositoryAdmin.class);
    repositoryAdmin.addRepository(new File("repository.xml").toURI().toURL());
    Repository[] repos = repositoryAdmin.listRepositories();
    for (Repository repo : repos) {
        Resource[] resources = repo.getResources();
        for (Resource r : resources) {
            Capability[] cs = r.getCapabilities();
            for (Capability c : cs) {
                System.out.println(c.getName() + " : " + c.getProperties());
            }
        }
    }
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test.eba")));
    app = manager.resolve(app);
    //installing requires a valid url for the bundle in repository.xml.
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
    HelloWorld hw = context().getService(HelloWorld.class);
    String result = hw.getMessage();
    assertEquals(result, "hello world");
    ctx.stop();
    manager.uninstall(ctx);
}
Also used : RepositoryAdmin(org.apache.felix.bundlerepository.RepositoryAdmin) Capability(org.apache.felix.bundlerepository.Capability) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) Resource(org.apache.felix.bundlerepository.Resource) AriesApplication(org.apache.aries.application.management.AriesApplication) HelloWorld(org.apache.aries.sample.HelloWorld) Repository(org.apache.felix.bundlerepository.Repository) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) File(java.io.File) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 30 with AriesApplicationContext

use of org.apache.aries.application.management.AriesApplicationContext in project aries by apache.

the class IsolatedCfgAdminRuntimeTest method installApplication.

private Context installApplication(IDirectory application, String applicationName) throws Exception {
    //install the application and start it
    AriesApplicationManager appManager = context().getService(AriesApplicationManager.class);
    AriesApplication app = appManager.createApplication(application);
    AriesApplicationContext appCtx = appManager.install(app);
    appCtx.start();
    return new Context(appCtx, IsolationTestUtils.findIsolatedAppBundleContext(context(), applicationName));
}
Also used : RichBundleContext(org.apache.aries.itest.RichBundleContext) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) BundleContext(org.osgi.framework.BundleContext) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplicationManager(org.apache.aries.application.management.AriesApplicationManager) AriesApplication(org.apache.aries.application.management.AriesApplication)

Aggregations

AriesApplicationContext (org.apache.aries.application.management.AriesApplicationContext)34 AriesApplication (org.apache.aries.application.management.AriesApplication)24 Test (org.junit.Test)23 AriesApplicationManager (org.apache.aries.application.management.AriesApplicationManager)19 File (java.io.File)18 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)18 HelloWorld (org.apache.aries.sample.HelloWorld)7 Ignore (org.junit.Ignore)7 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)6 RepositoryAdmin (org.apache.felix.bundlerepository.RepositoryAdmin)6 ArrayList (java.util.ArrayList)5 Repository (org.apache.felix.bundlerepository.Repository)5 UpdateException (org.apache.aries.application.management.UpdateException)4 MavenArtifactUrlReference (org.ops4j.pax.exam.options.MavenArtifactUrlReference)4 Bundle (org.osgi.framework.Bundle)4 URL (java.net.URL)3 DeploymentContent (org.apache.aries.application.DeploymentContent)3 BundleException (org.osgi.framework.BundleException)3 AriesApplicationContextManager (org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager)2 MethodCall (org.apache.aries.unittest.mocks.MethodCall)2