use of org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry in project alien4cloud by alien4cloud.
the class TopologyService method processNodeTemplate.
/**
* Process a node template to retrieve filters for node replacements search.
*
* TODO cleanup this method, better return a filter for node rather than adding it to a parameter list.
*
* @param topology The topology for which to search filters.
* @param nodeTempEntry The node template for which to find replacement filter.
* @param nodeTemplatesToFilters The map of filters in which to add the filter for the new Node.
*/
public void processNodeTemplate(final Topology topology, final Entry<String, NodeTemplate> nodeTempEntry, Map<String, Map<String, Set<String>>> nodeTemplatesToFilters) {
String capabilityFilterKey = "capabilities.type";
String requirementFilterKey = "requirements.type";
NodeTemplate template = nodeTempEntry.getValue();
Map<String, RelationshipTemplate> relTemplates = template.getRelationships();
nodeTemplatesToFilters.put(nodeTempEntry.getKey(), null);
// process the node template source of relationships
if (relTemplates != null && !relTemplates.isEmpty()) {
for (RelationshipTemplate relationshipTemplate : relTemplates.values()) {
addFilters(nodeTempEntry.getKey(), requirementFilterKey, relationshipTemplate.getRequirementType(), nodeTemplatesToFilters);
}
}
// process the node template target of relationships
List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTempEntry.getKey(), topology.getNodeTemplates());
for (RelationshipEntry targetRelationshipEntry : targetRelationships) {
addFilters(nodeTempEntry.getKey(), capabilityFilterKey, targetRelationshipEntry.getRelationship().getRequirementType(), nodeTemplatesToFilters);
}
}
use of org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry in project alien4cloud by alien4cloud.
the class TopologyCapabilityBoundsValidationServices method isCapabilityUpperBoundReachedForTarget.
//
public boolean isCapabilityUpperBoundReachedForTarget(String nodeTemplateName, Map<String, NodeTemplate> nodeTemplates, String capabilityName, Set<CSARDependency> dependencies) {
NodeTemplate nodeTemplate = nodeTemplates.get(nodeTemplateName);
NodeType relatedIndexedNodeType = toscaTypeSearchService.getRequiredElementInDependencies(NodeType.class, nodeTemplate.getType(), dependencies);
chekCapability(nodeTemplateName, capabilityName, nodeTemplate);
CapabilityDefinition capabilityDefinition = getCapabilityDefinition(relatedIndexedNodeType.getCapabilities(), capabilityName);
if (capabilityDefinition.getUpperBound() == Integer.MAX_VALUE) {
return false;
}
List<RelationshipEntry> targetRelatedRelationships = TopologyUtils.getTargetRelationships(nodeTemplateName, nodeTemplates);
if (targetRelatedRelationships == null || targetRelatedRelationships.isEmpty()) {
return false;
}
int count = 0;
for (RelationshipEntry relationshipEntry : targetRelatedRelationships) {
if (relationshipEntry.getRelationship().getTargetedCapabilityName().equals(capabilityName)) {
count++;
}
}
return count >= capabilityDefinition.getUpperBound();
}
use of org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry in project alien4cloud by alien4cloud.
the class ReplaceNodeProcessor method updateRelationshipsCapabilitiesRelationships.
private void updateRelationshipsCapabilitiesRelationships(Topology topology, NodeTemplate nodeTemplate) {
List<RelationshipEntry> targetRelationships = TopologyUtils.getTargetRelationships(nodeTemplate.getName(), topology.getNodeTemplates());
for (RelationshipEntry targetRelationshipEntry : targetRelationships) {
RelationshipTemplate targetRelationship = targetRelationshipEntry.getRelationship();
Capability capability = safe(nodeTemplate.getCapabilities()).get(targetRelationship.getTargetedCapabilityName());
if (capability == null || isCapabilityNotOfType(capability, targetRelationship.getRequirementType())) {
Entry<String, Capability> capabilityEntry = NodeTemplateUtils.getCapabilitEntryyByType(nodeTemplate, targetRelationship.getRequirementType());
targetRelationship.setTargetedCapabilityName(capabilityEntry.getKey());
// check that the relationship type is still valid with the new capability
RelationshipType relationshipType = ToscaContext.get(RelationshipType.class, targetRelationship.getType());
if (!isValidRelationship(relationshipType, capabilityEntry.getValue())) {
NodeType sourceNodeType = ToscaContext.get(NodeType.class, targetRelationshipEntry.getSource().getType());
RequirementDefinition requirementDefinition = NodeTypeUtils.getRequirementById(sourceNodeType, targetRelationshipEntry.getRelationship().getRequirementName());
NodeType targetNodeType = ToscaContext.get(NodeType.class, nodeTemplate.getType());
CapabilityDefinition capabilityDefinition = NodeTypeUtils.getCapabilityById(targetNodeType, capabilityEntry.getKey());
RelationshipType validRelationshipType = danglingRequirementService.fetchValidRelationshipType(requirementDefinition, capabilityDefinition);
targetRelationship.setType(validRelationshipType.getElementId());
targetRelationship.setType(validRelationshipType.getElementId());
targetRelationship.setArtifacts(newLinkedHashMap(safe(validRelationshipType.getArtifacts())));
targetRelationship.setAttributes(newLinkedHashMap(safe(validRelationshipType.getAttributes())));
Map<String, AbstractPropertyValue> properties = new LinkedHashMap();
TemplateBuilder.fillProperties(properties, validRelationshipType.getProperties(), null);
targetRelationship.setProperties(properties);
}
}
}
}
Aggregations