Search in sources :

Example 16 with Content

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

the class DeploymentManifestManagerImpl method generateDeploymentManifest.

/**
   * Perform provisioning to work out the 'freeze dried list' of the eba
   * @param app - Aries application
   * @param ResolveConstraint - resolver constraint for limiting the resolving results
   * @return manifest the generated deployment manifest
   * @throws ResolverException
   */
@Override
public Manifest generateDeploymentManifest(AriesApplication app, ResolveConstraint... constraints) throws ResolverException {
    _logger.debug(LOG_ENTRY, "generateDeploymentManifest", new Object[] { app, constraints });
    ApplicationMetadata appMetadata = app.getApplicationMetadata();
    Collection<ModelledResource> byValueBundles = null;
    try {
        // find out blueprint information
        byValueBundles = getByValueBundles(app);
    // find out by value bundles and then by reference bundles
    } catch (Exception e) {
        throw new ResolverException(e);
    }
    Collection<Content> bundlesToResolve = new ArrayList<Content>();
    bundlesToResolve.addAll(appMetadata.getApplicationContents());
    bundlesToResolve.addAll(app.getApplicationMetadata().getUseBundles());
    //If we pass in provision bundles (e.g. import deployment manifest sanity check), we add them into our bundlesToResolve set.
    // This is because we want to make sure all bundles we passed into resolver the same as what we are going to get from resolver. 
    List<Content> restrictedReqs = new ArrayList<Content>();
    for (ResolveConstraint constraint : constraints) {
        Content content = ContentFactory.parseContent(constraint.getBundleName(), constraint.getVersionRange().toString());
        restrictedReqs.add(content);
    }
    DeployedBundles deployedBundles = generateDeployedBundles(appMetadata, byValueBundles, restrictedReqs);
    Manifest man = generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    _logger.debug(LOG_EXIT, "generateDeploymentManifest", new Object[] { man });
    return man;
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) ResolverException(org.apache.aries.application.management.ResolverException) ResolveConstraint(org.apache.aries.application.management.ResolveConstraint) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Manifest(java.util.jar.Manifest) ResolverException(org.apache.aries.application.management.ResolverException) IOException(java.io.IOException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) ServiceUnavailableException(org.osgi.service.blueprint.container.ServiceUnavailableException) ModellerException(org.apache.aries.application.modelling.ModellerException) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 17 with Content

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

the class DeploymentGeneratorTest method mockContent.

private Content mockContent(String symbolicName, String version) {
    Content bundle = Skeleton.newMock(Content.class);
    VersionRange vr = new VersionRange(version);
    Skeleton.getSkeleton(bundle).setReturnValue(new MethodCall(Content.class, "getContentName"), symbolicName);
    Skeleton.getSkeleton(bundle).setReturnValue(new MethodCall(Content.class, "getVersion"), vr);
    return bundle;
}
Also used : Content(org.apache.aries.application.Content) VersionRange(org.apache.aries.util.VersionRange) MethodCall(org.apache.aries.unittest.mocks.MethodCall)

Example 18 with Content

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

the class DeploymentGeneratorTest method checkMultipleCircularDependenciesDetected.

/**
   * This method checks that the a more complicated circular dependency issues the correct error message
   * and checks that the details listed in the exception are correct. 
   * @throws Exception
   */
@Test
public void checkMultipleCircularDependenciesDetected() throws Exception {
    Collection<ModelledResource> cmr = new ArrayList<ModelledResource>();
    ExportedPackage testIsolated1 = createExportedPackage("test.isolated1", "1.0.0", new String[] { "test.isolated1", "test.isolated2" }, new String[] { "test.shared1", "test.shared2" });
    cmr.add(testIsolated1.getBundle());
    ExportedPackage testIsolated2 = createExportedPackage("test.isolated2", "1.0.0", new String[] { "test.isolated1", "test.isolated2" }, new String[] { "test.shared1", "test.shared2" });
    cmr.add(testIsolated2.getBundle());
    ExportedPackage testShared1 = createExportedPackage("test.shared1", "1.0.0", new String[] { "test.shared1", "test.shared2" }, new String[] { "test.isolated1", "test.isolated2" });
    cmr.add(testShared1.getBundle());
    ExportedPackage testShared2 = createExportedPackage("test.shared2", "1.0.0", new String[] { "test.shared1", "test.shared2" }, new String[] { "test.isolated1", "test.isolated2" });
    cmr.add(testShared2.getBundle());
    _resolver.addResult(cmr);
    // The second time DeploymentGenerator calls the Resolver, it will provide just 
    // test.shared. The resolver will return test.shared _plus_ test.isolated. 
    _resolver.addResult(cmr);
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("test.isolated1", "1.0.0"), mockContent("test.isolated2", "1.0.0")));
    app = Skeleton.newMock(AriesApplication.class);
    Skeleton.getSkeleton(app).setReturnValue(new MethodCall(AriesApplication.class, "getApplicationMetadata"), appMetadata);
    try {
        DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, Arrays.asList(new ModelledResource[] { testIsolated1.getBundle(), testIsolated2.getBundle() }), new ArrayList<Content>());
        deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    } catch (ResolverException rx) {
        // Get the unsatisfied Requirements
        List<String> unsatisfiedReqs = rx.getUnsatisfiedRequirements();
        // Ensure we've got 4 unsatisfied Requirements
        assertEquals("4 unsatisfied requirements expected, but got " + Arrays.toString(unsatisfiedReqs.toArray()), 4, unsatisfiedReqs.size());
        List<String> checkMessages = new ArrayList<String>();
        // Now load an array with the expected messages.
        checkMessages.add("Shared bundle test.shared1_1.0.0 has a dependency for package test.isolated1 which " + "is exported from application bundles [test.isolated1_1.0.0, test.isolated2_1.0.0]");
        checkMessages.add("Shared bundle test.shared1_1.0.0 has a dependency for package test.isolated2 which " + "is exported from application bundles [test.isolated1_1.0.0, test.isolated2_1.0.0]");
        checkMessages.add("Shared bundle test.shared2_1.0.0 has a dependency for package test.isolated1 which " + "is exported from application bundles [test.isolated1_1.0.0, test.isolated2_1.0.0]");
        checkMessages.add("Shared bundle test.shared2_1.0.0 has a dependency for package test.isolated2 which " + "is exported from application bundles [test.isolated1_1.0.0, test.isolated2_1.0.0]");
        // because some unsatisfied reqs have spaces at the end of the string.
        for (String unsatisfiedReq : unsatisfiedReqs) {
            assertTrue(unsatisfiedReq + " is not an expected msg", checkMessages.contains(unsatisfiedReq.trim()));
        }
    }
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) AriesApplication(org.apache.aries.application.management.AriesApplication) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) MethodCall(org.apache.aries.unittest.mocks.MethodCall) ModelledResource(org.apache.aries.application.modelling.ModelledResource) ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) Content(org.apache.aries.application.Content) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 19 with Content

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

the class ManifestProcessorTest method testManifestMetadataWithMultiLineEntries.

/**
   * Check metadata can be extracted from a manifest that uses multiple lines
   * for a single manifest attribute.
   */
@Test
public void testManifestMetadataWithMultiLineEntries() throws Exception {
    ApplicationMetadataFactoryImpl manager = new ApplicationMetadataFactoryImpl();
    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION2.MF");
    ApplicationMetadata am = manager.parseApplicationMetadata(in);
    assertNotNull(am);
    assertEquals(am.getApplicationName(), appName);
    //"com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
    List<Content> contents = am.getApplicationContents();
    for (Content content : contents) {
        if ("com.travel.reservation.web".equals(content.getContentName())) {
            VersionRange vr = content.getVersion();
            assertEquals(vr.getMinimumVersion(), new Version("1.1.0"));
            assertEquals(vr.getMaximumVersion(), new Version("1.2.0"));
        } else if ("com.travel.reservation.business".equals(content.getContentName())) {
            VersionRange vr = content.getVersion();
            assertEquals(new Version(0, 0, 0), vr.getMinimumVersion());
        } else
            fail("Unexepcted content name " + content.getContentName());
    }
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Version(org.osgi.framework.Version) InputStream(java.io.InputStream) Content(org.apache.aries.application.Content) VersionRange(org.apache.aries.util.VersionRange) ApplicationMetadataFactoryImpl(org.apache.aries.application.impl.ApplicationMetadataFactoryImpl) Test(org.junit.Test)

Example 20 with Content

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

the class ManifestProcessorTest method testManifestMetadata.

/**
   * Check metadata can be extracted from a simple manifest.
   */
@Test
public void testManifestMetadata() throws Exception {
    ApplicationMetadataFactoryImpl manager = new ApplicationMetadataFactoryImpl();
    InputStream in = getClass().getClassLoader().getResourceAsStream("META-INF/APPLICATION.MF");
    ApplicationMetadata am = manager.parseApplicationMetadata(in);
    assertNotNull(am);
    assertEquals(am.getApplicationName(), appName);
    //"com.travel.reservation.web;version=\"[1.1.0,1.2.0)\",com.travel.reservation.business",
    List<Content> contents = am.getApplicationContents();
    for (Content content : contents) {
        if ("com.travel.reservation.web".equals(content.getContentName())) {
            VersionRange vr = content.getVersion();
            assertEquals(vr.getMinimumVersion(), new Version("1.1.0"));
            assertEquals(vr.getMaximumVersion(), new Version("1.2.0"));
        } else if ("com.travel.reservation.business".equals(content.getContentName())) {
            VersionRange vr = content.getVersion();
            assertEquals(new Version(0, 0, 0), vr.getMinimumVersion());
        } else
            fail("Unexepcted content name " + content.getContentName());
    }
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Version(org.osgi.framework.Version) InputStream(java.io.InputStream) Content(org.apache.aries.application.Content) VersionRange(org.apache.aries.util.VersionRange) ApplicationMetadataFactoryImpl(org.apache.aries.application.impl.ApplicationMetadataFactoryImpl) Test(org.junit.Test)

Aggregations

Content (org.apache.aries.application.Content)27 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)12 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)10 ModelledResource (org.apache.aries.application.modelling.ModelledResource)9 AriesApplication (org.apache.aries.application.management.AriesApplication)8 ResolverException (org.apache.aries.application.management.ResolverException)8 Version (org.osgi.framework.Version)8 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)7 HashSet (java.util.HashSet)6 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 DeploymentContent (org.apache.aries.application.DeploymentContent)5 HashMap (java.util.HashMap)4 DeploymentMetadata (org.apache.aries.application.DeploymentMetadata)4 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)4 VersionRange (org.apache.aries.util.VersionRange)4 List (java.util.List)3 Map (java.util.Map)3 Manifest (java.util.jar.Manifest)3 ApplicationMetadataFactoryImpl (org.apache.aries.application.impl.ApplicationMetadataFactoryImpl)3