Search in sources :

Example 41 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class WorkflowStepWeightComparator method compareWorkflowSteps.

public static int compareWorkflowSteps(Topology topology, WorkflowStep l, WorkflowStep r) {
    if (l instanceof RelationshipWorkflowStep) {
        if (r instanceof RelationshipWorkflowStep) {
            RelationshipWorkflowStep lr = (RelationshipWorkflowStep) l;
            RelationshipWorkflowStep rr = (RelationshipWorkflowStep) r;
            if (lr.getOperationHost().equals(RelationshipOperationHost.TARGET.toString())) {
                if (rr.getOperationHost().equals(RelationshipOperationHost.TARGET.toString())) {
                    return 0;
                } else {
                    // l is target operation, r is source operation, execute for source before target so put l after r
                    return 1;
                }
            } else {
                if (rr.getOperationHost().equals(RelationshipOperationHost.TARGET.toString())) {
                    // l is source operation, r is target operation, execute for source before target so put l before r
                    return -1;
                } else {
                    // l and r are source operations
                    if (lr.getTarget().equals(rr.getTarget())) {
                        // l and r are operation concerning the same target
                        NodeTemplate nodeTemplate = topology.getNodeTemplates().get(lr.getTarget());
                        Integer lri = 0;
                        Integer rri = 0;
                        int counter = 0;
                        for (Map.Entry<String, RelationshipTemplate> relationshipTemplateEntry : nodeTemplate.getRelationships().entrySet()) {
                            // Hope that's linked hash map here so order is preserved
                            if (relationshipTemplateEntry.getKey().equals(lr.getTargetRelationship())) {
                                lri = counter;
                            }
                            if (relationshipTemplateEntry.getKey().equals(rr.getTargetRelationship())) {
                                rri = counter;
                            }
                            counter++;
                        }
                        // Execute operation coming from relationship in the same order at the source side
                        return lri.compareTo(rri);
                    } else {
                        // not the same target so don't care about order
                        return 0;
                    }
                }
            }
        } else {
            // execute node step before relationship step
            return -1;
        }
    } else {
        // l is node step
        if (r instanceof RelationshipWorkflowStep) {
            // execute node step before relationship step
            return 1;
        } else {
            // both are node steps then don't care about order
            return 0;
        }
    }
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) Map(java.util.Map)

Example 42 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class WorkflowUtils method getRelationshipTarget.

private static String getRelationshipTarget(String source, String relationshipId, TopologyContext topologyContext) {
    NodeTemplate sourceNode = safe(topologyContext.getTopology().getNodeTemplates()).get(source);
    if (sourceNode == null) {
        throw new NotFoundException("Source " + source + " cannot be found in the topology " + topologyContext.getTopology().getId());
    }
    RelationshipTemplate relationshipTemplate = safe(sourceNode.getRelationships()).get(relationshipId);
    if (relationshipTemplate == null) {
        throw new NotFoundException("Source " + source + " does not have the relationship " + relationshipId + " in the topology " + topologyContext.getTopology().getId());
    }
    return relationshipTemplate.getTarget();
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) NotFoundException(alien4cloud.exception.NotFoundException)

Example 43 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class WorkflowsBuilderService method addRelationship.

public void addRelationship(TopologyContext topologyContext, String nodeTemplateName, String relationshipName) {
    topologyContext.getTopology().getWorkflows().putAll(topologyContext.getTopology().getUnprocessedWorkflows());
    NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeTemplateName);
    RelationshipTemplate relationshipTemplate = nodeTemplate.getRelationships().get(relationshipName);
    for (Workflow wf : topologyContext.getTopology().getWorkflows().values()) {
        AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
        builder.addRelationship(wf, nodeTemplateName, nodeTemplate, relationshipName, relationshipTemplate, topologyContext);
        WorkflowUtils.fillHostId(wf, topologyContext);
    }
    postProcessTopologyWorkflows(topologyContext);
    debugWorkflow(topologyContext.getTopology());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Workflow(org.alien4cloud.tosca.model.workflow.Workflow)

Example 44 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class TopologyUtils method refreshNodeTemplateNameInRelationships.

private static void refreshNodeTemplateNameInRelationships(String oldNodeTemplateName, String newNodeTemplateName, Map<String, RelationshipTemplate> relationshipTemplates) {
    Map<String, String> updatedKeys = Maps.newHashMap();
    for (Map.Entry<String, RelationshipTemplate> relationshipTemplateEntry : relationshipTemplates.entrySet()) {
        String relationshipTemplateId = relationshipTemplateEntry.getKey();
        RelationshipTemplate relationshipTemplate = relationshipTemplateEntry.getValue();
        if (relationshipTemplate.getTarget().equals(oldNodeTemplateName)) {
            relationshipTemplate.setTarget(newNodeTemplateName);
            String formatedOldNodeName = getRelationShipName(relationshipTemplate.getType(), oldNodeTemplateName);
            // if the id/name of the relationship is auto-generated we should update it also as auto-generation is <typeName+targetId>
            if (relationshipTemplateId.equals(formatedOldNodeName)) {
                // check that the new name is not already used (so we won't override another relationship)...
                String validNewRelationshipTemplateId = getNexAvailableName(getRelationShipName(relationshipTemplate.getType(), newNodeTemplateName), "", relationshipTemplates.keySet());
                updatedKeys.put(relationshipTemplateId, validNewRelationshipTemplateId);
            }
        }
    }
    // update the relationship keys if any has been impacted
    for (Map.Entry<String, String> updateKeyEntry : updatedKeys.entrySet()) {
        RelationshipTemplate relationshipTemplate = relationshipTemplates.remove(updateKeyEntry.getKey());
        relationshipTemplates.put(updateKeyEntry.getValue(), relationshipTemplate);
    }
}
Also used : RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Map(java.util.Map)

Example 45 with RelationshipTemplate

use of org.alien4cloud.tosca.model.templates.RelationshipTemplate in project alien4cloud by alien4cloud.

the class DanglingRequirementService method addDanglingNode.

private NodeTemplate addDanglingNode(Topology topology, TopologyContext topologyContext, NodeTemplate nodeTemplate, RequirementDefinition requirementDefinition, NodeType danglingNodeType, RelationshipType danglingRelationshipType, CapabilityDefinition targetCapabilityDefinition) {
    NodeTemplate danglingTemplate = TemplateBuilder.buildNodeTemplate(danglingNodeType);
    // Add the filter as defined in the node type.
    danglingTemplate.setNodeFilter(requirementDefinition.getNodeFilter());
    // generate the dangling template name
    String danglingTemplateName = TopologyUtils.getNexAvailableName(nodeTemplate.getName() + "_" + requirementDefinition.getId(), "_", topology.getNodeTemplates().keySet());
    danglingTemplate.setName(danglingTemplateName);
    topology.getNodeTemplates().put(danglingTemplateName, danglingTemplate);
    workflowsBuilderService.addNode(topologyContext, danglingTemplateName);
    // Add the dangling requirement relationship
    if (nodeTemplate.getRelationships() == null) {
        nodeTemplate.setRelationships(Maps.newHashMap());
    }
    String danglingRelationshipTemplateName = TopologyUtils.getNexAvailableName(nodeTemplate.getName() + "_" + requirementDefinition.getId(), "_", nodeTemplate.getRelationships().keySet());
    RelationshipTemplate relationshipTemplate = new RelationshipTemplate();
    relationshipTemplate.setName(danglingRelationshipTemplateName);
    relationshipTemplate.setTarget(danglingTemplateName);
    String targetCapabilityName = targetCapabilityDefinition == null ? null : targetCapabilityDefinition.getId();
    relationshipTemplate.setTargetedCapabilityName(targetCapabilityName);
    relationshipTemplate.setRequirementName(requirementDefinition.getId());
    relationshipTemplate.setRequirementType(requirementDefinition.getType());
    relationshipTemplate.setType(danglingRelationshipType.getElementId());
    relationshipTemplate.setArtifacts(newLinkedHashMap(safe(danglingRelationshipType.getArtifacts())));
    relationshipTemplate.setAttributes(newLinkedHashMap(safe(danglingRelationshipType.getAttributes())));
    Map<String, AbstractPropertyValue> properties = new LinkedHashMap();
    TemplateBuilder.fillProperties(properties, danglingRelationshipType.getProperties(), null);
    relationshipTemplate.setProperties(properties);
    nodeTemplate.getRelationships().put(danglingRelationshipTemplateName, relationshipTemplate);
    workflowsBuilderService.addRelationship(topologyContext, nodeTemplate.getName(), danglingRelationshipTemplateName);
    // TODO remove this workaround as soon as matchin leverages
    setPropertiesFromFilter(danglingTemplate, danglingNodeType);
    return danglingTemplate;
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) AbstractPropertyValue(org.alien4cloud.tosca.model.definitions.AbstractPropertyValue) LinkedHashMap(java.util.LinkedHashMap) Maps.newLinkedHashMap(com.google.common.collect.Maps.newLinkedHashMap)

Aggregations

RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)47 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)37 Map (java.util.Map)12 Capability (org.alien4cloud.tosca.model.templates.Capability)12 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)11 NodeType (org.alien4cloud.tosca.model.types.NodeType)9 AbstractPropertyValue (org.alien4cloud.tosca.model.definitions.AbstractPropertyValue)7 NotFoundException (alien4cloud.exception.NotFoundException)6 PaaSRelationshipTemplate (alien4cloud.paas.model.PaaSRelationshipTemplate)4 LinkedHashMap (java.util.LinkedHashMap)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 AlreadyExistException (alien4cloud.exception.AlreadyExistException)3 ParsingError (alien4cloud.tosca.parser.ParsingError)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Interface (org.alien4cloud.tosca.model.definitions.Interface)3 RequirementDefinition (org.alien4cloud.tosca.model.definitions.RequirementDefinition)3 Requirement (org.alien4cloud.tosca.model.templates.Requirement)3 CapabilityType (org.alien4cloud.tosca.model.types.CapabilityType)3 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)3