use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parseTopologyTemplateWithRelationshipWorkflowMultipleActivities.
@Test
public void parseTopologyTemplateWithRelationshipWorkflowMultipleActivities() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflow-relationship-operation.yml"));
assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
assertNotNull(wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source"));
WorkflowStep step = wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source");
assertTrue(step instanceof RelationshipWorkflowStep);
RelationshipWorkflowStep relStep = (RelationshipWorkflowStep) step;
assertTrue(relStep.getTarget().equals("SoftwareComponent"));
assertTrue(relStep.getTargetRelationship().equals("hostedOnComputeHost"));
assertTrue(relStep.getOperationHost().equals("SOURCE"));
assertEquals(1, relStep.getActivities().size());
assertEquals(1, relStep.getOnSuccess().size());
assertTrue(relStep.getOnSuccess().contains("SoftwareComponent_hostedOnComputeHost_pre_configure_source_0"));
// test the second step, create to split activities into steps
WorkflowStep step_0 = wf.getSteps().get("SoftwareComponent_hostedOnComputeHost_pre_configure_source_0");
assertTrue(step_0 instanceof RelationshipWorkflowStep);
RelationshipWorkflowStep relStep_0 = (RelationshipWorkflowStep) step_0;
assertTrue(relStep_0.getTarget().equals("SoftwareComponent"));
assertTrue(relStep_0.getTargetRelationship().equals("hostedOnComputeHost"));
assertTrue(relStep_0.getOperationHost().equals("SOURCE"));
assertEquals(1, relStep_0.getActivities().size());
assertEquals(1, relStep_0.getOnSuccess().size());
assertTrue(relStep_0.getOnSuccess().contains("SoftwareComponent_install"));
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class WorkflowUtils method addOperationStep.
public static WorkflowStep addOperationStep(Workflow wf, String nodeId, String interfaceName, String operationName) {
WorkflowStep step = createOperationStep(wf, nodeId, interfaceName, operationName);
wf.addStep(step);
return step;
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class WorkflowUtils method fillHostId.
/**
* Compute the wf in order to ensure that all step are tagged with the hostId property.
* <p/>
* The hostId is the first (and normally unique) compute found in the ascendency.
*/
public static void fillHostId(Workflow wf, TopologyContext topologyContext) {
wf.getHosts().clear();
for (WorkflowStep step : wf.getSteps().values()) {
if (step instanceof NodeWorkflowStep) {
if (StringUtils.isEmpty(step.getTarget())) {
// FIXME when tosca is clear on this point then we might change the model because it's not beautiful
return;
}
String hostId = WorkflowUtils.getRootHostNode(step.getTarget(), topologyContext);
((NodeWorkflowStep) step).setHostId(hostId);
if (hostId != null) {
wf.getHosts().add(hostId);
}
} else if (step instanceof RelationshipWorkflowStep) {
RelationshipWorkflowStep relationshipWorkflowStep = (RelationshipWorkflowStep) step;
String sourceHostId = WorkflowUtils.getRootHostNode(relationshipWorkflowStep.getTarget(), topologyContext);
String targetHostId = WorkflowUtils.getRootHostNode(getRelationshipTarget(relationshipWorkflowStep.getTarget(), relationshipWorkflowStep.getTargetRelationship(), topologyContext), topologyContext);
relationshipWorkflowStep.setSourceHostId(sourceHostId);
relationshipWorkflowStep.setTargetHostId(targetHostId);
}
}
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class WorkflowUtils method addStateStep.
public static WorkflowStep addStateStep(Workflow wf, String nodeId, String stateName) {
WorkflowStep step = createStateStep(wf, nodeId, stateName);
wf.addStep(step);
return step;
}
use of org.alien4cloud.tosca.model.workflow.WorkflowStep in project alien4cloud by alien4cloud.
the class WorkflowUtils method debugWorkflow.
public static String debugWorkflow(Workflow wf) {
StringBuilder stringBuilder = new StringBuilder("\n ======> Paste the folowing graph in http://www.webgraphviz.com/ !!\n");
int subgraphCount = 0;
stringBuilder.append("\ndigraph ").append(wf.getName()).append(" {");
stringBuilder.append("\n node [shape=box];");
for (String host : wf.getHosts()) {
stringBuilder.append("\n subgraph cluster_").append(++subgraphCount).append(" {");
stringBuilder.append("\n label = \"").append(host).append("\";\n color=blue;");
for (WorkflowStep step : wf.getSteps().values()) {
if (step instanceof NodeWorkflowStep && host.equals(((NodeWorkflowStep) step).getHostId())) {
stringBuilder.append("\n \"").append(step.getName()).append("\";");
}
}
stringBuilder.append("\n }\n");
}
for (WorkflowStep step : wf.getSteps().values()) {
if (step.getOnSuccess() != null) {
for (String following : step.getOnSuccess()) {
stringBuilder.append("\n \"").append(step.getName()).append("\" -> \"").append(following).append("\";");
}
}
if (step.getOnSuccess() == null || step.getOnSuccess().isEmpty()) {
stringBuilder.append("\n \"").append(step.getName()).append("\" -> end;");
}
if (step.getPrecedingSteps() == null || step.getPrecedingSteps().isEmpty()) {
stringBuilder.append("\n start -> \"").append(step.getName()).append("\";");
}
}
stringBuilder.append("\n start [shape=doublecircle];\n");
stringBuilder.append(" end [shape=circle];\n");
stringBuilder.append("}\n");
stringBuilder.append("======================\n");
return stringBuilder.toString();
}
Aggregations