Search in sources :

Example 6 with Path

use of alien4cloud.paas.wf.model.Path in project alien4cloud by alien4cloud.

the class GraphPathsTest method test2.

/**
 * -- a --
 * -- b --
 */
@Test
public void test2() {
    Workflow wf = new Workflow();
    wf.setName(INSTALL);
    WorkflowStep a = wf.addStep(new SimpleStep("a"));
    WorkflowStep b = wf.addStep(new SimpleStep("b"));
    List<Path> paths = WorkflowGraphUtils.getWorkflowGraphCycles(wf);
    log.info(paths.toString());
}
Also used : Path(alien4cloud.paas.wf.model.Path) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Test(org.junit.Test)

Example 7 with Path

use of alien4cloud.paas.wf.model.Path in project alien4cloud by alien4cloud.

the class GraphPathsTest method testComplexe.

/**
 * <pre>
 *     -- b --      -- e
 *    /        \   /
 * a             d
 *    \        /   \
 *     -- c --      -- f
 * </pre>
 */
@Test
public void testComplexe() {
    Workflow wf = new Workflow();
    wf.setName(INSTALL);
    WorkflowStep a = wf.addStep(new SimpleStep("a"));
    WorkflowStep b = wf.addStep(new SimpleStep("b"));
    WorkflowStep c = wf.addStep(new SimpleStep("c"));
    WorkflowStep d = wf.addStep(new SimpleStep("d"));
    WorkflowStep e = wf.addStep(new SimpleStep("e"));
    WorkflowStep f = wf.addStep(new SimpleStep("f"));
    WorkflowUtils.linkSteps(a, b);
    WorkflowUtils.linkSteps(a, c);
    WorkflowUtils.linkSteps(b, d);
    WorkflowUtils.linkSteps(c, d);
    WorkflowUtils.linkSteps(d, e);
    WorkflowUtils.linkSteps(d, f);
    List<Path> paths = WorkflowGraphUtils.getWorkflowGraphCycles(wf);
    log.info(paths.toString());
}
Also used : Path(alien4cloud.paas.wf.model.Path) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Test(org.junit.Test)

Example 8 with Path

use of alien4cloud.paas.wf.model.Path in project alien4cloud by alien4cloud.

the class WorkflowGraphUtils method getWorkflowGraphCycles.

/**
 * Build the paths of the graph starting from the entry points (steps without predecessors, so connected to 'start').
 * <p>
 * Will also detect orphans brothers in the entire graph (cycles not connected to start).
 */
public static List<Path> getWorkflowGraphCycles(Workflow workflow) {
    SubGraph subGraph = new SubGraph(workflow, stepId -> true);
    List<Path> cycles = new ArrayList<>();
    subGraph.browse(new SimpleGraphConsumer() {

        @Override
        public boolean onNewPath(List<WorkflowStep> path) {
            if (path.size() > 1) {
                Path parentPath = new Path(path.subList(0, path.size() - 1));
                WorkflowStep currentStep = path.get(path.size() - 1);
                if (parentPath.contains(currentStep)) {
                    Path cycle = new Path(path);
                    cycle.setCycle(true);
                    cycle.setLoopingStep(currentStep);
                    cycles.add(cycle);
                    // abort so that do not run into loop
                    return false;
                }
            }
            return true;
        }
    });
    return cycles;
}
Also used : Path(alien4cloud.paas.wf.model.Path) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) ArrayList(java.util.ArrayList)

Aggregations

Path (alien4cloud.paas.wf.model.Path)8 WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)7 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)1 NodeWorkflowStep (org.alien4cloud.tosca.model.workflow.NodeWorkflowStep)1 RelationshipWorkflowStep (org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)1