Search in sources :

Example 1 with ExportedService

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

the class ApplicationServiceModeller method computeRequirementsAndCapabilities.

@Override
public ServiceModel computeRequirementsAndCapabilities(Resource resource, IDirectory directory) throws SubsystemException {
    try {
        ServiceModelImpl model = new ServiceModelImpl();
        ParsedServiceElements elements = manager.getServiceElements(directory);
        for (ExportedService service : elements.getServices()) {
            model.capabilities.add(new BasicCapability.Builder().namespace(ServiceNamespace.SERVICE_NAMESPACE).attribute(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE, new ArrayList<String>(service.getInterfaces())).attributes(service.getServiceProperties()).resource(resource).build());
        }
        for (ImportedService service : elements.getReferences()) {
            StringBuilder builder = new StringBuilder();
            String serviceInterface = service.getInterface();
            String filter = service.getFilter();
            if (serviceInterface != null && filter != null) {
                builder.append("(&");
            }
            if (serviceInterface != null) {
                builder.append('(').append(ServiceNamespace.CAPABILITY_OBJECTCLASS_ATTRIBUTE).append('=').append(serviceInterface).append(')');
            }
            if (filter != null)
                builder.append(filter);
            if (serviceInterface != null && filter != null) {
                builder.append(')');
            }
            if (builder.length() > 0) {
                model.requirements.add(new BasicRequirement.Builder().namespace(ServiceNamespace.SERVICE_NAMESPACE).directive(Namespace.REQUIREMENT_FILTER_DIRECTIVE, builder.toString()).directive(Namespace.REQUIREMENT_RESOLUTION_DIRECTIVE, service.isOptional() ? Namespace.RESOLUTION_OPTIONAL : Namespace.RESOLUTION_MANDATORY).directive(Namespace.REQUIREMENT_CARDINALITY_DIRECTIVE, service.isMultiple() ? Namespace.CARDINALITY_MULTIPLE : Namespace.CARDINALITY_SINGLE).resource(resource).build());
            }
        }
        return model;
    } catch (ModellerException e) {
        throw new SubsystemException(e);
    }
}
Also used : ExportedService(org.apache.aries.application.modelling.ExportedService) SubsystemException(org.osgi.service.subsystem.SubsystemException) ModellerException(org.apache.aries.application.modelling.ModellerException) ImportedService(org.apache.aries.application.modelling.ImportedService) ParsedServiceElements(org.apache.aries.application.modelling.ParsedServiceElements)

Example 2 with ExportedService

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

the class ModelledResourceManagerImpl method getServiceElements.

private ParsedServiceElements getServiceElements(BundleManifest bundleMf, IDirectory archive) throws ModellerException {
    Set<ExportedService> services = new HashSet<ExportedService>();
    Set<ImportedService> references = new HashSet<ImportedService>();
    try {
        ParsedServiceElements pse = getBlueprintServiceElements(bundleMf, findBlueprints(bundleMf, archive));
        services.addAll(pse.getServices());
        references.addAll(pse.getReferences());
        for (ServiceModeller sm : modellingPlugins) {
            pse = sm.modelServices(bundleMf, archive);
            services.addAll(pse.getServices());
            references.addAll(pse.getReferences());
        }
        return new ParsedServiceElementsImpl(services, references);
    } catch (Exception e) {
        throw new ModellerException(e);
    }
}
Also used : ServiceModeller(org.apache.aries.application.modelling.ServiceModeller) ExportedService(org.apache.aries.application.modelling.ExportedService) 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 3 with ExportedService

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

the class AbstractParserProxy method parseCDRForServices.

/**
	   * Extract Service metadata from a ComponentDefinitionRegistry. When doing SCA modelling, we
	   * need to suppress anonymous services. We don't want to do that when we're modelling for 
	   * provisioning dependencies. 
	   * @param cdr                       ComponentDefinitionRegistry
	   * @param suppressAnonymousServices Unnamed services will not be returned if this is true
	   * @return List<WrappedServiceMetadata>
	   */
private List<ExportedService> parseCDRForServices(ComponentDefinitionRegistry cdr, boolean suppressAnonymousServices) {
    _logger.debug(LOG_ENTRY, "parseCDRForServices", new Object[] { cdr, suppressAnonymousServices });
    List<ExportedService> result = new ArrayList<ExportedService>();
    for (ComponentMetadata compMetadata : findAllComponents(cdr)) {
        if (compMetadata instanceof ServiceMetadata) {
            ServiceMetadata serviceMetadata = (ServiceMetadata) compMetadata;
            String serviceName;
            int ranking;
            Collection<String> interfaces = new ArrayList<String>();
            Map<String, Object> serviceProps = new HashMap<String, Object>();
            ranking = serviceMetadata.getRanking();
            for (Object i : serviceMetadata.getInterfaces()) {
                interfaces.add((String) i);
            }
            // get the service properties
            List<MapEntry> props = serviceMetadata.getServiceProperties();
            for (MapEntry entry : props) {
                String key = ((ValueMetadata) entry.getKey()).getStringValue();
                Metadata value = entry.getValue();
                if (value instanceof CollectionMetadata) {
                    processMultiValueProperty(serviceProps, key, value);
                } else {
                    serviceProps.put(key, ((ValueMetadata) entry.getValue()).getStringValue());
                }
            }
            // serviceName: use the service id unless that's not set, 
            // in which case we use the bean id. 
            serviceName = serviceMetadata.getId();
            // If the Service references a Bean, export the bean id as a service property
            // as per 121.6.5 p669 of the blueprint 1.0 specification
            Target t = serviceMetadata.getServiceComponent();
            String targetId = null;
            if (t instanceof RefMetadata) {
                targetId = ((RefMetadata) t).getComponentId();
            } else if (t instanceof BeanMetadata) {
                targetId = ((BeanMetadata) t).getId();
            }
            // or auto-generated for an anonymous service. This must ALWAYS be set. 
            if (targetId != null && !targetId.startsWith(".")) {
                // Don't set this for anonymous inner components
                serviceProps.put("osgi.service.blueprint.compname", targetId);
                if (serviceName == null || serviceName.equals("") || serviceName.startsWith(".")) {
                    serviceName = targetId;
                }
            }
            if (serviceName != null && serviceName.startsWith("."))
                serviceName = null;
            // If suppressAnonymous services, do not expose services that have no name
            if (!suppressAnonymousServices || (serviceName != null)) {
                ExportedService wsm = _modellingManager.getExportedService(serviceName, ranking, interfaces, serviceProps);
                result.add(wsm);
            }
        }
    }
    _logger.debug(LOG_EXIT, "parseAllServiceElements", new Object[] { result });
    return result;
}
Also used : CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) MapEntry(org.osgi.service.blueprint.reflect.MapEntry) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) HashMap(java.util.HashMap) ExportedService(org.apache.aries.application.modelling.ExportedService) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) ArrayList(java.util.ArrayList) CollectionMetadata(org.osgi.service.blueprint.reflect.CollectionMetadata) ValueMetadata(org.osgi.service.blueprint.reflect.ValueMetadata) Metadata(org.osgi.service.blueprint.reflect.Metadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata) RefMetadata(org.osgi.service.blueprint.reflect.RefMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) ServiceReferenceMetadata(org.osgi.service.blueprint.reflect.ServiceReferenceMetadata) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) MapMetadata(org.osgi.service.blueprint.reflect.MapMetadata) ReferenceListMetadata(org.osgi.service.blueprint.reflect.ReferenceListMetadata) ComponentMetadata(org.osgi.service.blueprint.reflect.ComponentMetadata) Target(org.osgi.service.blueprint.reflect.Target) BeanMetadata(org.osgi.service.blueprint.reflect.BeanMetadata) WrappedServiceMetadata(org.apache.aries.application.modelling.WrappedServiceMetadata) ServiceMetadata(org.osgi.service.blueprint.reflect.ServiceMetadata)

Example 4 with ExportedService

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

the class DeployedBundlesImpl method getDeployedImportService.

/**
   * Get the Deployed-ImportService header. 
   * this.deployedImportService contains all the service import filters for every 
   * blueprint component within the application. We will only write an entry
   * to Deployed-ImportService if
   *   a) the reference isMultiple(), or
   *   b) the service was not available internally when the app was first deployed
   *   
   */
public String getDeployedImportService() {
    logger.debug(LOG_ENTRY, "getDeployedImportService");
    String result = cachedDeployedImportService;
    if (result == null) {
        Collection<ImportedService> deployedBundleServiceImports = new ArrayList<ImportedService>();
        Collection<ExportedService> servicesExportedWithinIsolatedContent = new ArrayList<ExportedService>();
        for (ModelledResource mRes : getDeployedContent()) {
            servicesExportedWithinIsolatedContent.addAll(mRes.getExportedServices());
        }
        for (ModelledResource mRes : fakeDeployedBundles) {
            servicesExportedWithinIsolatedContent.addAll(mRes.getExportedServices());
        }
        for (ImportedService impService : deployedImportService) {
            if (impService.isMultiple()) {
                deployedBundleServiceImports.add(impService);
            } else {
                boolean serviceProvidedWithinIsolatedContent = false;
                Iterator<ExportedService> it = servicesExportedWithinIsolatedContent.iterator();
                while (!serviceProvidedWithinIsolatedContent && it.hasNext()) {
                    ExportedService svc = it.next();
                    serviceProvidedWithinIsolatedContent |= impService.isSatisfied(svc);
                }
                if (!serviceProvidedWithinIsolatedContent) {
                    deployedBundleServiceImports.add(impService);
                }
            }
        }
        result = createManifestString(deployedBundleServiceImports);
        cachedDeployedImportService = result;
    }
    logger.debug(LOG_EXIT, "getDeployedImportService", result);
    return result;
}
Also used : ExportedService(org.apache.aries.application.modelling.ExportedService) ArrayList(java.util.ArrayList) ImportedService(org.apache.aries.application.modelling.ImportedService) ModelledResource(org.apache.aries.application.modelling.ModelledResource)

Example 5 with ExportedService

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

the class AbstractParserProxy method parseAllServiceElements.

public ParsedServiceElements parseAllServiceElements(InputStream blueprintToParse) throws Exception {
    _logger.debug(LOG_ENTRY, "parseAllServiceElements", new Object[] { blueprintToParse });
    ComponentDefinitionRegistry cdr = parseCDR(blueprintToParse);
    Collection<ExportedService> services = parseCDRForServices(cdr, false);
    Collection<ImportedService> references = parseCDRForReferences(cdr);
    ParsedServiceElements result = _modellingManager.getParsedServiceElements(services, references);
    _logger.debug(LOG_EXIT, "parseAllServiceElements", new Object[] { result });
    return result;
}
Also used : ComponentDefinitionRegistry(org.apache.aries.blueprint.ComponentDefinitionRegistry) ExportedService(org.apache.aries.application.modelling.ExportedService) ImportedService(org.apache.aries.application.modelling.ImportedService) ParsedServiceElements(org.apache.aries.application.modelling.ParsedServiceElements)

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