use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class DefaultNodeMatcher method typeSpecificMatching.
@Override
protected boolean typeSpecificMatching(NodeTemplate abstractTemplate, LocationResourceTemplate candidate, NodeType candidateType, LocationResources locationResources, MatchingConfiguration matchingConfiguration) {
for (Entry<String, Capability> candidateCapability : safe(candidate.getTemplate().getCapabilities()).entrySet()) {
MatchingFilterDefinition configuredFilterDefinition = matchingConfiguration == null ? null : safe(matchingConfiguration.getCapabilities()).get(candidateCapability.getKey());
Map<String, List<IMatchPropertyConstraint>> configuredFilters = configuredFilterDefinition == null ? null : configuredFilterDefinition.getProperties();
CapabilityType capabilityType = locationResources.getCapabilityTypes().get(candidateCapability.getValue().getType());
// Ignore scalable capabiltiy for matching.
if (!ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) {
Capability templateCapability = safe(abstractTemplate.getCapabilities()).get(candidateCapability.getKey());
if (templateCapability != null && !isValidTemplatePropertiesMatch(templateCapability.getProperties(), candidateCapability.getValue().getProperties(), capabilityType.getProperties(), configuredFilters)) {
return false;
}
}
}
return true;
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class TopologyServiceCore method getIndexedCapabilityTypesFromTopology.
/**
* Get all capability types used in a topology
*
* @param topology the topology to find all relationship types
* @return The map that contains the capability types.
*/
public Map<String, CapabilityType> getIndexedCapabilityTypesFromTopology(Topology topology) {
Map<String, CapabilityType> capabilityTypes = Maps.newHashMap();
if (topology.getNodeTemplates() == null) {
return capabilityTypes;
}
for (Map.Entry<String, NodeTemplate> templateEntry : topology.getNodeTemplates().entrySet()) {
NodeTemplate template = templateEntry.getValue();
if (template.getCapabilities() != null) {
for (Map.Entry<String, Capability> capabilityEntry : template.getCapabilities().entrySet()) {
Capability capability = capabilityEntry.getValue();
if (!capabilityTypes.containsKey(capability.getType())) {
CapabilityType capabilityType = getFromContextIfDefined(CapabilityType.class, capability.getType(), topology.getDependencies(), true);
capabilityTypes.put(capability.getType(), capabilityType);
}
}
}
}
return capabilityTypes;
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class NodeFilterValidationService method validateRequirementFilters.
/**
* Performs validation of the node filters to check that relationships targets the filter requirements.
*/
private List<NodeFiltersTask> validateRequirementFilters(Topology topology, boolean skipInputs) {
List<NodeFiltersTask> toReturnTaskList = Lists.newArrayList();
Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
Map<String, NodeType> nodeTypes = topologyServiceCore.getIndexedNodeTypesFromTopology(topology, false, true, true);
Map<String, CapabilityType> capabilityTypes = topologyServiceCore.getIndexedCapabilityTypesFromTopology(topology);
for (Map.Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
Map<String, RelationshipTemplate> relationshipsMap = nodeTempEntry.getValue().getRelationships();
if (relationshipsMap == null || relationshipsMap.isEmpty()) {
continue;
}
NodeType sourceNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTempEntry.getValue().getType(), topology.getDependencies());
if (sourceNodeType.isAbstract()) {
continue;
}
NodeFiltersTask task = new NodeFiltersTask();
task.setNodeTemplateName(nodeTempEntry.getKey());
task.setCode(TaskCode.NODE_FILTER_INVALID);
task.setComponent(sourceNodeType);
task.setNodeFiltersToSatisfy(Lists.<NodeFilterToSatisfy>newArrayList());
validateFiltersForNode(sourceNodeType, relationshipsMap, topology, nodeTypes, capabilityTypes, task, skipInputs);
if (!task.getNodeFiltersToSatisfy().isEmpty()) {
toReturnTaskList.add(task);
}
}
return toReturnTaskList.isEmpty() ? null : toReturnTaskList;
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class NodeMatchingReplaceModifier method processSpecificReplacement.
@Override
protected void processSpecificReplacement(NodeTemplate replacingNode, NodeTemplate replacedTopologyNode, Set<String> topologyNotMergedProps) {
// Also merge relationships
replacingNode.setRelationships(replacedTopologyNode.getRelationships());
// not miss any capability
for (Map.Entry<String, Capability> locationCapabilityEntry : safe(replacingNode.getCapabilities()).entrySet()) {
// Merge capabilities properties from the topology into the substituted node un-set properties
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, locationCapabilityEntry.getValue().getType());
Capability locationCapability = locationCapabilityEntry.getValue();
Capability abstractCapability = safe(replacedTopologyNode.getCapabilities()).get(locationCapabilityEntry.getKey());
// Ignore injection of location values for scalable capability
if (abstractCapability != null && MapUtils.isNotEmpty(abstractCapability.getProperties())) {
if (capabilityType != null && !ToscaTypeUtils.isOfType(capabilityType, NormativeCapabilityTypes.SCALABLE)) {
locationCapability.setProperties(CollectionUtils.merge(abstractCapability.getProperties(), locationCapability.getProperties(), true, topologyNotMergedProps));
} else {
locationCapability.setProperties(abstractCapability.getProperties());
}
}
}
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class ServiceResourceService method validateRelationshipTypes.
private void validateRelationshipTypes(ServiceResource serviceResource, final NodeType nodeType) {
safe(serviceResource.getCapabilitiesRelationshipTypes()).forEach((capabilityName, relationshipTypeId) -> {
RelationshipType relationshipType = toscaTypeSearchService.findByIdOrFail(RelationshipType.class, relationshipTypeId);
String[] validTargets = relationshipType.getValidTargets();
if (ArrayUtils.isNotEmpty(validTargets)) {
CapabilityDefinition capabilityDefinition = nodeType.getCapabilities().stream().filter(c -> c.getId().equals(capabilityName)).findFirst().get();
Csar csar = toscaTypeSearchService.getArchive(nodeType.getArchiveName(), nodeType.getArchiveVersion());
Set<CSARDependency> allDependencies = new HashSet<>(safe(csar.getDependencies()));
allDependencies.add(new CSARDependency(csar.getName(), csar.getVersion(), csar.getHash()));
CapabilityType capabilityType = toscaTypeSearchService.getElementInDependencies(CapabilityType.class, capabilityDefinition.getType(), allDependencies);
Set<String> allAcceptedTypes = new HashSet<>();
allAcceptedTypes.addAll(capabilityType.getDerivedFrom());
allAcceptedTypes.add(capabilityType.getElementId());
boolean isValid = false;
for (String validTarget : validTargets) {
if (allAcceptedTypes.contains(validTarget)) {
isValid = true;
break;
}
}
if (!isValid) {
throw new IncompatibleHalfRelationshipException("[" + relationshipType.getId() + "] is not compatible with [" + capabilityType.getId() + "]");
}
}
});
safe(serviceResource.getRequirementsRelationshipTypes()).forEach((k, v) -> {
toscaTypeSearchService.findByIdOrFail(RelationshipType.class, v);
});
}
Aggregations