Search in sources :

Example 46 with WorkflowStep

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

Example 47 with WorkflowStep

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;
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep)

Example 48 with WorkflowStep

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;
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep)

Example 49 with WorkflowStep

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());
    }
}
Also used : WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) WorkflowStepWeightComparator(alien4cloud.paas.wf.util.WorkflowStepWeightComparator) LinkedList(java.util.LinkedList)

Example 50 with WorkflowStep

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);
}
Also used : List(java.util.List) Getter(lombok.Getter) Map(java.util.Map) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Set(java.util.Set) HashMap(java.util.HashMap) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ArrayList(java.util.ArrayList) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) HashMap(java.util.HashMap)

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