Search in sources :

Example 1 with Maps.newLinkedHashMap

use of com.google.common.collect.Maps.newLinkedHashMap in project alien4cloud by alien4cloud.

the class ReplaceNodeProcessor method removeTheRelationshipsOnSource.

/**
 * If the node to replace is an target of relationship, we should swapped the relationship on source and clean used workflow steps
 */
private Map<String, Map<String, RelationshipTemplate>> removeTheRelationshipsOnSource(Topology topology, Csar csar, String nodeToReplace) {
    Map<String, Map<String, RelationshipTemplate>> relationshipDeleted = Maps.newLinkedHashMap();
    for (NodeTemplate nodeTemplate : safe(topology.getNodeTemplates()).values()) {
        if (!nodeToReplace.equals(nodeTemplate.getName())) {
            List<String> relationshipsToRemove = Lists.newArrayList();
            for (RelationshipTemplate relationshipTemplate : safe(nodeTemplate.getRelationships()).values()) {
                if (nodeToReplace.equals(relationshipTemplate.getTarget())) {
                    relationshipsToRemove.add(relationshipTemplate.getName());
                    if (!relationshipDeleted.containsKey(relationshipTemplate.getName())) {
                        Map<String, RelationshipTemplate> relationships = Maps.newHashMap();
                        // we save the RelationshipTemplate, so we will preserve the current properties of this relationship
                        relationshipDeleted.put(nodeTemplate.getName(), relationships);
                    }
                    relationshipDeleted.get(nodeTemplate.getName()).put(relationshipTemplate.getName(), relationshipTemplate);
                    // we should remove this relationship to maintain a great a workflow
                    workflowBuilderService.removeRelationship(topology, csar, nodeTemplate.getName(), relationshipTemplate.getName(), relationshipTemplate);
                }
            }
        }
    }
    return relationshipDeleted;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap)

Aggregations

Maps.newLinkedHashMap (com.google.common.collect.Maps.newLinkedHashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1