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;
}
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);
}
}
}
}
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;
}
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;
}
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);
}
Aggregations