Search in sources :

Example 1 with RequirementToSatisfy

use of alien4cloud.topology.task.RequirementToSatisfy 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)

Aggregations

RequirementToSatisfy (alien4cloud.topology.task.RequirementToSatisfy)1 RequirementsTask (alien4cloud.topology.task.RequirementsTask)1 Map (java.util.Map)1 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 NodeType (org.alien4cloud.tosca.model.types.NodeType)1