use of org.alien4cloud.tosca.model.workflow.WorkflowStep 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
}
}));
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class CycleDetectionTest method testAutoCycle.
/**
* <pre>
*
* /--|
* a -- b |
* \--|
*
* </pre>
*/
@Test()
public void testAutoCycle() {
WorkflowStep a = wf.addStep(new SimpleStep("a"));
WorkflowStep b = wf.addStep(new SimpleStep("b"));
WorkflowUtils.linkSteps(a, b);
WorkflowUtils.linkSteps(b, b);
processValidation(true, 1);
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class CycleDetectionTest method testOrphanCycle.
/**
* <pre>
*
* o --- c --- d
*
* --
* / \
* a b
* \ /
* --
* </pre>
*/
@Test
public void testOrphanCycle() {
WorkflowStep a = wf.addStep(new SimpleStep("a"));
WorkflowStep b = wf.addStep(new SimpleStep("b"));
WorkflowStep c = wf.addStep(new SimpleStep("c"));
WorkflowStep d = wf.addStep(new SimpleStep("d"));
WorkflowUtils.linkSteps(a, b);
WorkflowUtils.linkSteps(b, a);
WorkflowUtils.linkSteps(c, d);
processValidation(true, 1);
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class CycleDetectionTest method testForkJoinCycle.
/**
* <pre>
* -- b
* /
* a -- e
* \ / \
* -- c -- d --
* </pre>
*/
@Test()
public void testForkJoinCycle() {
WorkflowStep a = wf.addStep(new SimpleStep("a"));
WorkflowStep b = wf.addStep(new SimpleStep("b"));
WorkflowStep c = wf.addStep(new SimpleStep("c"));
WorkflowStep d = wf.addStep(new SimpleStep("d"));
WorkflowStep e = wf.addStep(new SimpleStep("e"));
WorkflowUtils.linkSteps(a, b);
WorkflowUtils.linkSteps(a, c);
WorkflowUtils.linkSteps(c, d);
WorkflowUtils.linkSteps(d, e);
WorkflowUtils.linkSteps(e, c);
processValidation(true, 1);
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class GraphPathsTest method testCycles.
@Test
public void testCycles() {
Workflow wf = new Workflow();
wf.setName(INSTALL);
WorkflowStep a = wf.addStep(new SimpleStep("a"));
WorkflowStep b = wf.addStep(new SimpleStep("b"));
WorkflowStep c = wf.addStep(new SimpleStep("c"));
WorkflowUtils.linkSteps(a, b);
WorkflowUtils.linkSteps(b, c);
WorkflowUtils.linkSteps(c, a);
List<Path> paths = WorkflowGraphUtils.getWorkflowGraphCycles(wf);
System.out.println(paths);
Assert.assertEquals(1, paths.size());
log.info(paths.toString());
}
Aggregations