Search in sources :

Example 1 with RelationshipEntry

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);
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) RelationshipEntry(org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry)

Example 2 with RelationshipEntry

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();
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipEntry(org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition)

Example 3 with RelationshipEntry

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);
            }
        }
    }
}
Also used : Capability(org.alien4cloud.tosca.model.templates.Capability) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) RequirementDefinition(org.alien4cloud.tosca.model.definitions.RequirementDefinition) LinkedHashMap(java.util.LinkedHashMap) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap) RelationshipEntry(org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NodeType(org.alien4cloud.tosca.model.types.NodeType) CapabilityDefinition(org.alien4cloud.tosca.model.definitions.CapabilityDefinition) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)

Aggregations

RelationshipEntry (org.alien4cloud.tosca.utils.TopologyUtils.RelationshipEntry)3 CapabilityDefinition (org.alien4cloud.tosca.model.definitions.CapabilityDefinition)2 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)2 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)2 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 Maps.newLinkedHashMap (com.google.common.collect.Maps.newLinkedHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)1 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)1 Capability (org.alien4cloud.tosca.model.templates.Capability)1 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)1