use of org.alien4cloud.tosca.model.workflow.WorkflowStep 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;
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class WorkflowUtils method addRelationshipOperationStep.
public static WorkflowStep addRelationshipOperationStep(Workflow wf, String nodeId, String relationshipId, String interfaceName, String operationName, String operationHost) {
WorkflowStep step = createRelationshipOperationStep(wf, nodeId, relationshipId, interfaceName, operationName, operationHost);
wf.addStep(step);
return step;
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class WorkflowUtils method addDelegateWorkflowStep.
public static WorkflowStep addDelegateWorkflowStep(Workflow wf, String nodeId) {
WorkflowStep step = createDelegateWorkflowStep(wf, nodeId);
wf.addStep(step);
return step;
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class WorkflowSimplifyService method flattenWorkflow.
private void flattenWorkflow(TopologyContext topologyContext, SubGraph subGraph) {
ComputeNodesWeightsGraphConsumer consumer = new ComputeNodesWeightsGraphConsumer();
subGraph.browse(consumer);
if (consumer.getAllNodes().isEmpty()) {
// This is really strange as we have a node template without any workflow step
return;
}
Map<String, WorkflowStep> allNodes = consumer.getAllNodes();
LinkedList<WorkflowStep> sortedByWeightsSteps = new LinkedList<>(allNodes.values());
sortedByWeightsSteps.sort(new WorkflowStepWeightComparator(consumer.getAllNodeWeights(), topologyContext.getTopology()));
Set<String> allSubGraphNodeIds = allNodes.keySet();
sortedByWeightsSteps.forEach(workflowStep -> {
// Remove all old links between the steps in the graph
workflowStep.removeAllPrecedings(allSubGraphNodeIds);
workflowStep.removeAllFollowings(allSubGraphNodeIds);
});
// Create a sequence with sorted sub graph steps
for (int i = 0; i < sortedByWeightsSteps.size() - 1; i++) {
sortedByWeightsSteps.get(i).addFollowing(sortedByWeightsSteps.get(i + 1).getName());
sortedByWeightsSteps.get(i + 1).addPreceding(sortedByWeightsSteps.get(i).getName());
}
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class SubGraph method browse.
public void browse(GraphConsumer graphConsumer) {
Map<String, WorkflowStep> subGraphSteps = WorkflowGraphUtils.getAllStepsInSubGraph(workflow, filter);
Set<String> allSubGraphNodeIds = subGraphSteps.keySet();
List<WorkflowStep> rootNodes = subGraphSteps.values().stream().filter(node -> Collections.disjoint(node.getPrecedingSteps(), allSubGraphNodeIds)).collect(Collectors.toList());
if (rootNodes.isEmpty() && !subGraphSteps.isEmpty()) {
// It means the whole sub graph is connected between them, we begin anyway with one of the node
rootNodes.add(subGraphSteps.values().iterator().next());
}
Map<String, WorkflowStep> allNodes = new HashMap<>();
for (WorkflowStep rootNode : rootNodes) {
boolean shouldContinue = internalBrowseSubGraph(subGraphSteps, graphConsumer, new ArrayList<>(), rootNode, allNodes);
if (!shouldContinue) {
break;
}
}
graphConsumer.onAllNodes(allNodes);
}
Aggregations