use of org.apache.aries.application.DeploymentContent in project aries by apache.
the class OBRResolverAdvancedTest method testDemoApp.
@Test
public void testDemoApp() throws Exception {
// do not provision against the local runtime
System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "true");
generateOBRRepoXML(false, TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + ".jar", USE_BUNDLE_BY_REFERENCE + ".jar");
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());
AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("demo.eba")));
// installing requires a valid url for the bundle in repository.xml.
app = manager.resolve(app);
DeploymentMetadata depMeta = app.getDeploymentMetadata();
List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
Collection<DeploymentContent> useBundles = depMeta.getDeployedUseBundle();
Collection<Content> importPackages = depMeta.getImportPackage();
assertEquals(provision.toString(), 2, provision.size());
assertEquals(useBundles.toString(), 1, useBundles.size());
assertEquals(importPackages.toString(), 4, importPackages.size());
List<String> bundleSymbolicNames = new ArrayList<String>();
for (DeploymentContent dep : provision) {
bundleSymbolicNames.add(dep.getContentName());
}
assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_REFERENCE));
assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_VALUE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_VALUE));
bundleSymbolicNames.clear();
for (DeploymentContent dep : useBundles) {
bundleSymbolicNames.add(dep.getContentName());
}
assertTrue("Bundle " + USE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(USE_BUNDLE_BY_REFERENCE));
Collection<String> packages = new ArrayList<String>();
Map<String, String> maps = new HashMap<String, String>();
maps.put("version", "0.0.0");
maps.put("bundle-symbolic-name", "use.bundle.by.reference");
maps.put("bundle-version", "[1.0.0,1.0.0]");
Content useContent = ContentFactory.parseContent("a.b.c", maps);
assertTrue("Use Bundle not found in import packags", importPackages.contains(useContent));
for (Content c : importPackages) {
packages.add(c.getContentName());
}
assertTrue("package javax.naming not found", packages.contains("javax.naming"));
assertTrue("package p.q.r not found", packages.contains("p.q.r"));
assertTrue("package x.y.z not found", packages.contains("x.y.z"));
assertTrue("package a.b.c not found", packages.contains("a.b.c"));
AriesApplicationContext ctx = manager.install(app);
ctx.start();
Set<Bundle> bundles = ctx.getApplicationContent();
assertEquals("Number of bundles provisioned in the app", 5, bundles.size());
ctx.stop();
manager.uninstall(ctx);
}
use of org.apache.aries.application.DeploymentContent in project aries by apache.
the class OBRResolverTest method testBlogApp.
@Test
public void testBlogApp() throws Exception {
// provision against the local runtime
System.setProperty(AppConstants.PROVISON_EXCLUDE_LOCAL_REPO_SYSPROP, "false");
generateOBRRepoXML(TRANSITIVE_BUNDLE_BY_REFERENCE + ".jar", CORE_BUNDLE_BY_REFERENCE + ".jar");
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());
AriesApplicationManager manager = context().getService(AriesApplicationManager.class);
AriesApplication app = manager.createApplication(FileSystem.getFSRoot(new File("blog.eba")));
// installing requires a valid url for the bundle in repository.xml.
app = manager.resolve(app);
DeploymentMetadata depMeta = app.getDeploymentMetadata();
List<DeploymentContent> provision = depMeta.getApplicationProvisionBundles();
assertEquals(provision.toString(), 3, provision.size());
List<String> bundleSymbolicNames = new ArrayList<String>();
for (DeploymentContent dep : provision) {
bundleSymbolicNames.add(dep.getContentName());
}
assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_REFERENCE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_REFERENCE));
assertTrue("Bundle " + TRANSITIVE_BUNDLE_BY_VALUE + " not found.", bundleSymbolicNames.contains(TRANSITIVE_BUNDLE_BY_VALUE));
assertTrue("Bundle " + BUNDLE_IN_FRAMEWORK + " not found.", bundleSymbolicNames.contains(BUNDLE_IN_FRAMEWORK));
AriesApplicationContext ctx = manager.install(app);
ctx.start();
Set<Bundle> bundles = ctx.getApplicationContent();
assertEquals("Number of bundles provisioned in the app", 4, bundles.size());
ctx.stop();
manager.uninstall(ctx);
}
use of org.apache.aries.application.DeploymentContent in project aries by apache.
the class AriesApplicationManagerImplTest method testCreate.
@Test
public void testCreate() throws Exception {
AriesApplication app = createApplication(TEST_EBA);
ApplicationMetadata appMeta = app.getApplicationMetadata();
assertEquals(appMeta.getApplicationName(), "Test application");
assertEquals(appMeta.getApplicationSymbolicName(), "org.apache.aries.application.management.test");
assertEquals(appMeta.getApplicationVersion(), new Version("1.0"));
List<Content> appContent = appMeta.getApplicationContents();
assertEquals(appContent.size(), 2);
Content fbw = new ContentImpl("foo.bar.widgets;version=1.0.0");
Content mbl = new ContentImpl("my.business.logic;version=1.0.0");
assertTrue(appContent.contains(fbw));
assertTrue(appContent.contains(mbl));
DeploymentMetadata dm = app.getDeploymentMetadata();
List<DeploymentContent> dcList = dm.getApplicationDeploymentContents();
assertEquals(2, dcList.size());
DeploymentContent dc1 = new DeploymentContentImpl("foo.bar.widgets;deployed-version=1.1.0");
DeploymentContent dc2 = new DeploymentContentImpl("my.business.logic;deployed-version=1.1.0");
DeploymentContent dc3 = new DeploymentContentImpl("a.handy.persistence.library;deployed-version=1.1.0");
assertTrue(dcList.contains(dc1));
assertTrue(dcList.contains(dc2));
dcList = dm.getApplicationProvisionBundles();
assertEquals(1, dcList.size());
assertTrue(dcList.contains(dc3));
}
use of org.apache.aries.application.DeploymentContent 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;
}
});
}
}
use of org.apache.aries.application.DeploymentContent 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);
}
}
}
}
Aggregations