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());
}
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"));
}
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);
}
}
}
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;
}
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;
}
Aggregations