use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class MetadataMapperService method populateVersionForSubWorkflow.
private void populateVersionForSubWorkflow(WorkflowTask workflowTask) {
Preconditions.checkNotNull(workflowTask, "WorkflowTask cannot be null");
SubWorkflowParams subworkflowParams = workflowTask.getSubWorkflowParam();
if (subworkflowParams.getVersion() == null) {
String subWorkflowName = subworkflowParams.getName();
Integer subWorkflowVersion = metadataDAO.getLatestWorkflowDef(subWorkflowName).map(WorkflowDef::getVersion).orElseThrow(() -> {
String reason = String.format("The Task %s defined as a sub-workflow has no workflow definition available ", subWorkflowName);
logger.error(reason);
return new TerminateWorkflowException(reason);
});
subworkflowParams.setVersion(subWorkflowVersion);
}
}
use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class MetadataMapperServiceTest method testVersionPopulationForSubworkflowTaskIfVersionIsNotAvailable.
@Test
public void testVersionPopulationForSubworkflowTaskIfVersionIsNotAvailable() {
String nameTaskDefinition = "taskSubworkflow6";
String workflowDefinitionName = "subworkflow";
Integer version = 3;
WorkflowDef subWorkflowDefinition = createWorkflowDefinition("workflowDefinitionName");
subWorkflowDefinition.setVersion(version);
WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition);
workflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW);
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
subWorkflowParams.setName(workflowDefinitionName);
workflowTask.setSubWorkflowParam(subWorkflowParams);
WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation");
workflowDefinition.setTasks(ImmutableList.of(workflowTask));
when(metadataDAO.getLatestWorkflowDef(workflowDefinitionName)).thenReturn(Optional.of(subWorkflowDefinition));
metadataMapperService.populateTaskDefinitions(workflowDefinition);
assertEquals(1, workflowDefinition.getTasks().size());
List<WorkflowTask> workflowTasks = workflowDefinition.getTasks();
SubWorkflowParams params = workflowTasks.get(0).getSubWorkflowParam();
assertEquals(workflowDefinitionName, params.getName());
assertEquals(version, params.getVersion());
verify(metadataDAO).getLatestWorkflowDef(workflowDefinitionName);
verify(metadataDAO).getTaskDef(nameTaskDefinition);
verifyNoMoreInteractions(metadataDAO);
}
use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class MetadataMapperServiceTest method testNoVersionPopulationForSubworkflowTaskIfAvailable.
@Test
public void testNoVersionPopulationForSubworkflowTaskIfAvailable() {
String nameTaskDefinition = "taskSubworkflow7";
String workflowDefinitionName = "subworkflow";
Integer version = 2;
WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition);
workflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW);
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
subWorkflowParams.setName(workflowDefinitionName);
subWorkflowParams.setVersion(version);
workflowTask.setSubWorkflowParam(subWorkflowParams);
WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation");
workflowDefinition.setTasks(ImmutableList.of(workflowTask));
metadataMapperService.populateTaskDefinitions(workflowDefinition);
assertEquals(1, workflowDefinition.getTasks().size());
List<WorkflowTask> workflowTasks = workflowDefinition.getTasks();
SubWorkflowParams params = workflowTasks.get(0).getSubWorkflowParam();
assertEquals(workflowDefinitionName, params.getName());
assertEquals(version, params.getVersion());
verify(metadataDAO).getTaskDef(nameTaskDefinition);
verifyNoMoreInteractions(metadataDAO);
}
use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class MetadataMapperServiceTest method testExceptionWhenWorkflowDefinitionNotAvailable.
@Test(expected = TerminateWorkflowException.class)
public void testExceptionWhenWorkflowDefinitionNotAvailable() {
String nameTaskDefinition = "taskSubworkflow8";
String workflowDefinitionName = "subworkflow";
WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition);
workflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW);
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
subWorkflowParams.setName(workflowDefinitionName);
workflowTask.setSubWorkflowParam(subWorkflowParams);
WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation");
workflowDefinition.setTasks(ImmutableList.of(workflowTask));
when(metadataDAO.getLatestWorkflowDef(workflowDefinitionName)).thenReturn(Optional.empty());
metadataMapperService.populateTaskDefinitions(workflowDefinition);
verify(metadataDAO).getLatestWorkflowDef(workflowDefinitionName);
}
use of com.netflix.conductor.common.metadata.workflow.SubWorkflowParams in project conductor by Netflix.
the class WorkflowServiceTest method createWorkflowWithInlineSubWorkflow.
private WorkflowDef createWorkflowWithInlineSubWorkflow() {
WorkflowDef subWorkflowDef = createInlineSubWorkflow();
WorkflowTask subWfTask = new WorkflowTask();
subWfTask.setName("subWorkflowTask");
subWfTask.setType(SUB_WORKFLOW.name());
SubWorkflowParams swp = new SubWorkflowParams();
swp.setName("does-not-existing-wf");
swp.setWorkflowDefinition(subWorkflowDef);
subWfTask.setSubWorkflowParam(swp);
Map<String, Object> inputParam = new HashMap<>();
inputParam.put("test", "test value");
inputParam.put("param1", "sub workflow input param1");
inputParam.put("param2", subWorkflowDef.getVersion());
subWfTask.setInputParameters(inputParam);
subWfTask.setTaskReferenceName("sw1");
WorkflowDef main = new WorkflowDef();
main.setVersion(2);
main.setSchemaVersion(2);
main.setInputParameters(Arrays.asList("param1", "param2"));
main.setName(WF_WITH_INLINE_SUB_WF);
main.getTasks().add(subWfTask);
return main;
}
Aggregations