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