Search in sources :

Example 1 with NodeWorkflowStep

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

the class ToscaParserAlien200Test method parseTopologyTemplateWithRelationshipWorkflow.

@Test
public void parseTopologyTemplateWithRelationshipWorkflow() throws ParsingException {
    Mockito.reset(csarRepositorySearchService);
    Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
    NodeType mockCompute = new NodeType();
    mockCompute.setElementId(NormativeComputeConstants.COMPUTE_TYPE);
    mockCompute.setArchiveName("tosca-normative-types");
    mockCompute.setArchiveVersion("1.0.0-ALIEN14");
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq(NormativeComputeConstants.COMPUTE_TYPE), Mockito.any(Set.class))).thenReturn(mockCompute);
    RelationshipType mockHostedOn = Mockito.mock(RelationshipType.class);
    Mockito.when(mockHostedOn.getElementId()).thenReturn(NormativeRelationshipConstants.HOSTED_ON);
    Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq(NormativeRelationshipConstants.HOSTED_ON), Mockito.any(Set.class))).thenReturn(mockHostedOn);
    ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-relationship-workflow.yml"));
    Assert.assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
    Assert.assertTrue(parsingResult.getResult().getTopology().getWorkflows().get("install") != null);
    Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
    WorkflowStep relStep = wf.getSteps().get("OracleJDK_hostedOnComputeHost_pre_configure_source");
    Assert.assertNotNull(relStep);
    Assert.assertTrue(relStep instanceof RelationshipWorkflowStep);
    RelationshipWorkflowStep relationshipWorkflowStep = (RelationshipWorkflowStep) relStep;
    Assert.assertNotNull(relationshipWorkflowStep.getTargetRelationship());
    Assert.assertNotNull(relationshipWorkflowStep.getSourceHostId());
    Assert.assertNotNull(relationshipWorkflowStep.getTargetHostId());
    WorkflowStep nStep = wf.getSteps().get("OracleJDK_start");
    Assert.assertNotNull(nStep);
    Assert.assertTrue(nStep instanceof NodeWorkflowStep);
    NodeWorkflowStep nodeWorkflowStep = (NodeWorkflowStep) nStep;
    Assert.assertNotNull(nodeWorkflowStep.getHostId());
}
Also used : Csar(org.alien4cloud.tosca.model.Csar) Set(java.util.Set) ArchiveRoot(alien4cloud.tosca.model.ArchiveRoot) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeType(org.alien4cloud.tosca.model.types.NodeType) RelationshipType(org.alien4cloud.tosca.model.types.RelationshipType) Workflow(org.alien4cloud.tosca.model.workflow.Workflow) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) Test(org.junit.Test)

Example 2 with NodeWorkflowStep

use of org.alien4cloud.tosca.model.workflow.NodeWorkflowStep 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);
        }
    }
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)

Example 3 with NodeWorkflowStep

use of org.alien4cloud.tosca.model.workflow.NodeWorkflowStep 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();
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep)

Example 4 with NodeWorkflowStep

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

the class WorkflowUtils method cloneStep.

public static WorkflowStep cloneStep(WorkflowStep step) {
    WorkflowStep cloned;
    if (step instanceof NodeWorkflowStep) {
        NodeWorkflowStep nodeWorkflowStep = (NodeWorkflowStep) step;
        cloned = new NodeWorkflowStep();
        ((NodeWorkflowStep) cloned).setHostId(nodeWorkflowStep.getHostId());
    } else {
        RelationshipWorkflowStep relationshipWorkflowStep = (RelationshipWorkflowStep) step;
        cloned = new RelationshipWorkflowStep();
        ((RelationshipWorkflowStep) cloned).setTargetRelationship(relationshipWorkflowStep.getTargetRelationship());
        ((RelationshipWorkflowStep) cloned).setSourceHostId(relationshipWorkflowStep.getSourceHostId());
        ((RelationshipWorkflowStep) cloned).setTargetHostId(relationshipWorkflowStep.getTargetHostId());
    }
    cloned.setActivities(step.getActivities());
    cloned.setFilter(step.getFilter());
    cloned.setName(step.getName());
    cloned.setOnFailure(step.getOnFailure());
    cloned.setOnSuccess(new HashSet<>(step.getOnSuccess()));
    cloned.setOperationHost(step.getOperationHost());
    cloned.setPrecedingSteps(new HashSet<>(step.getPrecedingSteps()));
    cloned.setTarget(step.getTarget());
    return cloned;
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)

Example 5 with NodeWorkflowStep

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

the class AbstractWorkflowBuilder method addActivityStep.

private WorkflowStep addActivityStep(Workflow wf, String target, String targetRelationship, AbstractWorkflowActivity activity) {
    WorkflowStep step;
    if (StringUtils.isEmpty(targetRelationship)) {
        step = new NodeWorkflowStep();
    } else {
        RelationshipWorkflowStep relationshipWorkflowStep = new RelationshipWorkflowStep();
        relationshipWorkflowStep.setTargetRelationship(targetRelationship);
        step = relationshipWorkflowStep;
    }
    step.setTarget(target);
    step.setActivity(activity);
    step.setName(WorkflowUtils.buildStepName(wf, step, 0));
    wf.addStep(step);
    return step;
}
Also used : NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) WorkflowStep(org.alien4cloud.tosca.model.workflow.WorkflowStep) NodeWorkflowStep(org.alien4cloud.tosca.model.workflow.NodeWorkflowStep) RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)

Aggregations

NodeWorkflowStep (org.alien4cloud.tosca.model.workflow.NodeWorkflowStep)9 RelationshipWorkflowStep (org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep)6 WorkflowStep (org.alien4cloud.tosca.model.workflow.WorkflowStep)5 NodeType (org.alien4cloud.tosca.model.types.NodeType)2 CallOperationWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.CallOperationWorkflowActivity)2 DelegateWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.DelegateWorkflowActivity)2 SetStateWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.SetStateWorkflowActivity)2 ArchiveRoot (alien4cloud.tosca.model.ArchiveRoot)1 Set (java.util.Set)1 Csar (org.alien4cloud.tosca.model.Csar)1 NodeTemplate (org.alien4cloud.tosca.model.templates.NodeTemplate)1 RelationshipTemplate (org.alien4cloud.tosca.model.templates.RelationshipTemplate)1 RelationshipType (org.alien4cloud.tosca.model.types.RelationshipType)1 Workflow (org.alien4cloud.tosca.model.workflow.Workflow)1 InlineWorkflowActivity (org.alien4cloud.tosca.model.workflow.activities.InlineWorkflowActivity)1 Test (org.junit.Test)1