Search in sources :

Example 6 with SubWorkflowParams

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);
    }
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) TerminateWorkflowException(com.netflix.conductor.core.execution.TerminateWorkflowException)

Example 7 with SubWorkflowParams

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);
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 8 with SubWorkflowParams

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);
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 9 with SubWorkflowParams

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);
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 10 with SubWorkflowParams

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;
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Aggregations

SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)26 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)21 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)17 Test (org.junit.Test)13 HashMap (java.util.HashMap)12 LinkedList (java.util.LinkedList)5 Task (com.netflix.conductor.common.metadata.tasks.Task)4 Workflow (com.netflix.conductor.common.run.Workflow)4 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)4 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ConstraintViolation (javax.validation.ConstraintViolation)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)1 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)1 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)1 TerminateWorkflowException (com.netflix.conductor.core.execution.TerminateWorkflowException)1