Search in sources :

Example 6 with Requirement

use of io.fabric8.agent.model.Requirement in project fabric8 by jboss-fuse.

the class SubsystemResolver method associateFragments.

private void associateFragments() {
    SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM);
    for (Map.Entry<Resource, List<Wire>> entry : wiring.entrySet()) {
        final Resource resource = entry.getKey();
        final Requirement requirement = getSubsystemRequirement(resource);
        if (isFragment(resource)) {
            List<Wire> wires = entry.getValue();
            final Resource host = wires.get(0).getProvider();
            final Wire wire = findMatchingWire(sf, wiring.get(host));
            if (wire != null) {
                wires.add(new Wire() {

                    @Override
                    public Capability getCapability() {
                        return wire.getCapability();
                    }

                    @Override
                    public Requirement getRequirement() {
                        return requirement;
                    }

                    @Override
                    public Resource getProvider() {
                        return wire.getProvider();
                    }

                    @Override
                    public Resource getRequirer() {
                        return resource;
                    }
                });
            }
        }
    }
}
Also used : Requirement(org.osgi.resource.Requirement) Capability(org.osgi.resource.Capability) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter) Resource(org.osgi.resource.Resource) List(java.util.List) Wire(org.osgi.resource.Wire) HashMap(java.util.HashMap) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap) Map(java.util.Map)

Example 7 with Requirement

use of io.fabric8.agent.model.Requirement in project fabric8 by jboss-fuse.

the class SubsystemResolver method prepare.

public void prepare(Collection<Feature> allFeatures, Map<String, Set<String>> requirements, Map<String, Set<BundleRevision>> system) throws Exception {
    // Build subsystems on the fly
    for (Map.Entry<String, Set<String>> entry : requirements.entrySet()) {
        String[] parts = entry.getKey().split("/");
        if (root == null) {
            root = new Subsystem(parts[0]);
        } else if (!root.getName().equals(parts[0])) {
            throw new IllegalArgumentException("Can not use multiple roots: " + root.getName() + ", " + parts[0]);
        }
        Subsystem ss = root;
        for (int i = 1; i < parts.length; i++) {
            ss = getOrCreateChild(ss, parts[i]);
        }
        for (String requirement : entry.getValue()) {
            ss.require(requirement);
        }
    }
    if (root == null) {
        return;
    }
    // Pre-resolve
    root.build(allFeatures);
    // Add system resources
    BundleRevision sysBundleRev = null;
    boolean hasEeCap = false;
    for (Map.Entry<String, Set<BundleRevision>> entry : system.entrySet()) {
        Subsystem ss = null;
        String[] parts = entry.getKey().split("/");
        String path = parts[0];
        if (path.equals(root.getName())) {
            ss = root;
        }
        for (int i = 1; ss != null && i < parts.length; i++) {
            path += "/" + parts[i];
            ss = ss.getChild(path);
        }
        if (ss != null) {
            ResourceImpl dummy = new ResourceImpl("dummy", "dummy", Version.emptyVersion);
            for (BundleRevision res : entry.getValue()) {
                // We need to explicitely provide service capabilities for bundles
                // We use both actual services and services declared from the headers
                // TODO: use actual services
                Map<String, String> headers = new DictionaryAsMap<>(res.getBundle().getHeaders());
                Resource tmp = ResourceBuilder.build(res.getBundle().getLocation(), headers);
                for (Capability cap : tmp.getCapabilities(ServiceNamespace.SERVICE_NAMESPACE)) {
                    dummy.addCapability(new CapabilityImpl(dummy, cap.getNamespace(), cap.getDirectives(), cap.getAttributes()));
                }
                ss.addSystemResource(res);
                for (Capability cap : res.getCapabilities(null)) {
                    hasEeCap |= cap.getNamespace().equals(EXECUTION_ENVIRONMENT_NAMESPACE);
                }
                if (res.getBundle().getBundleId() == 0) {
                    sysBundleRev = res;
                }
            }
            ss.addSystemResource(dummy);
        }
    }
    // Under Equinox, the osgi.ee capabilities are not provided by the system bundle
    if (!hasEeCap && sysBundleRev != null) {
        String provideCaps = sysBundleRev.getBundle().getHeaders().get(PROVIDE_CAPABILITY);
        environmentResource = new ResourceImpl("environment", "karaf.environment", Version.emptyVersion);
        environmentResource.addCapabilities(ResourceBuilder.parseCapability(environmentResource, provideCaps));
        root.addSystemResource(environmentResource);
    }
}
Also used : CapabilitySet(io.fabric8.agent.resolver.CapabilitySet) Set(java.util.Set) Capability(org.osgi.resource.Capability) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap) Resource(org.osgi.resource.Resource) ResourceImpl(io.fabric8.agent.resolver.ResourceImpl) CapabilityImpl(io.fabric8.agent.resolver.CapabilityImpl) BundleRevision(org.osgi.framework.wiring.BundleRevision) HashMap(java.util.HashMap) DictionaryAsMap(org.apache.felix.utils.collections.DictionaryAsMap) Map(java.util.Map)

Example 8 with Requirement

use of io.fabric8.agent.model.Requirement in project fabric8 by jboss-fuse.

the class BaseRepository method findProviders.

@Override
public Map<Requirement, Collection<Capability>> findProviders(Collection<? extends Requirement> requirements) {
    Map<Requirement, Collection<Capability>> result = new HashMap<Requirement, Collection<Capability>>();
    for (Requirement requirement : requirements) {
        CapabilitySet set = capSets.get(requirement.getNamespace());
        if (set != null) {
            SimpleFilter sf;
            if (requirement instanceof RequirementImpl) {
                sf = ((RequirementImpl) requirement).getFilter();
            } else {
                String filter = requirement.getDirectives().get(Constants.FILTER_DIRECTIVE);
                sf = (filter != null) ? SimpleFilter.parse(filter) : new SimpleFilter(null, null, SimpleFilter.MATCH_ALL);
            }
            result.put(requirement, set.match(sf, true));
        } else {
            result.put(requirement, Collections.<Capability>emptyList());
        }
    }
    return result;
}
Also used : Requirement(org.osgi.resource.Requirement) RequirementImpl(io.fabric8.agent.resolver.RequirementImpl) Capability(org.osgi.resource.Capability) HashMap(java.util.HashMap) SimpleFilter(io.fabric8.agent.resolver.SimpleFilter) Collection(java.util.Collection) CapabilitySet(io.fabric8.agent.resolver.CapabilitySet)

Example 9 with Requirement

use of io.fabric8.agent.model.Requirement in project fabric8 by jboss-fuse.

the class Subsystem method addRequirement.

protected void addRequirement(String requirement) throws BundleException {
    for (Requirement req : ResourceBuilder.parseRequirement(this, requirement)) {
        Object range = req.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
        if (range instanceof String) {
            req.getAttributes().put(CAPABILITY_VERSION_ATTRIBUTE, new VersionRange((String) range));
        }
        addRequirement(req);
    }
}
Also used : Requirement(org.osgi.resource.Requirement) ResourceUtils.toFeatureRequirement(io.fabric8.agent.resolver.ResourceUtils.toFeatureRequirement) ResourceUtils.addIdentityRequirement(io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement) VersionRange(org.apache.felix.utils.version.VersionRange)

Example 10 with Requirement

use of io.fabric8.agent.model.Requirement in project fabric8 by jboss-fuse.

the class RequireProfileSetAction method updateRequirements.

@Override
protected boolean updateRequirements(FabricRequirements requirements) {
    if (v != null) {
        setVersion(v);
    } else {
        setVersion(getFabricService().getDefaultVersionId());
    }
    ProfileRequirements requirement = new ProfileRequirements(profile);
    if (minimumInstances != null) {
        requirement.setMinimumInstances(minimumInstances);
    }
    if (maximumInstances != null) {
        requirement.setMaximumInstances(maximumInstances);
    }
    if (dependentProfiles != null) {
        requirement.setDependentProfiles(dependentProfiles);
    }
    requirements.addOrUpdateProfileRequirements(requirement);
    return true;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements)

Aggregations

Requirement (org.osgi.resource.Requirement)7 Resource (org.osgi.resource.Resource)6 Capability (org.osgi.resource.Capability)5 ResourceUtils.addIdentityRequirement (io.fabric8.agent.resolver.ResourceUtils.addIdentityRequirement)4 HashMap (java.util.HashMap)4 BundleRevision (org.osgi.framework.wiring.BundleRevision)4 SimpleFilter (io.fabric8.agent.resolver.SimpleFilter)3 VersionRange (org.apache.felix.utils.version.VersionRange)3 Wire (org.osgi.resource.Wire)3 MapUtils.addToMapSet (io.fabric8.agent.internal.MapUtils.addToMapSet)2 MapUtils.removeFromMapSet (io.fabric8.agent.internal.MapUtils.removeFromMapSet)2 BundleInfo (io.fabric8.agent.model.BundleInfo)2 Dependency (io.fabric8.agent.model.Dependency)2 Feature (io.fabric8.agent.model.Feature)2 CapabilitySet (io.fabric8.agent.resolver.CapabilitySet)2 FeatureResource (io.fabric8.agent.resolver.FeatureResource)2 ResourceUtils.toFeatureRequirement (io.fabric8.agent.resolver.ResourceUtils.toFeatureRequirement)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Map (java.util.Map)2