Search in sources :

Example 6 with ExportedService

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

the class SharedFrameworkPreResolveHook method collectFakeResources.

@Override
public void collectFakeResources(Collection<ModelledResource> resources) {
    Bundle b = fwMgr.getSharedBundleFramework().getIsolatedBundleContext().getBundle(1);
    BundleInfo info = new BundleInfoImpl(b);
    Collection<ImportedService> serviceImports = Collections.emptySet();
    Collection<ExportedService> serviceExports = Collections.emptySet();
    try {
        resources.add(mgr.getModelledResource(info.getLocation(), info, serviceImports, serviceExports));
    } catch (InvalidAttributeException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : BundleInfo(org.apache.aries.application.management.BundleInfo) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) Bundle(org.osgi.framework.Bundle) ExportedService(org.apache.aries.application.modelling.ExportedService) ImportedService(org.apache.aries.application.modelling.ImportedService)

Example 7 with ExportedService

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

the class ModelledResourceManagerImpl method getBlueprintServiceElements.

private ParsedServiceElements getBlueprintServiceElements(BundleManifest bundleMf, Iterable<InputStream> blueprints) throws ModellerException {
    _logger.debug(LOG_ENTRY, "getServiceElements", new Object[] { bundleMf, blueprints });
    Set<ExportedService> services = new HashSet<ExportedService>();
    Set<ImportedService> references = new HashSet<ImportedService>();
    try {
        for (InputStream is : blueprints) {
            try {
                ParsedServiceElements pse = getParserProxy().parseAllServiceElements(is);
                services.addAll(pse.getServices());
                references.addAll(pse.getReferences());
            } finally {
                IOUtils.close(is);
            }
        }
    } catch (Exception e) {
        ModellerException m = new ModellerException(e);
        _logger.debug(LOG_EXIT, "getServiceElements", m);
        throw m;
    }
    ParsedServiceElements result = _modellingManager.getParsedServiceElements(services, references);
    _logger.debug(LOG_EXIT, "getServiceElements", result);
    return result;
}
Also used : ExportedService(org.apache.aries.application.modelling.ExportedService) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ModellerException(org.apache.aries.application.modelling.ModellerException) ImportedService(org.apache.aries.application.modelling.ImportedService) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvalidAttributeException(org.apache.aries.application.InvalidAttributeException) ModellerException(org.apache.aries.application.modelling.ModellerException) HashSet(java.util.HashSet) ParsedServiceElements(org.apache.aries.application.modelling.ParsedServiceElements)

Example 8 with ExportedService

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

Example 9 with ExportedService

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

the class AbstractBundleResourceTest method testBundleResource.

@Test
public void testBundleResource() throws Exception {
    assertEquals("The bundle symbolic name is wrong.", "test.bundle1", bundleResource.getSymbolicName());
    assertEquals("The bundle version is wrong.", "2.0.0.build-121", bundleResource.getVersion().toString());
    assertEquals("The bundle presentation name is wrong.", "Test Bundle", bundleResource.getExportedBundle().getAttributes().get(ModellingConstants.OBR_PRESENTATION_NAME));
    int count = 0;
    for (ImportedPackage ip : bundleResource.getImportedPackages()) {
        String filter = ip.getAttributeFilter();
        Map<String, String> parsedFilterElements = ManifestHeaderProcessor.parseFilter(filter);
        if (ip.getPackageName().equals("org.osgi.framework")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "org.osgi.framework");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "1.3.0");
        } else if (ip.getPackageName().equals("aries.ws.kernel.file")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.kernel.file");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
        } else if (ip.getPackageName().equals("aries.wsspi.application.aries")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.wsspi.application.aries");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
            assertEquals("Company wrong", parsedFilterElements.get("company"), "yang");
            assertTrue("mandatory filter missing", filter.contains("(mandatory:<*company)"));
        } else if (ip.getPackageName().equals("aries.ws.ffdc")) {
            count++;
            assertEquals("The filter is wrong.", "(&(package=aries.ws.ffdc)(version>=0.0.0))", ip.getAttributeFilter());
            assertTrue("Optional import not correctly represented", ip.isOptional());
        } else if (ip.getPackageName().equals("aries.ws.app.framework.plugin")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.app.framework.plugin");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "[1.0.0,2.0.0)");
        } else if (ip.getPackageName().equals("aries.ejs.ras")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ejs.ras");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
        } else if (ip.getPackageName().equals("aries.ws.event")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.event");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "1.0.0");
        } else if (ip.getPackageName().equals("aries.wsspi.app.container.aries")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.wsspi.app.container.aries");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("bundle-symbolic-name"), "B");
            assertEquals("Wrong bundle version", parsedFilterElements.get("bundle-version"), "[1.2.0,2.2.0)");
        } else if (ip.getPackageName().equals("aries.ws.eba.bla")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bla");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "0.0.0");
        } else if (ip.getPackageName().equals("aries.ws.eba.launcher")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.launcher");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "[1.0.0,2.0.0]");
            assertTrue("Dynamic-ImportPackage should be optional", ip.isOptional());
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle4")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bundle4");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "3.0.0");
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle5")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bundle5");
            assertEquals("Wrong package version", parsedFilterElements.get("version"), "3.0.0");
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle6")) {
            count++;
            assertEquals("Wrong package", parsedFilterElements.get("package"), "aries.ws.eba.bundle6");
            assertEquals("The filter is wrong.", "(&(package=aries.ws.eba.bundle6)(version>=0.0.0))", ip.getAttributeFilter());
        } else if (ip.getPackageName().equals("aries.ws.eba.bundle7")) {
            count++;
            assertEquals("The filter is wrong.", "(&(package=aries.ws.eba.bundle7)(version>=0.0.0))", ip.getAttributeFilter());
        }
    }
    for (ImportedBundle ib : bundleResource.getRequiredBundles()) {
        String filter = ib.getAttributeFilter();
        Map<String, String> parsedFilterElements = ManifestHeaderProcessor.parseFilter(filter);
        if (ib.getSymbolicName().equals("com.acme.facade")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.acme.facade");
            assertEquals("Wrong bundle version", parsedFilterElements.get("version"), "3.0.0");
        } else if (ib.getSymbolicName().equals("com.acme.bar")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.acme.bar");
        } else if (ib.getSymbolicName().equals("aries.ws.eba.framework")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "aries.ws.eba.framework");
            assertEquals("Wrong bundle version", parsedFilterElements.get("version"), "(3.0.0,4.0.0)");
        } else if (ib.getSymbolicName().equals("com.de.ba")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.de.ba");
        } else if (ib.getSymbolicName().equals("com.ab.de")) {
            count++;
            assertEquals("Wrong bundle symbolic name", parsedFilterElements.get("symbolicname"), "com.ab.de");
        }
    }
    for (ImportedService svc : bundleResource.getImportedServices()) {
        if (svc.getInterface().equals("aries.ws.eba.import")) {
            count++;
            String filter = svc.getAttributeFilter();
            Map<String, String> parsedFilterElements = ManifestHeaderProcessor.parseFilter(filter);
            assertEquals("Wrong object class", parsedFilterElements.get("objectClass"), "aries.ws.eba.import");
            assertTrue("(service=service) should be present", svc.getAttributeFilter().contains("(service=service)"));
            assertTrue("(mandatory:<*service) should be present", svc.getAttributeFilter().contains("(mandatory:<*service)"));
        }
    }
    assertEquals("Not all requirements are listed.", bundleResource.getImportedPackages().size() + bundleResource.getImportedServices().size() + bundleResource.getRequiredBundles().size(), count);
    //verify the capability
    int verifiedExport = 0;
    for (ExportedPackage cap : bundleResource.getExportedPackages()) {
        if (cap.getPackageName().equals("aries.ws.eba.bundle1")) {
            verifiedExport++;
            assertEquals("The export package is not expected.", "2.2.0", cap.getVersion());
            assertEquals("The export package is not expected.", "test.bundle1", cap.getAttributes().get("bundle-symbolic-name"));
            assertEquals("The export package is not expected.", "2.0.0.build-121", cap.getAttributes().get("bundle-version").toString());
        } else if (cap.getPackageName().equals("aries.ws.eba.bundle2")) {
            verifiedExport++;
            assertEquals("The export package is not expected.", "3", cap.getVersion());
        } else if (cap.getPackageName().equals("aries.ws.eba.bundle3")) {
            verifiedExport++;
            assertEquals("The export package is not expected.", "3", cap.getVersion());
        }
    }
    assertEquals("The number of exports are not expected.", bundleResource.getExportedPackages().size(), verifiedExport);
    // bundle resource
    assertEquals("The bundle resource is wrong.", "Test Bundle", bundleResource.getExportedBundle().getAttributes().get(ModellingConstants.OBR_PRESENTATION_NAME));
    assertEquals("The bundle resource is wrong.", "2.0.0.build-121", bundleResource.getExportedBundle().getVersion());
    assertEquals("The bundle resource is wrong.", "test.bundle1", bundleResource.getExportedBundle().getSymbolicName());
    for (ExportedService svc : bundleResource.getExportedServices()) {
        assertEquals("The export service is wrong", "aries.ws.eba.export", svc.getInterfaces().iterator().next());
    }
}
Also used : ExportedPackage(org.apache.aries.application.modelling.ExportedPackage) ExportedService(org.apache.aries.application.modelling.ExportedService) ImportedPackage(org.apache.aries.application.modelling.ImportedPackage) ImportedService(org.apache.aries.application.modelling.ImportedService) ImportedBundle(org.apache.aries.application.modelling.ImportedBundle) Test(org.junit.Test)

Example 10 with ExportedService

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

the class DeployedBundlesTest method createModelledServiceBundle.

public static ModelledResource createModelledServiceBundle(String bundleName, String bundleVersion, Collection<String> importService, Collection<String> exportService) throws InvalidAttributeException {
    Attributes att = new Attributes();
    att.put(new Attributes.Name(Constants.BUNDLE_SYMBOLICNAME), bundleName);
    att.put(new Attributes.Name(Constants.BUNDLE_VERSION), bundleVersion);
    att.put(new Attributes.Name(Constants.BUNDLE_MANIFESTVERSION), "2");
    List<ImportedService> importedServices = new ArrayList<ImportedService>();
    for (String s : importService) {
        importedServices.add(new ImportedServiceImpl(false, s, null, null, null, false));
    }
    List<ExportedService> exportedServices = new ArrayList<ExportedService>();
    for (String s : exportService) {
        exportedServices.add(new ExportedServiceImpl(null, 0, Collections.singleton(s), Collections.<String, Object>emptyMap()));
    }
    return new ModelledResourceImpl(null, att, importedServices, exportedServices);
}
Also used : ImportedServiceImpl(org.apache.aries.application.modelling.impl.ImportedServiceImpl) ModelledResourceImpl(org.apache.aries.application.modelling.impl.ModelledResourceImpl) ExportedService(org.apache.aries.application.modelling.ExportedService) Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) ImportedService(org.apache.aries.application.modelling.ImportedService) ExportedServiceImpl(org.apache.aries.application.modelling.impl.ExportedServiceImpl)

Aggregations

ExportedService (org.apache.aries.application.modelling.ExportedService)10 ImportedService (org.apache.aries.application.modelling.ImportedService)8 ArrayList (java.util.ArrayList)4 ParsedServiceElements (org.apache.aries.application.modelling.ParsedServiceElements)4 InvalidAttributeException (org.apache.aries.application.InvalidAttributeException)3 ModellerException (org.apache.aries.application.modelling.ModellerException)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Attributes (java.util.jar.Attributes)2 ModelledResource (org.apache.aries.application.modelling.ModelledResource)2 InputStream (java.io.InputStream)1 ZipInputStream (java.util.zip.ZipInputStream)1 ServiceDeclaration (org.apache.aries.application.ServiceDeclaration)1 BundleInfo (org.apache.aries.application.management.BundleInfo)1 ExportedPackage (org.apache.aries.application.modelling.ExportedPackage)1 ImportedBundle (org.apache.aries.application.modelling.ImportedBundle)1 ImportedPackage (org.apache.aries.application.modelling.ImportedPackage)1