use of alien4cloud.paas.wf.util.WorkflowStepWeightComparator 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());
}
}
Aggregations