use of alien4cloud.topology.task.RequirementsTask 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;
}
Aggregations