Search in sources :

Example 1 with FilterDefinition

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);
        }
    }
}
Also used : FilterDefinition(org.alien4cloud.tosca.model.definitions.FilterDefinition) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Violations(alien4cloud.topology.task.NodeFilterToSatisfy.Violations) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) Map(java.util.Map)

Example 2 with FilterDefinition

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
                        }
                    }
                }
            }
        }
    }
}
Also used : RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) FilterDefinition(org.alien4cloud.tosca.model.definitions.FilterDefinition) PropertyConstraint(org.alien4cloud.tosca.model.definitions.PropertyConstraint) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) List(java.util.List) ArrayList(java.util.ArrayList) ParsingContext(alien4cloud.tosca.parser.ParsingContext) Capability(org.alien4cloud.tosca.model.templates.Capability) Topology(org.alien4cloud.tosca.model.templates.Topology) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map) NodeFilter(org.alien4cloud.tosca.model.definitions.NodeFilter)

Example 3 with FilterDefinition

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()));
            }
        }
    }
}
Also used : FilterDefinition(org.alien4cloud.tosca.model.definitions.FilterDefinition) CapabilityType(org.alien4cloud.tosca.model.types.CapabilityType) Capability(org.alien4cloud.tosca.model.templates.Capability) List(java.util.List) ScalarPropertyValue(org.alien4cloud.tosca.model.definitions.ScalarPropertyValue) EqualConstraint(org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)

Aggregations

FilterDefinition (org.alien4cloud.tosca.model.definitions.FilterDefinition)3 List (java.util.List)2 Map (java.util.Map)2 Capability (org.alien4cloud.tosca.model.templates.Capability)2 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)2 Violations (alien4cloud.topology.task.NodeFilterToSatisfy.Violations)1 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 ParsingContext (alien4cloud.tosca.parser.ParsingContext)1 ArrayList (java.util.ArrayList)1 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)1 NodeFilter (org.alien4cloud.tosca.model.definitions.NodeFilter)1 PropertyConstraint (org.alien4cloud.tosca.model.definitions.PropertyConstraint)1 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)1 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)1 EqualConstraint (org.alien4cloud.tosca.model.definitions.constraints.EqualConstraint)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1 Topology (org.alien4cloud.tosca.model.templates.Topology)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1