Search in sources :

Example 16 with AriesApplicationContext

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

the class BasicNoOpResolverTest method testAppWithApplicationManifest.

@Test
public void testAppWithApplicationManifest() throws Exception {
    AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
    AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("test2.eba")));
    // application name should equal to whatever Application name provided in the application.mf
    assertEquals("test application 2", app.getApplicationMetadata().getApplicationName());
    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 : 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) HelloWorld(org.apache.aries.sample.HelloWorld) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

Example 17 with AriesApplicationContext

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

the class ApplicationContextManagerImpl method unbindBundleFrameworkManager.

public void unbindBundleFrameworkManager(BundleFrameworkManager bfm) {
    LOGGER.debug(LOG_ENTRY, "unbindBundleFrameworkManager", bfm);
    List<AriesApplicationContext> appContexts = new ArrayList<AriesApplicationContext>();
    synchronized (_appToContextMap) {
        appContexts.addAll(_appToContextMap.values());
    }
    for (AriesApplicationContext c : appContexts) {
        try {
            ((ApplicationContextImpl) c).close();
        } catch (BundleException e) {
            LOGGER.debug(LOG_EXCEPTION, e);
        }
    }
    LOGGER.debug(LOG_EXIT, "unbindBundleFrameworkManager");
}
Also used : AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) ArrayList(java.util.ArrayList) BundleException(org.osgi.framework.BundleException)

Example 18 with AriesApplicationContext

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

the class ApplicationContextManagerImpl method getApplicationContext.

public synchronized AriesApplicationContext getApplicationContext(AriesApplication app) throws BundleException, ManagementException {
    LOGGER.debug(LOG_ENTRY, "getApplicationContext", app);
    AriesApplicationContext result;
    if (_appToContextMap.containsKey(app)) {
        result = _appToContextMap.get(app);
    } else {
        result = new ApplicationContextImpl(app, this);
        AriesApplicationContext previous = _appToContextMap.putIfAbsent(app, result);
        if (previous != null) {
            result = previous;
        }
    }
    LOGGER.debug(LOG_EXIT, "getApplicationContext", result);
    return result;
}
Also used : AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext)

Example 19 with AriesApplicationContext

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

Example 20 with AriesApplicationContext

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

the class TwitterTest method testTwitter.

/**
	 * Test for ARIES-461
	 * Application that bring in dependency bundles from a bundle repository doesn't deploy
	 * 
	 * @throws Exception
	 */
@Test
public void testTwitter() throws Exception {
    // provision against the local runtime
    System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
    deleteRepos();
    MavenArtifactUrlReference twitterEbaUrl = maven("org.apache.aries.samples.twitter", "org.apache.aries.samples.twitter.eba").versionAsInProject().type("eba");
    MavenArtifactUrlReference twitterCommonLangJar = maven("commons-lang", "commons-lang").versionAsInProject();
    MavenArtifactUrlReference twitterJar = maven("org.apache.aries.samples.twitter", "org.apache.aries.samples.twitter.twitter4j").versionAsInProject();
    // add the repository xml to the repository admin
    String repositoryXML = getRepoContent("/obr/twitter/TwitterRepository.xml");
    // replace the jar file url with the real url related to the environment
    String repo = repositoryXML.replaceAll("commons.lang.location", twitterCommonLangJar.getURL()).replaceAll("twitter4j.location", twitterJar.getURL());
    URL url = getRepoUrl(repo);
    repositoryAdmin.addRepository(url);
    AriesApplication app = manager.createApplication(new URL(twitterEbaUrl.getURL()));
    app = manager.resolve(app);
    DeploymentMetadata depMeta = app.getDeploymentMetadata();
    List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
    Collection<DeploymentContent> useBundles = depMeta.getDeployedUseBundle();
    Collection<DeploymentContent> appContent = depMeta.getApplicationDeploymentContents();
    // We cannot be sure whether there are two or three provision bundles pulled in by Felix OBR as there is an outstanding defect
    // https://issues.apache.org/jira/browse/FELIX-2672
    // The workaround is to check we get the two bundles we are looking for, instead of insisting on just having two bundles.
    List<String> provisionBundleSymbolicNames = new ArrayList<String>();
    for (DeploymentContent dep : provision) {
        provisionBundleSymbolicNames.add(dep.getContentName());
    }
    String provision_bundle1 = "org.apache.commons.lang";
    String provision_bundle2 = "twitter4j";
    assertTrue("Bundle " + provision_bundle1 + " not found.", provisionBundleSymbolicNames.contains(provision_bundle1));
    assertTrue("Bundle " + provision_bundle2 + " not found.", provisionBundleSymbolicNames.contains(provision_bundle2));
    assertEquals(useBundles.toString(), 0, useBundles.size());
    assertEquals(appContent.toString(), 1, appContent.size());
    AriesApplicationContext ctx = manager.install(app);
    ctx.start();
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) AriesApplicationContext(org.apache.aries.application.management.AriesApplicationContext) AriesApplication(org.apache.aries.application.management.AriesApplication) ArrayList(java.util.ArrayList) URL(java.net.URL) MavenArtifactUrlReference(org.ops4j.pax.exam.options.MavenArtifactUrlReference) DeploymentContent(org.apache.aries.application.DeploymentContent) Test(org.junit.Test) AbstractIntegrationTest(org.apache.aries.itest.AbstractIntegrationTest)

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