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());
}
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());
}
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;
}
Aggregations