Search in sources :

Example 26 with ModelledResource

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

the class DeploymentManifestManagerImpl method findSuspects.

/**
   * We've done a sanity check resolve on our sharedBundles and received back 
   * resolvedSharedBundles. The resolvedSharedBundles should not contain any bundles listed in the isolated bundle list.
   * If this is not true, we've found a case of shared bundles depending on isolated bundles. 
   * This method extracts the name_versions of those bundles in resolvedSharedBundles
   * that do not appear in sharedBundles. 
   * @param resolvedSharedBundles What we got back from the resolver
   * @param sharedBundles         What we expected to get back from the resolver
   * @param appContentBundles     The isolated bundles
   * @return                      The isolated bundles depended by the shared bundles
   */
private List<String> findSuspects(Collection<ModelledResource> resolvedSharedBundles, Collection<ModelledResource> sharedBundles, Collection<ModelledResource> appContentBundles) {
    _logger.debug(LOG_ENTRY, "findSuspects", new Object[] { resolvedSharedBundles, sharedBundles, appContentBundles });
    Set<String> expectedBundles = new HashSet<String>();
    Set<String> isolatedBundles = new HashSet<String>();
    for (ModelledResource sb : sharedBundles) {
        expectedBundles.add(sb.getExportedBundle().getSymbolicName() + "_" + sb.getExportedBundle().getVersion());
    }
    for (ModelledResource sb : appContentBundles) {
        isolatedBundles.add(sb.getExportedBundle().getSymbolicName() + "_" + sb.getExportedBundle().getVersion());
    }
    List<String> suspects = new ArrayList<String>();
    for (ModelledResource mr : resolvedSharedBundles) {
        String thisBundle = mr.getExportedBundle().getSymbolicName() + "_" + mr.getExportedBundle().getVersion();
        if (!expectedBundles.contains(thisBundle) && (isolatedBundles.contains(thisBundle))) {
            suspects.add(thisBundle);
        }
    }
    _logger.debug(LOG_EXIT, "findSuspects", new Object[] { suspects });
    return suspects;
}
Also used : ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 27 with ModelledResource

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

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

the class DeploymentManifestManagerImpl method getByValueBundles.

/**
   * Get a list of bundles included by value in this application.
   * @param app The Aries Application
   * @return a list of by value bundles
   * @throws IOException
   * @throws InvalidAttributeException
   * @throws ModellerException
   */
private Collection<ModelledResource> getByValueBundles(AriesApplication app) throws IOException, InvalidAttributeException, ModellerException {
    _logger.debug(LOG_ENTRY, "getByValueBundles", new Object[] { app });
    Collection<BundleInfo> bundles = app.getBundleInfo();
    Collection<ModelledResource> result = new ArrayList<ModelledResource>();
    for (BundleInfo bundleInfo : bundles) {
        // find out the eba directory
        String bundleLocation = bundleInfo.getLocation();
        String bundleFileName = bundleLocation.substring(bundleLocation.lastIndexOf('/') + 1);
        // just the portion of root directory excluding !      
        URL jarUrl = new URL(bundleLocation);
        URLConnection jarCon = jarUrl.openConnection();
        jarCon.connect();
        InputStream in = jarCon.getInputStream();
        File dir = getLocalPlatform().getTemporaryDirectory();
        File temp = new File(dir, bundleFileName);
        OutputStream out = new FileOutputStream(temp);
        IOUtils.copy(in, out);
        IOUtils.close(out);
        result.add(modelledResourceManager.getModelledResource(null, FileSystem.getFSRoot(temp)));
        // delete the temp file
        temp.delete();
        IOUtils.deleteRecursive(dir);
    }
    _logger.debug(LOG_EXIT, "getByValueBundles", new Object[] { result });
    return result;
}
Also used : BundleInfo(org.apache.aries.application.management.BundleInfo) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ArrayList(java.util.ArrayList) File(java.io.File) URL(java.net.URL) URLConnection(java.net.URLConnection) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 29 with ModelledResource

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

the class DeploymentGeneratorTest method testResolve.

@Test
public void testResolve() throws Exception {
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getApplicationContents"), Arrays.asList(mockContent("aries.test.a", "1.0.0"), mockContent("aries.test.b", "[1.0.0, 2.0.0)")));
    Skeleton.getSkeleton(appMetadata).setReturnValue(new MethodCall(ApplicationMetadata.class, "getUseBundles"), Arrays.asList(BUNDLE_C, BUNDLE_D));
    DeployedBundles deployedBundles = deplMFMgr.generateDeployedBundles(appMetadata, new ArrayList<ModelledResource>(), Collections.<Content>emptyList());
    Manifest man = deplMFMgr.generateDeploymentManifest(appMetadata.getApplicationSymbolicName(), appMetadata.getApplicationVersion().toString(), deployedBundles);
    Attributes attrs = man.getMainAttributes();
    assertEquals("aries.test", attrs.getValue(AppConstants.APPLICATION_SYMBOLIC_NAME));
    assertEquals("1.0.0", attrs.getValue(AppConstants.APPLICATION_VERSION));
    String content = attrs.getValue(AppConstants.DEPLOYMENT_CONTENT);
    String useBundle = attrs.getValue(AppConstants.DEPLOYMENT_USE_BUNDLE);
    String provisioned = attrs.getValue(AppConstants.DEPLOYMENT_PROVISION_BUNDLE);
    assertTrue(content.contains("aries.test.a;deployed-version=1.0.0"));
    assertTrue(content.contains("aries.test.b;deployed-version=1.1.0"));
    assertTrue(useBundle.contains("aries.test.c;deployed-version=1.0.5"));
    assertFalse(useBundle.contains("aries.test.d"));
    assertTrue(provisioned.contains("aries.test.e;deployed-version=1.0.0"));
}
Also used : ApplicationMetadata(org.apache.aries.application.ApplicationMetadata) Attributes(java.util.jar.Attributes) DeployedBundles(org.apache.aries.application.modelling.DeployedBundles) Manifest(java.util.jar.Manifest) MethodCall(org.apache.aries.unittest.mocks.MethodCall) ModelledResource(org.apache.aries.application.modelling.ModelledResource) Test(org.junit.Test)

Example 30 with ModelledResource

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

the class DeploymentManifestManagerImpl method createFakeBundle.

// create a 'mock' bundle that does nothing but export services required by 
// Application-ImportService
private ModelledResource createFakeBundle(Collection<ServiceDeclaration> appImportServices) throws InvalidAttributeException {
    _logger.debug(LOG_ENTRY, "createFakeBundle", new Object[] { appImportServices });
    Attributes attrs = new Attributes();
    attrs.putValue(Constants.BUNDLE_SYMBOLICNAME, FAKE_BUNDLE_NAME);
    attrs.putValue(Constants.BUNDLE_VERSION_ATTRIBUTE, "1.0");
    attrs.putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
    // Build an ExportedService for every Application-ImportService entry
    Collection<ExportedService> exportedServices = new ArrayList<ExportedService>();
    for (ServiceDeclaration sDec : appImportServices) {
        Collection<String> ifaces = Arrays.asList(sDec.getInterfaceName());
        Filter filter = sDec.getFilter();
        Map<String, String> serviceProperties;
        if (filter != null) {
            serviceProperties = ManifestHeaderProcessor.parseFilter(filter.toString());
        } else {
            serviceProperties = new HashMap<String, String>();
        }
        serviceProperties.put("service.imported", "");
        exportedServices.add(modellingManager.getExportedService("", 0, ifaces, new HashMap<String, Object>(serviceProperties)));
    }
    ModelledResource fakeBundle = modellingManager.getModelledResource(null, attrs, null, exportedServices);
    _logger.debug(LOG_EXIT, "createFakeBundle", new Object[] { fakeBundle });
    return fakeBundle;
}
Also used : Filter(org.osgi.framework.Filter) HashMap(java.util.HashMap) ExportedService(org.apache.aries.application.modelling.ExportedService) ServiceDeclaration(org.apache.aries.application.ServiceDeclaration) Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Aggregations

ModelledResource (org.apache.aries.application.modelling.ModelledResource)41 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)16 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ZipOutputStream (java.util.zip.ZipOutputStream)11 ResolverException (org.apache.aries.application.management.ResolverException)11 AbstractIntegrationTest (org.apache.aries.itest.AbstractIntegrationTest)11 DeployedBundles (org.apache.aries.application.modelling.DeployedBundles)10 File (java.io.File)8 Content (org.apache.aries.application.Content)8 ApplicationMetadata (org.apache.aries.application.ApplicationMetadata)7 FileOutputStream (java.io.FileOutputStream)6 HashSet (java.util.HashSet)6 MethodCall (org.apache.aries.unittest.mocks.MethodCall)6 Manifest (java.util.jar.Manifest)5 AriesApplication (org.apache.aries.application.management.AriesApplication)5 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)5 HashMap (java.util.HashMap)4 Attributes (java.util.jar.Attributes)4 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)4