Search in sources :

Example 41 with Workflow

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());
}
Also used : NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) RelationshipTemplate(org.alien4cloud.tosca.model.templates.RelationshipTemplate) Workflow(org.alien4cloud.tosca.model.workflow.Workflow)

Example 42 with Workflow

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());
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow)

Example 43 with Workflow

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);
}
Also used : List(java.util.List) Getter(lombok.Getter) Map(java.util.Map) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Set(java.util.Set) HashMap(java.util.HashMap) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ArrayList(java.util.ArrayList) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) HashMap(java.util.HashMap)

Example 44 with Workflow

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"));
}
Also used : ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Test(org.junit.Test)

Example 45 with Workflow

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"));
}
Also used : InlineWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Test(org.junit.Test)

Aggregations

Workflow (org.alien4cloud.tosca.model.workflow.Workflow)46 WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)20 NotFoundException (alien4cloud.exception.NotFoundException)11 Test (org.junit.Test)10 Map (java.util.Map)7 Path (alien4cloud.paas.wf.model.Path)6 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)6 List (java.util.List)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)5 TopologyDTO (alien4cloud.topology.TopologyDTO)4 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)4 AlienUtils.safe (alien4cloud.utils.AlienUtils.safe)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Slf4j (lombok.extern.slf4j.Slf4j)4 Csar (org.alien4cloud.tosca.model.Csar)4 Topology (org.alien4cloud.tosca.model.templates.Topology)4 WorkflowUtils (alien4cloud.paas.wf.util.WorkflowUtils)3