Search in sources :

Example 11 with DeploymentMetadata

use of org.apache.aries.application.DeploymentMetadata in project aries by apache.

the class AriesApplicationManagerImplTest method testUpdateWithIncorrectDepMf.

@Test(expected = IllegalArgumentException.class)
public void testUpdateWithIncorrectDepMf() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    DeploymentMetadata depMf = Skeleton.newMock(DeploymentMetadata.class);
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationSymbolicName"), "random.app");
    Skeleton.getSkeleton(depMf).setReturnValue(new MethodCall(DeploymentMetadata.class, "getApplicationVersion"), new Version("1.0.0"));
    AriesApplicationContextManager ctxMgr = Skeleton.newMock(AriesApplicationContextManager.class);
    _appMgr.setApplicationContextManager(ctxMgr);
    _appMgr.update(app, depMf);
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) AriesApplicationContextManager(org.apache.aries.application.management.spi.runtime.AriesApplicationContextManager) Version(org.osgi.framework.Version) AriesApplication(org.apache.aries.application.management.AriesApplication) MethodCall(org.apache.aries.unittest.mocks.MethodCall) Test(org.junit.Test)

Example 12 with DeploymentMetadata

use of org.apache.aries.application.DeploymentMetadata in project aries by apache.

the class AriesApplicationManagerImplTest method testFailedUpdate.

@Test
public void testFailedUpdate() throws Exception {
    AriesApplication app = createApplication(TEST_EBA);
    DeploymentMetadata depMf = createUpdateDepMf();
    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, false, null));
    _appMgr.setApplicationContextManager(ctxMgr);
    try {
        _appMgr.update(app, depMf);
        fail("Update should have failed.");
    } catch (UpdateException e) {
        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) 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 13 with DeploymentMetadata

use of org.apache.aries.application.DeploymentMetadata in project aries by apache.

the class AriesApplicationManagerImplTest method testCreateAndConversion.

@Test
public void testCreateAndConversion() throws Exception {
    AriesApplication app = createApplication(CONVERSION_EBA);
    ApplicationMetadata appMeta = app.getApplicationMetadata();
    assertEquals(appMeta.getApplicationName(), "conversion.eba");
    assertEquals(appMeta.getApplicationSymbolicName(), "conversion.eba");
    assertEquals(appMeta.getApplicationVersion(), new Version("0.0"));
    List<Content> appContent = appMeta.getApplicationContents();
    assertEquals(2, appContent.size());
    Content fbw = new ContentImpl("hello.world.jar;version=\"[1.1.0, 1.1.0]\"");
    Content mbl = new ContentImpl("helloWorld.war;version=\"[0.0.0, 0.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("hello.world.jar;deployed-version=1.1.0");
    DeploymentContent dc2 = new DeploymentContentImpl("helloWorld.war;deployed-version=0.0.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));
    assertEquals(2, app.getBundleInfo().size());
    BundleInfo info;
    info = findBundleInfo(app.getBundleInfo(), "hello.world.jar");
    assertNotNull(info);
    assertEquals("HelloWorldJar", info.getHeaders().get(Constants.BUNDLE_NAME));
    info = findBundleInfo(app.getBundleInfo(), "helloWorld.war");
    assertNotNull(info);
    assertEquals("helloWorld.war", info.getHeaders().get(Constants.BUNDLE_NAME));
    assertEquals("/test", info.getHeaders().get("Bundle-ContextPath"));
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) BundleInfo(org.apache.aries.application.management.BundleInfo) SimpleBundleInfo(org.apache.aries.application.utils.management.SimpleBundleInfo) Version(org.osgi.framework.Version) Content(org.apache.aries.application.Content) DeploymentContent(org.apache.aries.application.DeploymentContent) AriesApplication(org.apache.aries.application.management.AriesApplication) ContentImpl(org.apache.aries.application.impl.ContentImpl) DeploymentContentImpl(org.apache.aries.application.impl.DeploymentContentImpl) DeploymentContent(org.apache.aries.application.DeploymentContent) Test(org.junit.Test)

Example 14 with DeploymentMetadata

use of org.apache.aries.application.DeploymentMetadata in project aries by apache.

the class BundleFrameworkConfigurationFactoryImpl method createBundleFrameworkConfig.

public BundleFrameworkConfiguration createBundleFrameworkConfig(String frameworkId, BundleContext parentCtx, AriesApplication app) {
    BundleFrameworkConfiguration config = null;
    DeploymentMetadata metadata = app.getDeploymentMetadata();
    /**
     * Set up framework config properties
     */
    Properties frameworkConfig = new Properties();
    // Problems occur if the parent framework has osgi.console set because the child framework
    // will also attempt to listen on the same port which will cause port clashs. Setting this
    // to null essentially turns the console off.
    frameworkConfig.put("osgi.console", "none");
    String flowedSystemPackages = EquinoxFrameworkUtils.calculateSystemPackagesToFlow(EquinoxFrameworkUtils.getSystemExtraPkgs(parentCtx), metadata.getImportPackage());
    frameworkConfig.put(Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, flowedSystemPackages);
    /**
     * Set up BundleManifest for the framework bundle
     */
    Properties frameworkBundleManifest = new Properties();
    frameworkBundleManifest.put(Constants.BUNDLE_SYMBOLICNAME, metadata.getApplicationSymbolicName());
    frameworkBundleManifest.put(Constants.BUNDLE_VERSION, metadata.getApplicationVersion().toString());
    /**
     * Set up Import-Package header for framework manifest
     */
    // Extract the import packages and remove anything we already have available in the current framework
    Collection<Content> imports = EquinoxFrameworkUtils.calculateImports(metadata.getImportPackage(), EquinoxFrameworkUtils.getExportPackages(parentCtx));
    if (imports != null && !imports.isEmpty()) {
        StringBuffer buffer = new StringBuffer();
        for (Content i : imports) buffer.append(EquinoxFrameworkUtils.contentToString(i) + ",");
        frameworkBundleManifest.put(Constants.IMPORT_PACKAGE, buffer.substring(0, buffer.length() - 1));
    }
    /**
     * Set up CompositeServiceFilter-Import header for framework manifest
     */
    StringBuilder serviceImportFilter = new StringBuilder();
    String txRegsitryImport = "(" + Constants.OBJECTCLASS + "=" + EquinoxFrameworkConstants.TRANSACTION_REGISTRY_BUNDLE + ")";
    Collection<Filter> deployedServiceImports = metadata.getDeployedServiceImport();
    //if there are more services than the txRegistry import a OR group is required for the Filter
    if (deployedServiceImports.size() > 0) {
        serviceImportFilter.append("(|");
    }
    for (Filter importFilter : metadata.getDeployedServiceImport()) {
        serviceImportFilter.append(importFilter.toString());
    }
    serviceImportFilter.append(txRegsitryImport);
    //close the OR group if needed
    if (deployedServiceImports.size() > 0) {
        serviceImportFilter.append(")");
    }
    frameworkBundleManifest.put(EquinoxFrameworkConstants.COMPOSITE_SERVICE_FILTER_IMPORT, serviceImportFilter.toString());
    config = new BundleFrameworkConfigurationImpl(frameworkId, frameworkConfig, frameworkBundleManifest);
    return config;
}
Also used : DeploymentMetadata(org.apache.aries.application.DeploymentMetadata) Filter(org.osgi.framework.Filter) Content(org.apache.aries.application.Content) Properties(java.util.Properties) BundleFrameworkConfiguration(org.apache.aries.application.management.spi.framework.BundleFrameworkConfiguration)

Example 15 with DeploymentMetadata

use of org.apache.aries.application.DeploymentMetadata 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

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