Search in sources :

Example 41 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class AbstractWorkflowBuilder method connectStepTo.

void connectStepTo(Workflow wf, String stepId, String[] stepNames) {
    WorkflowStep from = wf.getSteps().get(stepId);
    if (from == null) {
        throw new InconsistentWorkflowException(String.format("Inconsistent workflow: a step nammed '%s' can not be found while it's referenced else where ...", stepId));
    }
    for (String following : stepNames) {
        WorkflowStep followingStep = wf.getSteps().get(following);
        WorkflowUtils.linkSteps(from, followingStep);
    }
}
Also used : InconsistentWorkflowException(alien4cloud.paas.wf.exception.InconsistentWorkflowException) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep)

Example 42 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class AbstractWorkflowBuilder method swapSteps.

/**
 * Swap steps means:
 * <ul>
 * <li>The connection between step and target is inverted.
 * <li>All step's predecessors become predecessors of target & vice versa
 * <li>All step's followers become followers of target & vice versa
 * </ul>
 * That's all folks !
 */
public void swapSteps(Workflow wf, String stepId, String targetId) {
    WorkflowStep step = wf.getSteps().get(stepId);
    WorkflowStep target = wf.getSteps().get(targetId);
    unlinkSteps(step, target);
    List<WorkflowStep> stepPredecessors = removePredecessors(wf, step);
    List<WorkflowStep> stepFollowers = removeFollowers(wf, step);
    List<WorkflowStep> targetPredecessors = removePredecessors(wf, target);
    List<WorkflowStep> targetFollowers = removeFollowers(wf, target);
    associateFollowers(step, targetFollowers);
    associateFollowers(target, stepFollowers);
    associatePredecessors(step, targetPredecessors);
    associatePredecessors(target, stepPredecessors);
    WorkflowUtils.linkSteps(target, step);
}
Also used : NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep)

Example 43 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class AbstractWorkflowBuilder method insertActivityStep.

private void insertActivityStep(Workflow wf, String stepId, String target, String targetRelationship, AbstractWorkflowActivity activity) {
    WorkflowStep lastStep = wf.getSteps().get(stepId);
    String stepBeforeId = null;
    if (lastStep.getPrecedingSteps() != null && lastStep.getPrecedingSteps().size() == 1) {
        stepBeforeId = lastStep.getPrecedingSteps().iterator().next();
    }
    WorkflowStep insertedStep = addActivityStep(wf, target, targetRelationship, activity);
    WorkflowUtils.linkSteps(insertedStep, lastStep);
    if (stepBeforeId != null) {
        WorkflowStep stepBefore = wf.getSteps().get(stepBeforeId);
        unlinkSteps(stepBefore, lastStep);
        WorkflowUtils.linkSteps(stepBefore, insertedStep);
    }
}
Also used : NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep)

Example 44 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class AbstractWorkflowBuilder method addActivityStep.

private WorkflowStep addActivityStep(Workflow wf, String target, String targetRelationship, AbstractWorkflowActivity activity) {
    WorkflowStep step;
    if (StringUtils.isEmpty(targetRelationship)) {
        step = new NodeWorkflowStep();
    } else {
        RelationshipWorkflowStep relationshipWorkflowStep = new RelationshipWorkflowStep();
        relationshipWorkflowStep.setTargetRelationship(targetRelationship);
        step = relationshipWorkflowStep;
    }
    step.setTarget(target);
    step.setActivity(activity);
    step.setName(WorkflowUtils.buildStepName(wf, step, 0));
    wf.addStep(step);
    return step;
}
Also used : NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)

Example 45 with WorkflowStep

use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.

the class DefaultWorkflowBuilder method addNode.

@Override
public void addNode(Workflow workflow, String nodeId, TopologyContext topologyContext, boolean isCompute) {
    if (WorkflowUtils.isNativeOrSubstitutionNode(nodeId, topologyContext)) {
        // for a native node, we just add a sub-workflow step
        WorkflowUtils.addDelegateWorkflowStep(workflow, nodeId);
    } else {
        NodeDeclarativeWorkflow nodeDeclarativeWorkflow = defaultDeclarativeWorkflows.getNodeWorkflows().get(workflow.getName());
        // only trigger this method if it's a default workflow
        if (nodeDeclarativeWorkflow != null) {
            // Create all the states of the workflow at first
            Map<String, WorkflowStep> statesSteps = safe(nodeDeclarativeWorkflow.getStates()).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, stateEntry -> WorkflowUtils.addStateStep(workflow, nodeId, stateEntry.getKey())));
            // Create all the operations of the workflow at first
            Map<String, WorkflowStep> operationSteps = safe(nodeDeclarativeWorkflow.getOperations()).entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, operationEntry -> WorkflowUtils.addOperationStep(workflow, nodeId, ToscaNodeLifecycleConstants.STANDARD_SHORT, operationEntry.getKey())));
            Steps steps = new Steps(operationSteps, statesSteps, null);
            // Declare dependencies on the states steps
            safe(nodeDeclarativeWorkflow.getStates()).forEach((stateName, stateDependencies) -> declareStepDependencies(stateDependencies, steps.getStateStep(stateName), steps));
            // Declare dependencies on the operation steps
            safe(nodeDeclarativeWorkflow.getOperations()).forEach((operationName, operationDependencies) -> declareStepDependencies(operationDependencies, steps.getOperationStep(operationName), steps));
        }
    }
}
Also used : ToscaNodeLifecycleConstants(alien4cloud.paas.plan.ToscaNodeLifecycleConstants) RelationshipWeavingDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.RelationshipWeavingDeclarativeWorkflow) OperationDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.OperationDeclarativeWorkflow) ToscaRelationshipLifecycleConstants(alien4cloud.paas.plan.ToscaRelationshipLifecycleConstants) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) ArrayList(java.util.ArrayList) DefaultDeclarativeWorkflows(org.alien4cloud.tosca.model.workflow.declarative.DefaultDeclarativeWorkflows) List(java.util.List) RelationshipDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.RelationshipDeclarativeWorkflow) NodeDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.NodeDeclarativeWorkflow) Map(java.util.Map) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipWeaving(org.alien4cloud.tosca.model.workflow.declarative.RelationshipWeaving) RelationshipOperationHost(org.alien4cloud.tosca.model.workflow.declarative.RelationshipOperationHost) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Steps(alien4cloud.paas.wf.util.Steps) Collections(java.util.Collections) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) WorkflowUtils(alien4cloud.paas.wf.util.WorkflowUtils) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Steps(alien4cloud.paas.wf.util.Steps) NodeDeclarativeWorkflow(org.alien4cloud.tosca.model.workflow.declarative.NodeDeclarativeWorkflow) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Map(java.util.Map)

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