Search in sources :

Example 11 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class ToscaParserAlien200Test method parseTopologyTemplateWithRelationshipWorkflowMultipleActivities.

@Test
public void parseTopologyTemplateWithRelationshipWorkflowMultipleActivities() throws ParsingException {
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflow-relationship-operation.yml"));
    assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
    assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
    Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
    assertNotNull(wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source"));
    WorkflowStep step = wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source");
    assertTrue(step instanceof RelationshipWorkflowStep);
    RelationshipWorkflowStep relStep = (RelationshipWorkflowStep) step;
    assertTrue(relStep.getTarget().equals("SoftwareComponent"));
    assertTrue(relStep.getTargetRelationship().equals("hostedOnComputeHost"));
    assertTrue(relStep.getOperationHost().equals("SOURCE"));
    assertEquals(1, relStep.getActivities().size());
    assertEquals(1, relStep.getOnSuccess().size());
    assertTrue(relStep.getOnSuccess().contains("SoftwareComponent_hostedOnComputeHost_pre_configure_source_0"));
    // test the second step, create to split activities into steps
    WorkflowStep step_0 = wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source_0");
    assertTrue(step_0 instanceof RelationshipWorkflowStep);
    RelationshipWorkflowStep relStep_0 = (RelationshipWorkflowStep) step_0;
    assertTrue(relStep_0.getTarget().equals("SoftwareComponent"));
    assertTrue(relStep_0.getTargetRelationship().equals("hostedOnComputeHost"));
    assertTrue(relStep_0.getOperationHost().equals("SOURCE"));
    assertEquals(1, relStep_0.getActivities().size());
    assertEquals(1, relStep_0.getOnSuccess().size());
    assertTrue(relStep_0.getOnSuccess().contains("SoftwareComponent_install"));
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) Test(org.junit.Test)

Example 12 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class WorkflowUtils method addOperationStep.

public static WorkflowStep addOperationStep(Workflow wf, String nodeId, String interfaceName, String operationName) {
    WorkflowStep step = createOperationStep(wf, nodeId, interfaceName, operationName);
    wf.addStep(step);
    return step;
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep)

Example 13 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class WorkflowUtils method fillHostId.

/**
 * Compute the wf in order to ensure that all step are tagged with the hostId property.
 * <p/>
 * The hostId is the first (and normally unique) compute found in the ascendency.
 */
public static void fillHostId(Workflow wf, TopologyContext topologyContext) {
    wf.getHosts().clear();
    for (WorkflowStep step : wf.getSteps().values()) {
        if (step instanceof NodeWorkflowStep) {
            if (StringUtils.isEmpty(step.getTarget())) {
                // FIXME when tosca is clear on this point then we might change the model because it's not beautiful
                return;
            }
            String hostId = WorkflowUtils.getRootHostNode(step.getTarget(), topologyContext);
            ((NodeWorkflowStep) step).setHostId(hostId);
            if (hostId != null) {
                wf.getHosts().add(hostId);
            }
        } else if (step instanceof RelationshipWorkflowStep) {
            RelationshipWorkflowStep relationshipWorkflowStep = (RelationshipWorkflowStep) step;
            String sourceHostId = WorkflowUtils.getRootHostNode(relationshipWorkflowStep.getTarget(), topologyContext);
            String targetHostId = WorkflowUtils.getRootHostNode(getRelationshipTarget(relationshipWorkflowStep.getTarget(), relationshipWorkflowStep.getTargetRelationship(), topologyContext), topologyContext);
            relationshipWorkflowStep.setSourceHostId(sourceHostId);
            relationshipWorkflowStep.setTargetHostId(targetHostId);
        }
    }
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)

Example 14 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class WorkflowUtils method addStateStep.

public static WorkflowStep addStateStep(Workflow wf, String nodeId, String stateName) {
    WorkflowStep step = createStateStep(wf, nodeId, stateName);
    wf.addStep(step);
    return step;
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep)

Example 15 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class WorkflowUtils method debugWorkflow.

public static String debugWorkflow(Workflow wf) {
    StringBuilder stringBuilder = new StringBuilder("\n ======> Paste the folowing graph in http://www.webgraphviz.com/  !!\n");
    int subgraphCount = 0;
    stringBuilder.append("\ndigraph ").append(wf.getName()).append(" {");
    stringBuilder.append("\n  node [shape=box];");
    for (String host : wf.getHosts()) {
        stringBuilder.append("\n  subgraph cluster_").append(++subgraphCount).append(" {");
        stringBuilder.append("\n    label = \"").append(host).append("\";\n    color=blue;");
        for (WorkflowStep step : wf.getSteps().values()) {
            if (step instanceof NodeWorkflowStep && host.equals(((NodeWorkflowStep) step).getHostId())) {
                stringBuilder.append("\n    \"").append(step.getName()).append("\";");
            }
        }
        stringBuilder.append("\n  }\n");
    }
    for (WorkflowStep step : wf.getSteps().values()) {
        if (step.getOnSuccess() != null) {
            for (String following : step.getOnSuccess()) {
                stringBuilder.append("\n  \"").append(step.getName()).append("\" -> \"").append(following).append("\";");
            }
        }
        if (step.getOnSuccess() == null || step.getOnSuccess().isEmpty()) {
            stringBuilder.append("\n  \"").append(step.getName()).append("\" -> end;");
        }
        if (step.getPrecedingSteps() == null || step.getPrecedingSteps().isEmpty()) {
            stringBuilder.append("\n  start -> \"").append(step.getName()).append("\";");
        }
    }
    stringBuilder.append("\n  start [shape=doublecircle];\n");
    stringBuilder.append("  end [shape=circle];\n");
    stringBuilder.append("}\n");
    stringBuilder.append("======================\n");
    return stringBuilder.toString();
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep)

Aggregations

WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)51 RelationshipWorkflowStep (org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)24 NodeWorkflowStep (org.alien4cloud.tosca.model.workflow.NodeWorkflowStep)23 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)20 Test (org.junit.Test)17 Path (alien4cloud.paas.wf.model.Path)7 Map (java.util.Map)6 ArrayList (java.util.ArrayList)5 Set (java.util.Set)5 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)5 InconsistentWorkflowException (alien4cloud.paas.wf.exception.InconsistentWorkflowException)4 TopologyDTO (alien4cloud.topology.TopologyDTO)4 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 HashMap (java.util.HashMap)3 LinkedList (java.util.LinkedList)3 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)3 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)3 StringUtils (org.apache.commons.lang3.StringUtils)3