Search in sources :

Example 1 with RelationshipWorkflowStep

use of org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep 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 RelationshipWorkflowStep

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

Example 3 with RelationshipWorkflowStep

use of org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep 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 4 with RelationshipWorkflowStep

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

the class WorkflowUtils method createRelationshipOperationStep.

public static WorkflowStep createRelationshipOperationStep(Workflow wf, String nodeId, String relationshipId, String interfaceName, String operationName, String operationHost) {
    CallOperationWorkflowActivity task = new CallOperationWorkflowActivity();
    task.setInterfaceName(interfaceName);
    task.setOperationName(operationName);
    RelationshipWorkflowStep step = new RelationshipWorkflowStep();
    step.setTarget(nodeId);
    step.setTargetRelationship(relationshipId);
    step.setActivity(task);
    step.setName(buildStepName(wf, step, 0));
    step.setOperationHost(operationHost);
    return step;
}
Also used : RelationshipWorkflowStep(org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep) CallOperationWorkflowActivity(org.alien4cloud.tosca.model.workflow.activities.CallOperationWorkflowActivity)

Example 5 with RelationshipWorkflowStep

use of org.alien4cloud.tosca.model.workflow.RelationshipWorkflowStep 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)

Aggregations

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