use of org.alien4cloud.tosca.model.definitions.FilterDefinition in project alien4cloud by alien4cloud.
the class NodeFilterValidationService method validateNodeFilterCapabilities.
private void validateNodeFilterCapabilities(NodeFilter nodeFilter, NodeTemplate target, NodeType targetType, Map<String, CapabilityType> capabilityTypes, NodeFilterToSatisfy nodeFilterToSatisfy, boolean skipInputs) {
if (nodeFilter.getCapabilities() == null || nodeFilter.getCapabilities().isEmpty()) {
return;
}
Map<String, FilterDefinition> capabilities = nodeFilter.getCapabilities();
for (Map.Entry<String, FilterDefinition> filterDefinitionEntry : capabilities.entrySet()) {
String capabilityName = filterDefinitionEntry.getKey();
CapabilityDefinition definition = getCapabilityDefinition(targetType, capabilityName);
if (definition == null) {
nodeFilterToSatisfy.getMissingCapabilities().add(capabilityName);
continue;
}
CapabilityType capabilityType = capabilityTypes.get(definition.getType());
List<Violations> violations = validatePropertyFilters(filterDefinitionEntry.getValue().getProperties(), target.getCapabilities().get(definition.getId()).getProperties(), capabilityType.getProperties(), skipInputs);
violations.forEach(violation -> violation.capabilityName = capabilityName);
if (nodeFilterToSatisfy.getViolations() == null) {
nodeFilterToSatisfy.setViolations(violations);
} else {
nodeFilterToSatisfy.getViolations().addAll(violations);
}
}
}
use of org.alien4cloud.tosca.model.definitions.FilterDefinition in project alien4cloud by alien4cloud.
the class SuggestionService method postProcessSuggestionFromArchive.
public void postProcessSuggestionFromArchive(ParsingResult<ArchiveRoot> parsingResult) {
ArchiveRoot archiveRoot = parsingResult.getResult();
ParsingContext context = parsingResult.getContext();
if (archiveRoot.hasToscaTopologyTemplate()) {
Topology topology = archiveRoot.getTopology();
Map<String, NodeTemplate> nodeTemplateMap = topology.getNodeTemplates();
if (MapUtils.isEmpty(nodeTemplateMap)) {
return;
}
for (Map.Entry<String, NodeTemplate> nodeTemplateEntry : nodeTemplateMap.entrySet()) {
NodeTemplate nodeTemplate = nodeTemplateEntry.getValue();
String nodeName = nodeTemplateEntry.getKey();
if (MapUtils.isNotEmpty(nodeTemplate.getProperties())) {
checkProperties(nodeName, nodeTemplate.getProperties(), NodeType.class, nodeTemplate.getType(), context);
}
Map<String, Capability> capabilityMap = nodeTemplate.getCapabilities();
if (MapUtils.isNotEmpty(capabilityMap)) {
for (Map.Entry<String, Capability> capabilityEntry : capabilityMap.entrySet()) {
String capabilityName = capabilityEntry.getKey();
Capability capability = capabilityEntry.getValue();
if (MapUtils.isNotEmpty(capability.getProperties())) {
checkProperties(nodeName + ".capabilities." + capabilityName, capability.getProperties(), CapabilityType.class, capability.getType(), context);
}
}
}
Map<String, RelationshipTemplate> relationshipTemplateMap = nodeTemplate.getRelationships();
if (MapUtils.isNotEmpty(relationshipTemplateMap)) {
for (Map.Entry<String, RelationshipTemplate> relationshipEntry : relationshipTemplateMap.entrySet()) {
String relationshipName = relationshipEntry.getKey();
RelationshipTemplate relationship = relationshipEntry.getValue();
if (MapUtils.isNotEmpty(relationship.getProperties())) {
checkProperties(nodeName + ".relationships." + relationshipName, relationship.getProperties(), RelationshipType.class, relationship.getType(), context);
}
}
}
}
}
if (archiveRoot.hasToscaTypes()) {
Map<String, NodeType> allNodeTypes = archiveRoot.getNodeTypes();
if (MapUtils.isNotEmpty(allNodeTypes)) {
for (Map.Entry<String, NodeType> nodeTypeEntry : allNodeTypes.entrySet()) {
NodeType nodeType = nodeTypeEntry.getValue();
if (nodeType.getRequirements() != null && !nodeType.getRequirements().isEmpty()) {
for (RequirementDefinition requirementDefinition : nodeType.getRequirements()) {
NodeFilter nodeFilter = requirementDefinition.getNodeFilter();
if (nodeFilter != null) {
Map<String, FilterDefinition> capabilitiesFilters = nodeFilter.getCapabilities();
if (MapUtils.isNotEmpty(capabilitiesFilters)) {
for (Map.Entry<String, FilterDefinition> capabilityFilterEntry : capabilitiesFilters.entrySet()) {
FilterDefinition filterDefinition = capabilityFilterEntry.getValue();
for (Map.Entry<String, List<PropertyConstraint>> constraintEntry : filterDefinition.getProperties().entrySet()) {
List<PropertyConstraint> constraints = constraintEntry.getValue();
checkPropertyConstraints("node_filter.capabilities", CapabilityType.class, capabilityFilterEntry.getKey(), constraintEntry.getKey(), constraints, context);
}
}
}
// FIXME check also the value properties filter of a node filter
}
}
}
}
}
}
}
use of org.alien4cloud.tosca.model.definitions.FilterDefinition in project alien4cloud by alien4cloud.
the class DanglingRequirementService method setPropertiesFromFilter.
// TODO This is a workaround as right now matching does not use filter but properties.
private void setPropertiesFromFilter(NodeTemplate danglingTemplate, NodeType danglingNodeType) {
if (danglingTemplate.getNodeFilter() == null) {
return;
}
for (Entry<String, List<PropertyConstraint>> constraintEntry : safe(danglingTemplate.getNodeFilter().getProperties()).entrySet()) {
if (constraintEntry.getValue().size() == 1 && constraintEntry.getValue().get(0) instanceof EqualConstraint && ToscaTypes.isSimple(danglingNodeType.getProperties().get(constraintEntry.getKey()).getType())) {
danglingTemplate.getProperties().put(constraintEntry.getKey(), new ScalarPropertyValue(((EqualConstraint) constraintEntry.getValue().get(0)).getEqual()));
}
}
for (Entry<String, FilterDefinition> capabilityFilter : safe(danglingTemplate.getNodeFilter().getCapabilities()).entrySet()) {
Capability capability = getCapability(danglingTemplate, capabilityFilter.getKey());
CapabilityType capabilityType = ToscaContext.get(CapabilityType.class, capability.getType());
for (Entry<String, List<PropertyConstraint>> constraintEntry : safe(capabilityFilter.getValue().getProperties()).entrySet()) {
if (constraintEntry.getValue().size() == 1 && constraintEntry.getValue().get(0) instanceof EqualConstraint && ToscaTypes.isSimple(capabilityType.getProperties().get(constraintEntry.getKey()).getType())) {
capability.getProperties().put(constraintEntry.getKey(), new ScalarPropertyValue(((EqualConstraint) constraintEntry.getValue().get(0)).getEqual()));
}
}
}
}
Aggregations