Search in sources :

Example 16 with DeployedBundles

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

use of org.apache.aries.application.modelling.DeployedBundles in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_rfc138PreventsBundleSymbolicNameWorking.

@Test
public void testGetImportPackage_rfc138PreventsBundleSymbolicNameWorking() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.USES, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.b;version=1.0.0;bundle-symbolic-name=bundle.b"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", new ArrayList<String>(), Arrays.asList("package.b;version=2.0.0")));
    // Check that the bundle-symbolic-name attribute for a bundle outside use-bundle causes an exception.
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
        Assert.fail("Expected exception. ImportPackage=" + importPackageEntry);
    } catch (ResolverException e) {
    // We expect to reach this point if the test passes.
    }
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

Example 18 with DeployedBundles

use of org.apache.aries.application.modelling.DeployedBundles in project aries by apache.

the class DeployedBundlesTest method testGetRequiredUseBundle_RedundantEntry.

@Test
public void testGetRequiredUseBundle_RedundantEntry() throws Exception {
    // Bundle A requires package B from bundle B with no version requirement.
    // Bundle B requires package C from bundle C with no version requirement.
    // Bundle C requires package B from bundle B with explicit version requirement.
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.USES, ternary.USES);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.b"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", Arrays.asList("package.c"), Arrays.asList("package.b;version=1.0.0")));
    deployedBundles.addBundle(createModelledResource("bundle.c", "1.0.0", Arrays.asList("package.b;version=1.0.0"), Arrays.asList("package.c;version=1.0.0")));
    // Check the redundant use-bundle entry is identified.
    // Bundle C is not required by app content, although it is specified in use-bundle.
    Collection<ModelledResource> requiredUseBundle = null;
    try {
        requiredUseBundle = deployedBundles.getRequiredUseBundle();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    Assert.assertTrue("RequiredUseBundle=" + requiredUseBundle, requiredUseBundle.size() == 1);
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test)

Example 19 with DeployedBundles

use of org.apache.aries.application.modelling.DeployedBundles in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_InvalidBundleVersion.

// Inside cannot bundle-symbolic-name an outside bundle until the new RFC 138!
@Test
public void testGetImportPackage_InvalidBundleVersion() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.USES, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.b;version=\"[1.0.0,1.0.0]\";bundle-symbolic-name=bundle.b;bundle-version=\"[0.0.0,1.0.0)\""), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", new ArrayList<String>(), Arrays.asList("package.b;version=1.0.0")));
    // Check that the bundle version requirement generates an error because it doesn't match the a bundle in use-bundle.
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
        Assert.fail("Expected exception. ImportPackage=" + importPackageEntry);
    } catch (ResolverException e) {
    // We expect to reach this point if the test passes.
    }
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

Example 20 with DeployedBundles

use of org.apache.aries.application.modelling.DeployedBundles in project aries by apache.

the class DeployedBundlesTest method testGetImportPackage_ValidDuplicatesWithAttributes.

@Test
public void testGetImportPackage_ValidDuplicatesWithAttributes() throws Exception {
    DeployedBundles deployedBundles = getSimpleDeployedBundles(ternary.CONTENT, ternary.CONTENT, ternary.NONE);
    deployedBundles.addBundle(createModelledResource("bundle.a", "1.0.0", Arrays.asList("package.c;version=1.0.0;was_internal=true"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.b", "1.0.0", Arrays.asList("package.c;version=2.0.0;was_internal=true"), new ArrayList<String>()));
    deployedBundles.addBundle(createModelledResource("bundle.c", "1.0.0", new ArrayList<String>(), Arrays.asList("package.c;version=2.0.0;was_internal=true")));
    // Check that package C is not duplicated in Import-Package, and that the version range
    // has been narrowed to the intersection of the original requirements.
    String importPackageEntry = null;
    try {
        importPackageEntry = deployedBundles.getImportPackage();
    } catch (ResolverException e) {
        e.printStackTrace();
        Assert.fail(e.toString());
    }
    String expectedResult = "package.c;was_internal=\"true\";version=\"2.0.0\"";
    Assert.assertTrue("ImportPackage=" + importPackageEntry, isEqual(importPackageEntry, expectedResult));
}
Also used : ResolverException(org.apache.aries.application.management.ResolverException) ArrayList(java.util.ArrayList) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Test(org.junit.Test)

Aggregations

DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)26 Test (org.junit.Test)23 ArrayList (java.util.ArrayList)17 ResolverException (org.apache.aries.application.management.ResolverException)17 ModelledResource (org.apache.aries.application.modelling.ModelledResource)10 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)8 Content (org.apache.aries.application.Content)7 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 Manifest (java.util.jar.Manifest)4 AriesApplication (org.apache.aries.application.management.AriesApplication)4 List (java.util.List)3 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)3 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)2 ServiceUnavailableException (org.osgi.service.blueprint.container.ServiceUnavailableException)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Attributes (java.util.jar.Attributes)1 ResolveConstraint (org.apache.aries.application.management.ResolveConstraint)1