use of alien4cloud.exception.NotFoundException 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 alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class WorkflowsBuilderService method swapSteps.
public void swapSteps(Topology topology, Csar csar, String workflowName, String stepId, String targetId) {
TopologyContext topologyContext = buildTopologyContext(topology, csar);
Workflow wf = topology.getWorkflows().get(workflowName);
if (wf == null) {
throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
}
AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
builder.swapSteps(wf, stepId, targetId);
WorkflowUtils.fillHostId(wf, topologyContext);
if (log.isDebugEnabled()) {
log.debug(WorkflowUtils.debugWorkflow(wf));
}
workflowValidator.validate(topologyContext, wf);
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class WorkflowsBuilderService method addActivity.
public void addActivity(Topology topology, Csar csar, String workflowName, String relatedStepId, boolean before, String target, String targetRelationship, AbstractWorkflowActivity activity) {
Workflow wf = topology.getWorkflows().get(workflowName);
if (wf == null) {
throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
}
TopologyContext topologyContext = buildTopologyContext(topology, csar);
AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
builder.addActivity(wf, relatedStepId, before, target, targetRelationship, activity, topologyContext);
WorkflowUtils.fillHostId(wf, topologyContext);
if (log.isDebugEnabled()) {
log.debug(WorkflowUtils.debugWorkflow(wf));
}
workflowValidator.validate(topologyContext, wf);
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class WorkflowsBuilderService method removeStep.
public void removeStep(Topology topology, Csar csar, String workflowName, String stepId) {
TopologyContext topologyContext = buildTopologyContext(topology, csar);
Workflow wf = topology.getWorkflows().get(workflowName);
if (wf == null) {
throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
}
AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
builder.removeStep(wf, stepId, false);
if (log.isDebugEnabled()) {
log.debug(WorkflowUtils.debugWorkflow(wf));
}
workflowValidator.validate(topologyContext, wf);
}
use of alien4cloud.exception.NotFoundException in project alien4cloud by alien4cloud.
the class WorkflowsBuilderService method removeEdge.
public Workflow removeEdge(Topology topology, Csar csar, String workflowName, String from, String to) {
TopologyContext topologyContext = buildTopologyContext(topology, csar);
Workflow wf = topology.getWorkflows().get(workflowName);
if (wf == null) {
throw new NotFoundException(String.format("The workflow '%s' can not be found", workflowName));
}
AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
builder.removeEdge(wf, from, to);
workflowValidator.validate(topologyContext, wf);
return wf;
}
Aggregations