use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class WorkflowUtils method cloneStep.
public static WorkflowStep cloneStep(WorkflowStep step) {
WorkflowStep cloned;
if (step instanceof NodeWorkflowStep) {
NodeWorkflowStep nodeWorkflowStep = (NodeWorkflowStep) step;
cloned = new NodeWorkflowStep();
((NodeWorkflowStep) cloned).setHostId(nodeWorkflowStep.getHostId());
} else {
RelationshipWorkflowStep relationshipWorkflowStep = (RelationshipWorkflowStep) step;
cloned = new RelationshipWorkflowStep();
((RelationshipWorkflowStep) cloned).setTargetRelationship(relationshipWorkflowStep.getTargetRelationship());
((RelationshipWorkflowStep) cloned).setSourceHostId(relationshipWorkflowStep.getSourceHostId());
((RelationshipWorkflowStep) cloned).setTargetHostId(relationshipWorkflowStep.getTargetHostId());
}
cloned.setActivities(step.getActivities());
cloned.setFilter(step.getFilter());
cloned.setName(step.getName());
cloned.setOnFailure(step.getOnFailure());
cloned.setOnSuccess(new HashSet<>(step.getOnSuccess()));
cloned.setOperationHost(step.getOperationHost());
cloned.setPrecedingSteps(new HashSet<>(step.getPrecedingSteps()));
cloned.setTarget(step.getTarget());
return cloned;
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class WorkflowUtils method processInlineWorkflow.
private static void processInlineWorkflow(Map<String, Workflow> workflowMap, Workflow workflow) {
final Set<String> newInlinedStepNames = new HashSet<>();
// Clone the map as we iterate and in the same time modify it
Maps.newHashMap(workflow.getSteps()).entrySet().stream().filter(entry -> entry.getValue().getActivity() instanceof InlineWorkflowActivity).forEach(inlinedStepEntry -> {
String inlinedStepName = inlinedStepEntry.getKey();
WorkflowStep inlinedStep = inlinedStepEntry.getValue();
InlineWorkflowActivity inlineWorkflowActivity = (InlineWorkflowActivity) inlinedStep.getActivity();
String inlinedName = inlineWorkflowActivity.getInline();
Workflow inlined = workflowMap.get(inlinedName);
if (inlined == null) {
throw new NotFoundException("Inlined workflow " + inlinedName);
}
Map<String, WorkflowStep> generatedSteps = cloneSteps(inlined.getSteps());
Map<String, WorkflowStep> generatedStepsWithNewNames = generatedSteps.entrySet().stream().collect(Collectors.toMap(entry -> {
String newName = generateNewWfStepNameWithPrefix(inlinedStepEntry.getKey() + "_", workflow.getSteps().keySet(), newInlinedStepNames, entry.getKey());
newInlinedStepNames.add(newName);
if (!newName.equals(entry.getKey())) {
entry.getValue().setName(newName);
generatedSteps.forEach((generatedStepId, generatedStep) -> {
if (generatedStep.removeFollowing(entry.getKey())) {
generatedStep.addFollowing(newName);
}
if (generatedStep.removePreceding(entry.getKey())) {
generatedStep.addPreceding(newName);
}
});
}
return newName;
}, Map.Entry::getValue));
// Find all root steps of the workflow and link them to the parent workflows
final Map<String, WorkflowStep> rootInlinedSteps = generatedStepsWithNewNames.values().stream().filter(generatedStepWithNewName -> generatedStepWithNewName.getPrecedingSteps().isEmpty()).peek(rootInlinedStep -> rootInlinedStep.addAllPrecedings(inlinedStep.getPrecedingSteps())).collect(Collectors.toMap(WorkflowStep::getName, rootInlinedStep -> rootInlinedStep));
inlinedStep.getPrecedingSteps().forEach(precedingStepName -> {
WorkflowStep precedingStep = workflow.getSteps().get(precedingStepName);
precedingStep.removeFollowing(inlinedStepName);
precedingStep.addAllFollowings(rootInlinedSteps.keySet());
});
// Find all leaf steps of the workflow and link them to the parent workflows
final Map<String, WorkflowStep> leafInlinedSteps = generatedStepsWithNewNames.values().stream().filter(generatedStepWithNewName -> generatedStepWithNewName.getOnSuccess().isEmpty()).peek(leafInlinedStep -> leafInlinedStep.addAllFollowings(inlinedStep.getOnSuccess())).collect(Collectors.toMap(WorkflowStep::getName, leafInlinedStep -> leafInlinedStep));
inlinedStep.getOnSuccess().forEach(onSuccessStepName -> {
WorkflowStep onSuccessStep = workflow.getSteps().get(onSuccessStepName);
onSuccessStep.removePreceding(inlinedStepName);
onSuccessStep.addAllPrecedings(leafInlinedSteps.keySet());
});
// Remove the inlined step and replace by other workflow's steps
workflow.getSteps().remove(inlinedStepName);
workflow.addAllSteps(generatedStepsWithNewNames);
});
// Check if the workflow contains inline activity event after processing
boolean processedWorkflowContainsInline = workflow.getSteps().values().stream().anyMatch(step -> step.getActivity() instanceof InlineWorkflowActivity);
if (processedWorkflowContainsInline) {
// Recursively process inline workflow until no step is inline workflow
processInlineWorkflow(workflowMap, workflow);
}
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class AbstractWorkflowBuilder method removeEdge.
public void removeEdge(Workflow wf, String from, String to) {
WorkflowStep fromStep = wf.getSteps().get(from);
if (fromStep == null) {
throw new InconsistentWorkflowException(String.format("Inconsistent workflow: a step nammed '%s' can not be found while it's referenced else where ...", from));
}
WorkflowStep toStep = wf.getSteps().get(to);
if (toStep == null) {
throw new InconsistentWorkflowException(String.format("Inconsistent workflow: a step nammed '%s' can not be found while it's referenced else where ...", to));
}
fromStep.removeFollowing(to);
toStep.removePreceding(from);
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class AbstractWorkflowBuilder method removePredecessors.
private List<WorkflowStep> removePredecessors(Workflow wf, WorkflowStep step) {
List<WorkflowStep> result = Lists.newArrayList();
if (step.getPrecedingSteps() == null || step.getPrecedingSteps().size() == 0) {
return result;
}
Object[] precedings = step.getPrecedingSteps().toArray();
for (Object precedingId : precedings) {
WorkflowStep precedingStep = wf.getSteps().get(precedingId);
unlinkSteps(precedingStep, step);
result.add(precedingStep);
}
return result;
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class AbstractWorkflowBuilder method connectStepFrom.
void connectStepFrom(Workflow wf, String stepId, String[] stepNames) {
WorkflowStep to = wf.getSteps().get(stepId);
if (to == 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 preceding : stepNames) {
WorkflowStep precedingStep = wf.getSteps().get(preceding);
if (precedingStep == null) {
throw new InconsistentWorkflowException(String.format("Inconsistent workflow: a step nammed '%s' can not be found while it's referenced else where ...", preceding));
}
WorkflowUtils.linkSteps(precedingStep, to);
}
}
Aggregations