Search in sources :

Example 1 with Workflow

use of org.alien4cloud.tosca.model.workflow.Workflow in project yorc-a4c-plugin by ystia.

the class ShowTopology method topologyInLog.

/**
 * Log topology infos for debugging
 * @param ctx
 */
public static void topologyInLog(PaaSTopologyDeploymentContext ctx) {
    String paasId = ctx.getDeploymentPaaSId();
    PaaSTopology ptopo = ctx.getPaaSTopology();
    DeploymentTopology dtopo = ctx.getDeploymentTopology();
    // Deployment Workflows
    Map<String, Workflow> workflows = dtopo.getWorkflows();
    for (String wfname : workflows.keySet()) {
        log.debug("***** Workflow " + wfname);
        Workflow wf = workflows.get(wfname);
        log.debug("name: " + wf.getName());
        log.debug("host: " + wf.getHosts().toString());
        log.debug("steps: " + wf.getSteps().keySet().toString());
    }
    // Deployment Groups
    Map<String, NodeGroup> groups = dtopo.getGroups();
    if (groups != null) {
        for (String grname : groups.keySet()) {
            NodeGroup group = groups.get(grname);
            log.debug("***** Group " + grname);
            log.debug("name: " + group.getName());
            log.debug("members: " + group.getMembers().toString());
        }
    }
    // PaaS Compute Nodes
    for (PaaSNodeTemplate node : ptopo.getAllNodes().values()) {
        printNode(node);
    }
}
Also used : PaaSTopology(alien4cloud.paas.model.PaaSTopology) PaaSNodeTemplate(alien4cloud.paas.model.PaaSNodeTemplate) DeploymentTopology(alien4cloud.model.deployment.DeploymentTopology) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) NodeGroup(org.alien4cloud.tosca.model.templates.NodeGroup)

Example 2 with Workflow

use of org.alien4cloud.tosca.model.workflow.Workflow 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
        }
    }));
}
Also used : ToscaContextual(alien4cloud.tosca.context.ToscaContextual) Csar(org.alien4cloud.tosca.model.Csar) WorkflowValidator(alien4cloud.paas.wf.validation.WorkflowValidator) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Resource(javax.annotation.Resource) Set(java.util.Set) ConnectStepFromProcessor(org.alien4cloud.tosca.editor.processors.workflow.ConnectStepFromProcessor) TopologyModifierSupport(org.alien4cloud.alm.deployment.configuration.flow.TopologyModifierSupport) TopologyNavigationUtil(org.alien4cloud.tosca.utils.TopologyNavigationUtil) AlienUtils.safe(alien4cloud.utils.AlienUtils.safe) Slf4j(lombok.extern.slf4j.Slf4j) Component(org.springframework.stereotype.Component) RemoveEdgeOperation(org.alien4cloud.tosca.editor.operations.workflow.RemoveEdgeOperation) FlowExecutionContext(org.alien4cloud.alm.deployment.configuration.flow.FlowExecutionContext) Map(java.util.Map) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) Topology(org.alien4cloud.tosca.model.templates.Topology) ConnectStepFromOperation(org.alien4cloud.tosca.editor.operations.workflow.ConnectStepFromOperation) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) RemoveEdgeProcessor(org.alien4cloud.tosca.editor.processors.workflow.RemoveEdgeProcessor) Csar(org.alien4cloud.tosca.model.Csar) RemoveEdgeOperation(org.alien4cloud.tosca.editor.operations.workflow.RemoveEdgeOperation) NodeTemplate(org.alien4cloud.tosca.model.templates.NodeTemplate) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) ConnectStepFromOperation(org.alien4cloud.tosca.editor.operations.workflow.ConnectStepFromOperation) Workflow(org.alien4cloud.tosca.model.workflow.Workflow)

Example 3 with Workflow

use of org.alien4cloud.tosca.model.workflow.Workflow in project alien4cloud by alien4cloud.

the class AbstractValidationTest method prepare.

@Before
public void prepare() {
    wf = new Workflow();
    wf.setName(INSTALL);
}
Also used : Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Before(org.junit.Before)

Example 4 with Workflow

use of org.alien4cloud.tosca.model.workflow.Workflow 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());
}
Also used : Path(alien4cloud.paas.wf.model.Path) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) Test(org.junit.Test)

Example 5 with Workflow

use of org.alien4cloud.tosca.model.workflow.Workflow in project alien4cloud by alien4cloud.

the class GraphPathsTest method test23.

/**
 * <pre>
 *      c
 *     /
 * -- a
 *     \
 *      b
 * </pre>
 */
@Test
public void test23() {
    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(a, c);
    List<Path> paths = WorkflowGraphUtils.getWorkflowGraphCycles(wf);
    log.info(paths.toString());
}
Also used : Path(alien4cloud.paas.wf.model.Path) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) 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