Search in sources :

Example 66 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class TopologyRequirementBoundsValidationServices method validateRequirementsLowerBounds.

/**
 * Perform validation of requirements bounds/occurences for the given topology.
 *
 * @param topology The topology to check
 * @return A list of validation errors (tasks to be done to make the topology compliant).
 */
public List<RequirementsTask> validateRequirementsLowerBounds(Topology topology) {
    List<RequirementsTask> toReturnTaskList = Lists.newArrayList();
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    for (Map.Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
        NodeTemplate nodeTemp = nodeTempEntry.getValue();
        if (nodeTemp.getRequirements() == null) {
            continue;
        }
        NodeType relatedIndexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemp.getType(), topology.getDependencies());
        // do pass if abstract node
        if (relatedIndexedNodeType.isAbstract()) {
            continue;
        }
        RequirementsTask task = new RequirementsTask();
        task.setNodeTemplateName(nodeTempEntry.getKey());
        task.setCode(TaskCode.SATISFY_LOWER_BOUND);
        task.setComponent(relatedIndexedNodeType);
        task.setRequirementsToImplement(Lists.<RequirementToSatisfy>newArrayList());
        if (CollectionUtils.isNotEmpty(relatedIndexedNodeType.getRequirements())) {
            for (RequirementDefinition reqDef : relatedIndexedNodeType.getRequirements()) {
                int count = countRelationshipsForRequirement(nodeTemp, reqDef);
                if (count < reqDef.getLowerBound()) {
                    task.getRequirementsToImplement().add(new RequirementToSatisfy(reqDef.getId(), reqDef.getType(), reqDef.getLowerBound() - count));
                }
            }
            if (CollectionUtils.isNotEmpty(task.getRequirementsToImplement())) {
                toReturnTaskList.add(task);
            }
        }
    }
    return toReturnTaskList.isEmpty() ? null : toReturnTaskList;
}
Also used : RequirementsTask(alien4cloud.topology.task.RequirementsTask) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) RequirementToSatisfy(alien4cloud.topology.task.RequirementToSatisfy) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Map(java.util.Map)

Example 67 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType 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 68 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class WorkflowUtils method getOperation.

/**
 * @return the operation browsing the type hierarchy
 *         FIXME: should we browse hierarchy ? what about order ?
 */
public static Operation getOperation(String nodeTypeName, String interfaceName, String operationName, TopologyContext topologyContext) {
    NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTypeName);
    if (nodeType == null) {
        return null;
    }
    if (nodeType.getInterfaces() == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    Interface interfaceType = nodeType.getInterfaces().get(interfaceName);
    if (interfaceType == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    if (interfaceType.getOperations() == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    Operation operation = interfaceType.getOperations().get(operationName);
    if (interfaceType.getOperations() == null) {
        return getOperationInSuperTypes(nodeType, interfaceName, operationName, topologyContext);
    }
    return operation;
}
Also used : NodeType(org.alien4cloud.tosca.model.types.NodeType) Operation(org.alien4cloud.tosca.model.definitions.Operation) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Example 69 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class WorkflowUtils method isNativeOrSubstitutionNode.

public static boolean isNativeOrSubstitutionNode(String nodeId, TopologyContext topologyContext) {
    NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId);
    if (nodeTemplate == null) {
        return false;
    }
    NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType());
    if (nodeType.isAbstract() || nodeType.getSubstitutionTopologyId() != null) {
        return true;
    }
    // (since these types will be abstract)
    return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, NETWORK_TYPE) || isOfType(nodeType, "tosca.nodes.BlockStorage");
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType)

Example 70 with NodeType

use of org.alien4cloud.tosca.model.types.NodeType in project alien4cloud by alien4cloud.

the class WorkflowUtils method isComputeOrVolume.

public static boolean isComputeOrVolume(String nodeId, TopologyContext topologyContext) {
    NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeId);
    if (nodeTemplate == null) {
        return false;
    }
    NodeType nodeType = topologyContext.findElement(NodeType.class, nodeTemplate.getType());
    return isOfType(nodeType, NormativeComputeConstants.COMPUTE_TYPE) || isOfType(nodeType, "tosca.nodes.BlockStorage");
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType)

Aggregations

NodeType (org.alien4cloud.tosca.model.types.NodeType)156 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)50 Test (org.junit.Test)44 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)26 Set (java.util.Set)26 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)23 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)22 Map (java.util.Map)19 Csar (org.alien4cloud.tosca.model.Csar)19 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)16 HashMap (java.util.HashMap)15 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)15 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)14 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)14 Topology (org.alien4cloud.tosca.model.templates.Topology)9 NotFoundException (alien4cloud.exception.NotFoundException)8 Capability (org.alien4cloud.tosca.model.templates.Capability)8 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)8 MatchingConfiguration (alien4cloud.model.deployment.matching.MatchingConfiguration)7 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7