use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.
the class Subsystem method build.
@SuppressWarnings("InfiniteLoopStatement")
public void build(Collection<Feature> features) throws Exception {
for (Subsystem child : children) {
child.build(features);
}
if (feature != null) {
for (Dependency dep : feature.getDependencies()) {
Subsystem ss = this;
while (!ss.isAcceptDependencies()) {
ss = ss.getParent();
}
ss.requireFeature(dep.getName(), dep.getVersion(), !dep.isDependency());
}
}
List<Requirement> processed = new ArrayList<>();
while (true) {
List<Requirement> requirements = getRequirements(IDENTITY_NAMESPACE);
requirements.addAll(dependentFeatures);
requirements.removeAll(processed);
if (requirements.isEmpty()) {
break;
}
for (Requirement requirement : requirements) {
String name = (String) requirement.getAttributes().get(IDENTITY_NAMESPACE);
String type = (String) requirement.getAttributes().get(CAPABILITY_TYPE_ATTRIBUTE);
VersionRange range = (VersionRange) requirement.getAttributes().get(CAPABILITY_VERSION_ATTRIBUTE);
if (TYPE_FEATURE.equals(type)) {
for (Feature feature : features) {
if (feature.getName().equals(name) && (range == null || range.contains(VersionTable.getVersion(feature.getVersion())))) {
if (feature != this.feature) {
String ssName = this.name + "#" + (feature.hasVersion() ? feature.getName() + "-" + feature.getVersion() : feature.getName());
Subsystem fs = getChild(ssName);
if (fs == null) {
fs = new Subsystem(ssName, feature, this);
fs.build(features);
installable.add(fs);
children.add(fs);
}
}
}
}
}
processed.add(requirement);
}
}
}
use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.
the class SubsystemResolveContext method findProviders.
@Override
public List<Capability> findProviders(Requirement requirement) {
List<Capability> caps = new ArrayList<Capability>();
Region requirerRegion = getRegion(requirement.getResource());
if (requirerRegion != null) {
Map<Requirement, Collection<Capability>> resMap = repository.findProviders(Collections.singleton(requirement));
Collection<Capability> res = resMap != null ? resMap.get(requirement) : null;
if (res != null && !res.isEmpty()) {
caps.addAll(res);
} else if (globalRepository != null) {
// Only bring in external resources for non optional requirements
if (!RESOLUTION_OPTIONAL.equals(requirement.getDirectives().get(RESOLUTION_DIRECTIVE))) {
resMap = globalRepository.findProviders(Collections.singleton(requirement));
res = resMap != null ? resMap.get(requirement) : null;
if (res != null && !res.isEmpty()) {
caps.addAll(res);
}
}
}
// Use the digraph to prune non visible capabilities
Visitor visitor = new Visitor(caps);
requirerRegion.visitSubgraph(visitor);
Collection<Capability> allowed = visitor.getAllowed();
caps.retainAll(allowed);
// the parent one
if (caps.size() > 1) {
Map<String, Resource> providers = new HashMap<String, Resource>();
for (Capability cap : caps) {
Resource resource = cap.getResource();
String id = getSymbolicName(resource) + "|" + getVersion(resource);
Resource prev = providers.get(id);
if (prev != null && prev != resource) {
Region r1 = getRegion(prev);
Region r2 = getRegion(resource);
boolean r2canSeeR1 = isResourceVisibleFromRegion(prev, r2);
boolean r1canSeeR2 = isResourceVisibleFromRegion(resource, r1);
if (r1canSeeR2 && r2canSeeR1) {
// r1 and r2 can see each other
int reqDiff = prev.getRequirements(null).size() - resource.getRequirements(null).size();
if (reqDiff == 0) {
String r1Name = getRegion(prev).getName();
String r2Name = getRegion(resource).getName();
int c = r1Name.compareTo(r2Name);
if (c == 0) {
// One of the resource has to be a bundle, use that one
c = (prev instanceof BundleRevision) ? -1 : +1;
}
resource = c < 0 ? prev : resource;
} else {
// one of the resource has less requirements, so use this one
// This can be the case when one resource has conditionals, which adds further
// requirements to the condition feature.
resource = reqDiff < 0 ? prev : resource;
}
} else {
// only one region can see the other, grab the correct
resource = r1canSeeR2 ? prev : resource;
}
}
providers.put(id, resource);
}
for (Iterator<Capability> it = caps.iterator(); it.hasNext(); ) {
Capability cap = it.next();
if (!providers.values().contains(cap.getResource())) {
it.remove();
}
}
}
// Sort caps
Collections.sort(caps, candidateComparator);
}
return caps;
}
use of io.fabric8.agent.model.Feature in project fabric8 by jboss-fuse.
the class SubsystemResolver method getResourceMapping.
private Map<Resource, String> getResourceMapping(SimpleFilter resourceFilter) {
Map<String, String> flats = getFlatSubsystemsMap();
Map<Resource, List<Wire>> wiring = getWiring();
Map<Resource, String> resources = new HashMap<>();
SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM);
if (wiring != null) {
for (Resource resource : wiring.keySet()) {
if (findMatchingCapability(resourceFilter, resource.getCapabilities(null)) != null) {
// Find the subsystem where this feature is installed
Wire wire = findMatchingWire(sf, wiring.get(resource));
if (wire != null) {
String region = (String) wire.getCapability().getAttributes().get(IDENTITY_NAMESPACE);
region = flats.get(region);
resources.put(resource, region);
}
}
}
}
return resources;
}
use of io.fabric8.agent.model.Feature 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.Feature in project fabric8 by jboss-fuse.
the class CamelProfileScriptTest method testFeatures.
@Test
public void testFeatures() throws Exception {
System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
// System.out.println(executeCommand("shell:info"));
// System.out.println(executeCommand("fabric:info"));
// System.out.println(executeCommand("fabric:profile-list"));
ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
try {
FabricService fabricService = fabricProxy.getService();
Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy).withName("feature-camel").withProfiles("feature-camel").assertProvisioningResult().build();
try {
CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
assertProvisionedFeature(fabricService, curator, containers, "camel-script-javascript", "feature-camel", "scriptengines-javascript");
} finally {
ContainerBuilder.destroy(containers);
}
} finally {
fabricProxy.close();
}
}
Aggregations