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);
}
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");
}
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;
}
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);
}
}
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();
}
Aggregations