use of org.alien4cloud.tosca.model.workflow.Workflow in project alien4cloud by alien4cloud.
the class WorkflowsBuilderService method addRelationship.
public void addRelationship(TopologyContext topologyContext, String nodeTemplateName, String relationshipName) {
topologyContext.getTopology().getWorkflows().putAll(topologyContext.getTopology().getUnprocessedWorkflows());
NodeTemplate nodeTemplate = topologyContext.getTopology().getNodeTemplates().get(nodeTemplateName);
RelationshipTemplate relationshipTemplate = nodeTemplate.getRelationships().get(relationshipName);
for (Workflow wf : topologyContext.getTopology().getWorkflows().values()) {
AbstractWorkflowBuilder builder = getWorkflowBuilder(topologyContext.getDSLVersion(), wf);
builder.addRelationship(wf, nodeTemplateName, nodeTemplate, relationshipName, relationshipTemplate, topologyContext);
WorkflowUtils.fillHostId(wf, topologyContext);
}
postProcessTopologyWorkflows(topologyContext);
debugWorkflow(topologyContext.getTopology());
}
use of org.alien4cloud.tosca.model.workflow.Workflow in project alien4cloud by alien4cloud.
the class WorkflowsBuilderService method postProcessTopologyWorkflows.
public void postProcessTopologyWorkflows(TopologyContext topologyContext) {
topologyContext.getTopology().getUnprocessedWorkflows().putAll(topologyContext.getTopology().getWorkflows().entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, entry -> WorkflowUtils.cloneWorkflow(entry.getValue()))));
workflowFlattenService.simplifyWorkflow(topologyContext);
for (Workflow wf : topologyContext.getTopology().getWorkflows().values()) {
workflowValidator.validate(topologyContext, wf);
}
debugWorkflow(topologyContext.getTopology());
}
use of org.alien4cloud.tosca.model.workflow.Workflow in project alien4cloud by alien4cloud.
the class SubGraph method browse.
public void browse(GraphConsumer graphConsumer) {
Map<String, WorkflowStep> subGraphSteps = WorkflowGraphUtils.getAllStepsInSubGraph(workflow, filter);
Set<String> allSubGraphNodeIds = subGraphSteps.keySet();
List<WorkflowStep> rootNodes = subGraphSteps.values().stream().filter(node -> Collections.disjoint(node.getPrecedingSteps(), allSubGraphNodeIds)).collect(Collectors.toList());
if (rootNodes.isEmpty() && !subGraphSteps.isEmpty()) {
// It means the whole sub graph is connected between them, we begin anyway with one of the node
rootNodes.add(subGraphSteps.values().iterator().next());
}
Map<String, WorkflowStep> allNodes = new HashMap<>();
for (WorkflowStep rootNode : rootNodes) {
boolean shouldContinue = internalBrowseSubGraph(subGraphSteps, graphConsumer, new ArrayList<>(), rootNode, allNodes);
if (!shouldContinue) {
break;
}
}
graphConsumer.onAllNodes(allNodes);
}
use of org.alien4cloud.tosca.model.workflow.Workflow in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parseTopologyTemplateWithActivities.
@Test
public void parseTopologyTemplateWithActivities() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-activities.yml"));
assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
// check activities
assertEquals(1, wf.getSteps().get("Compute_install").getActivities().size());
assertEquals(1, wf.getSteps().get("Compute_install_0").getActivities().size());
assertEquals(1, wf.getSteps().get("Compute_install_1").getActivities().size());
// check activities of an other step
assertTrue(wf.getSteps().get("Compute_uninstall").getActivities().size() == 1);
assertTrue(wf.getSteps().get("Compute_uninstall_0").getActivities().size() == 1);
assertEquals(1, wf.getSteps().get("Compute_install").getOnSuccess().size());
assertEquals(1, wf.getSteps().get("Compute_install_0").getOnSuccess().size());
assertEquals(1, wf.getSteps().get("Compute_install_1").getOnSuccess().size());
assertEquals(1, wf.getSteps().get("Compute_uninstall").getOnSuccess().size());
assertEquals(0, wf.getSteps().get("Compute_uninstall_0").getOnSuccess().size());
// check onSuccess
assertTrue(wf.getSteps().get("Compute_install").getOnSuccess().contains("Compute_install_0"));
assertTrue(wf.getSteps().get("Compute_install_0").getOnSuccess().contains("Compute_install_1"));
assertTrue(wf.getSteps().get("Compute_install_1").getOnSuccess().contains("Compute_uninstall"));
assertTrue(wf.getSteps().get("Compute_uninstall").getOnSuccess().contains("Compute_uninstall_0"));
}
use of org.alien4cloud.tosca.model.workflow.Workflow in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parseTopologyTemplateWithInlineWorkflow.
@Test
public void parseTopologyTemplateWithInlineWorkflow() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-inline-workflow.yml"));
assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
assertEquals(1, wf.getSteps().get("Compute_install_0").getActivities().size());
assertTrue(wf.getSteps().get("Compute_install_0").getActivities().get(0) instanceof InlineWorkflowActivity);
InlineWorkflowActivity activity = (InlineWorkflowActivity) wf.getSteps().get("Compute_install_0").getActivities().get(0);
assertTrue(activity.getInline().equals("my_custom_wf"));
WorkflowUtils.processInlineWorkflows(parsingResult.getResult().getTopology().getWorkflows());
assertFalse(wf.getSteps().containsKey("Compute_install_0"));
assertTrue(wf.getSteps().containsKey("Compute_install_0_Compute_stop"));
assertTrue(wf.getSteps().containsKey("Compute_install_0_Compute_uninstall"));
assertTrue(wf.getSteps().containsKey("Some_other_inline_Compute_stop"));
assertTrue(wf.getSteps().containsKey("Some_other_inline_Compute_uninstall"));
assertTrue(wf.getSteps().get("Compute_install").getOnSuccess().contains("Compute_install_0_Compute_stop"));
assertTrue(wf.getSteps().get("Compute_install_0_Compute_stop").getPrecedingSteps().contains("Compute_install"));
assertEquals(1, wf.getSteps().get("Compute_install").getOnSuccess().size());
assertEquals(0, wf.getSteps().get("Compute_install").getPrecedingSteps().size());
assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_stop").getPrecedingSteps().size());
assertFalse(wf.getSteps().get("Compute_install").getOnSuccess().contains("Compute_install_0_Compute_uninstall"));
assertFalse(wf.getSteps().get("Compute_install_0_Compute_uninstall").getPrecedingSteps().contains("Compute_install"));
assertTrue(wf.getSteps().get("Compute_install_0_Compute_stop").getOnSuccess().contains("Compute_install_0_Compute_uninstall"));
assertTrue(wf.getSteps().get("Compute_install_0_Compute_uninstall").getPrecedingSteps().contains("Compute_install_0_Compute_stop"));
assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_stop").getOnSuccess().size());
assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_uninstall").getPrecedingSteps().size());
assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_uninstall").getOnSuccess().size());
assertTrue(wf.getSteps().get("Compute_install_0_Compute_uninstall").getOnSuccess().contains("Compute_start"));
assertTrue(wf.getSteps().get("Compute_start").getPrecedingSteps().contains("Compute_install_0_Compute_uninstall"));
assertTrue(wf.getSteps().get("Some_other_inline_Compute_stop").getOnSuccess().contains("Some_other_inline_Compute_uninstall"));
assertTrue(wf.getSteps().get("Some_other_inline_Compute_uninstall").getPrecedingSteps().contains("Some_other_inline_Compute_stop"));
assertTrue(wf.getSteps().get("inception_inline_inception_inline_Compute_stop").getOnSuccess().contains("inception_inline_inception_inline_Compute_uninstall"));
assertTrue(wf.getSteps().get("inception_inline_inception_inline_Compute_uninstall").getPrecedingSteps().contains("inception_inline_inception_inline_Compute_stop"));
}
Aggregations