use of org.alien4cloud.tosca.editor.operations.workflow.RemoveEdgeOperation in project yorc-a4c-plugin by ystia.
the class OpenStackBSComputeWFModifier method doProcess.
private void doProcess(Topology topology, FlowExecutionContext context) {
Csar csar = new Csar(topology.getArchiveName(), topology.getArchiveVersion());
Workflow installWF = topology.getWorkflows().get("install");
Workflow uninstallWF = topology.getWorkflows().get("uninstall");
Set<NodeTemplate> bsSet = TopologyNavigationUtil.getNodesOfType(topology, YORC_OPENSTACK_BS_TYPE, true);
// Let's process all BS
bsSet.forEach(bs -> safe(bs.getRelationships()).forEach((rn, rt) -> {
if ("tosca.capabilities.Attachment".equals(rt.getRequirementType())) {
// Attachment found
context.getLog().info("Found a BlockStorage <{}> with an attachment on <{}>. Let's swap their workflow steps to match Yorc " + "expectations.", bs.getName(), rt.getTarget());
String computeNodeName = rt.getTarget();
// Now lets locate corresponding wf steps in install wf
for (Map.Entry<String, WorkflowStep> workflowStepEntry : installWF.getSteps().entrySet()) {
if (workflowStepEntry.getValue().getTarget().equals(bs.getName())) {
for (String precedingStepName : workflowStepEntry.getValue().getPrecedingSteps()) {
WorkflowStep precedingStep = installWF.getSteps().get(precedingStepName);
if (precedingStep.getTarget().equals(computeNodeName)) {
// We do not use swap operation here as it may mess up other workflow edges
// First remove the edge between steps
RemoveEdgeOperation removeEdgeOperation = new RemoveEdgeOperation();
removeEdgeOperation.setWorkflowName(installWF.getName());
removeEdgeOperation.setFromStepId(precedingStepName);
removeEdgeOperation.setToStepId(workflowStepEntry.getKey());
log.debug("Swapping {} with target {}", precedingStepName, workflowStepEntry.getKey());
removeEdgeProcessor.process(csar, topology, removeEdgeOperation);
// Then reconnect them in the right sequence
ConnectStepFromOperation connectStepFromOperation = new ConnectStepFromOperation();
connectStepFromOperation.setWorkflowName(installWF.getName());
connectStepFromOperation.setFromStepIds(new String[] { workflowStepEntry.getKey() });
connectStepFromOperation.setToStepId(precedingStepName);
connectStepFromProcessor.process(csar, topology, connectStepFromOperation);
break;
}
}
break;
}
}
// Now lets locate corresponding wf steps in uninstall wf
for (Map.Entry<String, WorkflowStep> workflowStepEntry : uninstallWF.getSteps().entrySet()) {
if (workflowStepEntry.getValue().getTarget().equals(bs.getName())) {
for (String onSuccessStepName : workflowStepEntry.getValue().getOnSuccess()) {
WorkflowStep onSuccessStep = uninstallWF.getSteps().get(onSuccessStepName);
if (onSuccessStep.getTarget().equals(computeNodeName)) {
// We do not use swap operation here as it may mess up other workflow edges
// First remove the edge between steps
RemoveEdgeOperation removeEdgeOperation = new RemoveEdgeOperation();
removeEdgeOperation.setWorkflowName(uninstallWF.getName());
removeEdgeOperation.setFromStepId(workflowStepEntry.getKey());
removeEdgeOperation.setToStepId(onSuccessStepName);
log.debug("Swapping {} with target {}", onSuccessStepName, workflowStepEntry.getKey());
removeEdgeProcessor.process(csar, topology, removeEdgeOperation);
// Then reconnect them in the right sequence
ConnectStepFromOperation connectStepFromOperation = new ConnectStepFromOperation();
connectStepFromOperation.setWorkflowName(uninstallWF.getName());
connectStepFromOperation.setFromStepIds(new String[] { onSuccessStepName });
connectStepFromOperation.setToStepId(workflowStepEntry.getKey());
connectStepFromProcessor.process(csar, topology, connectStepFromOperation);
break;
}
}
break;
}
}
// Start & Stop make no sense for those kind of nodes in Yorc as those operations are not implemented.
// Do not change those WFs
}
}));
}
Aggregations