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;
}
});
}
}
}
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations