Search in sources :

Example 61 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class TopologyServiceCore method getIndexedNodeTypesFromDependencies.

private Map<String, NodeType> getIndexedNodeTypesFromDependencies(Map<String, NodeTemplate> nodeTemplates, Set<CSARDependency> dependencies, boolean abstractOnly, boolean useTemplateNameAsKey, boolean failOnTypeNotFound) {
    Map<String, NodeType> nodeTypes = Maps.newHashMap();
    if (nodeTemplates == null) {
        return nodeTypes;
    }
    for (Map.Entry<String, NodeTemplate> template : nodeTemplates.entrySet()) {
        if (!nodeTypes.containsKey(template.getValue().getType())) {
            NodeType nodeType = getFromContextIfDefined(NodeType.class, template.getValue().getType(), dependencies, failOnTypeNotFound);
            if (!abstractOnly || nodeType.isAbstract()) {
                String key = useTemplateNameAsKey ? template.getKey() : template.getValue().getType();
                nodeTypes.put(key, nodeType);
            }
        }
    }
    return nodeTypes;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map)

Example 62 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class NodeFilterValidationService method validateFiltersForNode.

private void validateFiltersForNode(NodeType sourceNodeType, Map<String, RelationshipTemplate> relationshipsMap, Topology topology, Map<String, NodeType> nodeTypes, Map<String, CapabilityType> capabilityTypes, NodeFiltersTask task, boolean skipInputs) {
    Map<String, RequirementDefinition> requirementDefinitionMap = getRequirementsAsMap(sourceNodeType);
    for (Map.Entry<String, RelationshipTemplate> relationshipEntry : relationshipsMap.entrySet()) {
        RequirementDefinition requirementDefinition = requirementDefinitionMap.get(relationshipEntry.getValue().getRequirementName());
        NodeFilter nodeFilter = requirementDefinition.getNodeFilter();
        if (nodeFilter != null) {
            NodeTemplate targetNode = topology.getNodeTemplates().get(relationshipEntry.getValue().getTarget());
            NodeType targetType = nodeTypes.get(relationshipEntry.getValue().getTarget());
            NodeFilterToSatisfy nodeFilterToSatisfy = new NodeFilterToSatisfy();
            nodeFilterToSatisfy.setRelationshipName(relationshipEntry.getKey());
            nodeFilterToSatisfy.setTargetName(targetNode.getName());
            nodeFilterToSatisfy.setMissingCapabilities(Lists.<String>newArrayList());
            nodeFilterToSatisfy.setViolations(Lists.<Violations>newArrayList());
            validateNodeFilter(nodeFilter, targetNode, targetType, capabilityTypes, nodeFilterToSatisfy, skipInputs);
            if (!nodeFilterToSatisfy.getViolations().isEmpty() || !nodeFilterToSatisfy.getMissingCapabilities().isEmpty()) {
                task.getNodeFiltersToSatisfy().add(nodeFilterToSatisfy);
            }
        }
    }
}
Also used : RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) Map(java.util.Map) NodeFilterToSatisfy(alien4cloud.topology.task.NodeFilterToSatisfy) NodeFilter(org.alien4cloud.tosca.model.definitions.NodeFilter)

Example 63 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class TopologyPropertiesValidationService method validateProperties.

/**
 * Validate properties.
 *
 * @param topology
 * @param skipInputProperties whether to skip input properties validation or not. This is in case inputs are not yet processed
 * @return
 */
private List<PropertiesTask> validateProperties(Topology topology, boolean skipInputProperties) {
    List<PropertiesTask> toReturnTaskList = Lists.newArrayList();
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    // create task by nodetemplate
    for (Map.Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
        NodeTemplate nodeTemplate = nodeTempEntry.getValue();
        NodeType relatedIndexedNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
        // do pass if abstract node
        if (relatedIndexedNodeType.isAbstract()) {
            continue;
        }
        validateNodeTemplate(toReturnTaskList, relatedIndexedNodeType, nodeTemplate, nodeTempEntry.getKey(), skipInputProperties);
    }
    return toReturnTaskList.isEmpty() ? null : toReturnTaskList;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) PropertiesTask(alien4cloud.topology.task.PropertiesTask) NodeType(org.alien4cloud.tosca.model.types.NodeType) Map(java.util.Map)

Example 64 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate 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 65 with NodeTemplate

use of org.alien4cloud.tosca.model.templates.NodeTemplate in project alien4cloud by alien4cloud.

the class TopologyServiceInterfaceOverrideCheckerService method findWarnings.

public List<IllegalOperationWarning> findWarnings(Topology topology) {
    Set<IllegalOperationWarning> warnings = Sets.newHashSet();
    Map<String, NodeTemplate> nodeTemplates = topology.getNodeTemplates();
    for (Entry<String, NodeTemplate> nodeTempEntry : nodeTemplates.entrySet()) {
        NodeTemplate nodeTemplate = nodeTempEntry.getValue();
        Map<String, RelationshipTemplate> relationships = nodeTemplate.getRelationships();
        if (relationships != null) {
            for (Entry<String, RelationshipTemplate> entry : relationships.entrySet()) {
                RelationshipTemplate relationshipTemplate = entry.getValue();
                String target = relationshipTemplate.getTarget();
                NodeTemplate targetNodeTemplate = nodeTemplates.get(target);
                boolean serviceIsSource = isService(nodeTemplate);
                boolean serviceIsTarget = isService(targetNodeTemplate);
                if (serviceIsSource || serviceIsTarget) {
                    RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, relationshipTemplate.getType());
                    if (relationshipType != null) {
                        Map<String, Interface> interfaces = relationshipType.getInterfaces();
                        if (interfaces != null) {
                            interfaces.forEach((relationshipName, relationshipInterface) -> {
                                Map<String, Operation> operations = relationshipInterface.getOperations();
                                if (operations != null) {
                                    operations.forEach((operationName, operation) -> {
                                        String serviceName;
                                        if (serviceIsTarget) {
                                            serviceName = nodeTemplate.getName();
                                            switch(operationName.toLowerCase()) {
                                                case "add_source":
                                                case "remove_source":
                                                case "source_changed":
                                                case "post_configure_target":
                                                case "pre_configure_target":
                                                    ImplementationArtifact artifact = operation.getImplementationArtifact();
                                                    boolean stepDoSomething = artifact != null;
                                                    if (stepDoSomething) {
                                                        addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
                                                    }
                                                    break;
                                            }
                                        }
                                        if (serviceIsSource) {
                                            serviceName = targetNodeTemplate.getName();
                                            switch(operationName.toLowerCase()) {
                                                case "add_target":
                                                case "remove_target":
                                                case "target_changed":
                                                case "pre_configure_source":
                                                case "post_configure_source":
                                                    ImplementationArtifact artifact = operation.getImplementationArtifact();
                                                    boolean stepDoSomething = artifact != null;
                                                    if (stepDoSomething) {
                                                        addWarning(warnings, nodeTemplate, relationshipInterface, operationName, serviceName, relationshipTemplate.getType());
                                                    }
                                                    break;
                                            }
                                        }
                                    });
                                }
                            });
                        }
                    }
                }
            }
        }
    }
    return warnings.isEmpty() ? null : new ArrayList<>(warnings);
}
Also used : RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Operation(org.alien4cloud.tosca.model.definitions.Operation) IllegalOperationWarning(alien4cloud.topology.warning.IllegalOperationWarning) ImplementationArtifact(org.alien4cloud.tosca.model.definitions.ImplementationArtifact) ServiceNodeTemplate(org.alien4cloud.tosca.model.templates.ServiceNodeTemplate) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Interface(org.alien4cloud.tosca.model.definitions.Interface)

Aggregations

NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)162 NodeType (org.alien4cloud.tosca.model.types.NodeType)52 Map (java.util.Map)40 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)37 Test (org.junit.Test)32 Capability (org.alien4cloud.tosca.model.templates.Capability)27 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)25 Topology (org.alien4cloud.tosca.model.templates.Topology)22 NotFoundException (alien4cloud.exception.NotFoundException)17 Then (cucumber.api.java.en.Then)15 ScalarPropertyValue (org.alien4cloud.tosca.model.definitions.ScalarPropertyValue)15 HashMap (java.util.HashMap)14 PropertyDefinition (org.alien4cloud.tosca.model.definitions.PropertyDefinition)13 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)13 TopologyDTO (alien4cloud.topology.TopologyDTO)12 ComplexPropertyValue (org.alien4cloud.tosca.model.definitions.ComplexPropertyValue)12 LocationResourceTemplate (alien4cloud.model.orchestrators.locations.LocationResourceTemplate)11 PaaSNodeTemplate (alien4cloud.paas.model.PaaSNodeTemplate)11 DeploymentArtifact (org.alien4cloud.tosca.model.definitions.DeploymentArtifact)10 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)10