Search in sources :

Example 76 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class AbstractWorkflowServiceTest method createConditionalWFWithSystemTask.

private void createConditionalWFWithSystemTask() {
    WorkflowDef defConditionalHttp = new WorkflowDef();
    defConditionalHttp.setName(CONDITIONAL_SYSTEM_WORKFLOW);
    defConditionalHttp.setDescription(defConditionalHttp.getName());
    defConditionalHttp.setVersion(1);
    defConditionalHttp.setInputParameters(Arrays.asList("param1", "param2"));
    Map<String, Object> outputParameters = new HashMap<>();
    outputParameters.put("o2", "${t1.output.op}");
    defConditionalHttp.setOutputParameters(outputParameters);
    defConditionalHttp.setSchemaVersion(2);
    LinkedList<WorkflowTask> wftasks = new LinkedList<>();
    WorkflowTask wft1 = new WorkflowTask();
    wft1.setName("junit_task_1");
    Map<String, Object> ip1 = new HashMap<>();
    ip1.put("tp11", "${workflow.input.param1}");
    ip1.put("tp12", "${workflow.input.param2}");
    wft1.setInputParameters(ip1);
    wft1.setTaskReferenceName("t1");
    TaskDef taskDef = new TaskDef();
    taskDef.setName("user_task");
    taskDef.setTimeoutSeconds(20);
    taskDef.setRetryCount(1);
    taskDef.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskDef.setRetryDelaySeconds(10);
    metadataService.registerTaskDef(Collections.singletonList(taskDef));
    WorkflowTask userTask = new WorkflowTask();
    userTask.setName(taskDef.getName());
    userTask.setType(UserTask.NAME);
    Map<String, Object> userIP = new HashMap<>();
    userIP.put("largeInput", "${t1.output.op}");
    userTask.setInputParameters(userIP);
    userTask.setTaskReferenceName("user_task");
    WorkflowTask wft2 = new WorkflowTask();
    wft2.setName("junit_task_2");
    Map<String, Object> ip2 = new HashMap<>();
    ip2.put("tp21", "${workflow.input.param1}");
    wft2.setInputParameters(ip2);
    wft2.setTaskReferenceName("t2");
    WorkflowTask decisionTask = new WorkflowTask();
    decisionTask.setType(TaskType.DECISION.name());
    decisionTask.setCaseValueParam("case");
    decisionTask.setName("conditional2");
    decisionTask.setTaskReferenceName("conditional2");
    Map<String, Object> decisionIP = new HashMap<>();
    decisionIP.put("case", "${t1.output.case}");
    decisionTask.setInputParameters(decisionIP);
    Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
    decisionCases.put("one", Collections.singletonList(wft2));
    decisionCases.put("two", Collections.singletonList(userTask));
    decisionTask.setDecisionCases(decisionCases);
    WorkflowTask wft3 = new WorkflowTask();
    wft3.setName("junit_task_3");
    Map<String, Object> ip3 = new HashMap<>();
    ip3.put("tp31", "${workflow.input.param2}");
    wft3.setInputParameters(ip3);
    wft3.setTaskReferenceName("t3");
    wftasks.add(wft1);
    wftasks.add(decisionTask);
    wftasks.add(wft3);
    defConditionalHttp.setTasks(wftasks);
    metadataService.updateWorkflowDef(defConditionalHttp);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) LinkedList(java.util.LinkedList) LinkedList(java.util.LinkedList)

Example 77 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testSubWorkflowRetryLastFailedTask.

@Test
public void testSubWorkflowRetryLastFailedTask() {
    String taskName = "junit_task_2";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    int retryCount = notFoundSafeGetTaskDef(taskName).getRetryCount();
    taskDef.setRetryCount(0);
    metadataService.updateTaskDef(taskDef);
    createSubWorkflow();
    WorkflowDef found = metadataService.getWorkflowDef(WF_WITH_SUB_WF, 1);
    WorkflowTask workflowTask = found.getTasks().stream().filter(t -> t.getType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
    TaskDef subWorkflowTaskDef = new TaskDef();
    subWorkflowTaskDef.setRetryCount(0);
    subWorkflowTaskDef.setName("test_subworkflow_task");
    subWorkflowTaskDef.setOwnerEmail("test@qbc.com");
    workflowTask.setTaskDefinition(subWorkflowTaskDef);
    metadataService.updateWorkflowDef(found);
    Map<String, Object> workflowInputParams = new HashMap<>();
    workflowInputParams.put("param1", "param 1");
    workflowInputParams.put("param3", "param 2");
    workflowInputParams.put("wfName", LINEAR_WORKFLOW_T1_T2);
    String workflowId = startOrLoadWorkflowExecution(WF_WITH_SUB_WF, 1, "test", workflowInputParams, null, null);
    assertNotNull(workflowId);
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    Task task = workflowExecutionService.poll("junit_task_5", "test");
    assertNotNull(task);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    String subWorkflowTaskId = workflow.getTaskByRefName("a2").getTaskId();
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertNotNull(workflow.getTasks());
    assertEquals(2, workflow.getTasks().size());
    task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
    assertNotNull(task);
    assertNotNull(task.getOutputData());
    assertNotNull("Output: " + task.getOutputData().toString() + ", status: " + task.getStatus(), task.getSubWorkflowId());
    String subWorkflowId = task.getSubWorkflowId();
    workflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(workflow);
    assertNotNull(workflow.getTasks());
    assertEquals(workflowId, workflow.getParentWorkflowId());
    assertEquals(RUNNING, workflow.getStatus());
    task = workflowExecutionService.poll("junit_task_1", "test");
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    Workflow subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    task = workflowExecutionService.poll("junit_task_2", "test");
    task.setStatus(FAILED);
    workflowExecutionService.updateTask(task);
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(WorkflowStatus.FAILED, subWorkflow.getStatus());
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    task = subWorkflow.getTasks().stream().filter(t -> t.getTaskType().equals("junit_task_2")).findAny().orElse(null);
    assertNotNull(task);
    assertEquals(FAILED, task.getStatus());
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(WorkflowStatus.FAILED, subWorkflow.getStatus());
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
    workflowExecutor.retry(workflowId, true);
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(RUNNING, subWorkflow.getStatus());
    task = workflowExecutionService.poll("junit_task_2", "test");
    assertEquals(subWorkflowId, task.getWorkflowInstanceId());
    String uuid = UUID.randomUUID().toString();
    task.getOutputData().put("uuid", uuid);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(WorkflowStatus.COMPLETED, subWorkflow.getStatus());
    assertNotNull(subWorkflow.getOutput());
    assertTrue(subWorkflow.getOutput().containsKey("o1"));
    assertTrue(subWorkflow.getOutput().containsKey("o2"));
    assertEquals("sub workflow input param1", subWorkflow.getOutput().get("o1"));
    assertEquals(uuid, subWorkflow.getOutput().get("o2"));
    workflowExecutor.executeSystemTask(subworkflow, subWorkflow.getParentWorkflowTaskId(), 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    task = workflowExecutionService.poll("junit_task_6", "test");
    assertNotNull(task);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(retryCount);
    metadataService.updateTaskDef(taskDef);
    workflowTask = found.getTasks().stream().filter(t -> t.getType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
    workflowTask.setTaskDefinition(null);
    metadataService.updateWorkflowDef(found);
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) MethodSorters(org.junit.runners.MethodSorters) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Arrays(java.util.Arrays) TimeoutPolicy(com.netflix.conductor.common.metadata.tasks.TaskDef.TimeoutPolicy) TEMP_FILE_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TEMP_FILE_PATH) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) Future(java.util.concurrent.Future) COMPLETED_WITH_ERRORS(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) After(org.junit.After) PollData(com.netflix.conductor.common.metadata.tasks.PollData) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) TASK_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TASK_OUTPUT_PATH) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) WorkflowRepairService(com.netflix.conductor.core.execution.WorkflowRepairService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Executors(java.util.concurrent.Executors) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) QueueDAO(com.netflix.conductor.dao.QueueDAO) INPUT_PAYLOAD_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INPUT_PAYLOAD_PATH) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) Assert.assertFalse(org.junit.Assert.assertFalse) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) COMPLETED(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED) ExecutionService(com.netflix.conductor.service.ExecutionService) FixMethodOrder(org.junit.FixMethodOrder) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) MetadataService(com.netflix.conductor.service.MetadataService) WorkflowContext(com.netflix.conductor.core.WorkflowContext) BeforeClass(org.junit.BeforeClass) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) LinkedList(java.util.LinkedList) ExpectedException(org.junit.rules.ExpectedException) RUNNING(com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) TERMINATED(com.netflix.conductor.common.run.Workflow.WorkflowStatus.TERMINATED) INITIAL_WORKFLOW_INPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INITIAL_WORKFLOW_INPUT_PATH) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) WorkflowSweeper(com.netflix.conductor.core.execution.WorkflowSweeper) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTask(com.netflix.conductor.tests.utils.UserTask) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) WORKFLOW_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.WORKFLOW_OUTPUT_PATH) TimeUnit(java.util.concurrent.TimeUnit) DECISION(com.netflix.conductor.common.metadata.workflow.TaskType.DECISION) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Ignore(org.junit.Ignore) RetryLogic(com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 78 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class AbstractEndToEndTest method createTaskDefinition.

protected TaskDef createTaskDefinition(String name) {
    TaskDef taskDefinition = new TaskDef();
    taskDefinition.setName(name);
    return taskDefinition;
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef)

Example 79 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class AbstractEndToEndTest method testEphemeralWorkflowsWithEphemeralAndStoredTasks.

@Test
public void testEphemeralWorkflowsWithEphemeralAndStoredTasks() {
    createAndRegisterTaskDefinitions("storedTask", 1);
    WorkflowDef workflowDefinition = createWorkflowDefinition("testEphemeralWorkflowsWithEphemeralAndStoredTasks");
    WorkflowTask workflowTask1 = createWorkflowTask("ephemeralTask1");
    TaskDef taskDefinition1 = createTaskDefinition("ephemeralTaskDef1");
    workflowTask1.setTaskDefinition(taskDefinition1);
    WorkflowTask workflowTask2 = createWorkflowTask("storedTask0");
    workflowDefinition.getTasks().add(workflowTask1);
    workflowDefinition.getTasks().add(workflowTask2);
    String workflowExecutionName = "ephemeralWorkflowWithEphemeralAndStoredTasks";
    String workflowId = startWorkflow(workflowExecutionName, workflowDefinition);
    assertNotNull(workflowId);
    Workflow workflow = getWorkflow(workflowId, true);
    WorkflowDef ephemeralWorkflow = workflow.getWorkflowDefinition();
    assertNotNull(ephemeralWorkflow);
    assertEquals(workflowDefinition, ephemeralWorkflow);
    TaskDef storedTaskDefinition = getTaskDefinition("storedTask0");
    List<WorkflowTask> tasks = ephemeralWorkflow.getTasks();
    assertEquals(2, tasks.size());
    assertEquals(workflowTask1, tasks.get(0));
    TaskDef currentStoredTaskDefinition = tasks.get(1).getTaskDefinition();
    assertNotNull(currentStoredTaskDefinition);
    assertEquals(storedTaskDefinition, currentStoredTaskDefinition);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 80 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class MetadataServiceImpl method updateTaskDef.

/*
     * @param taskDefinition Task Definition to be updated
     */
@Service
public void updateTaskDef(TaskDef taskDefinition) {
    TaskDef existing = metadataDAO.getTaskDef(taskDefinition.getName());
    if (existing == null) {
        throw new ApplicationException(Code.NOT_FOUND, "No such task by name " + taskDefinition.getName());
    }
    taskDefinition.setUpdatedBy(WorkflowContext.get().getClientApp());
    taskDefinition.setUpdateTime(System.currentTimeMillis());
    metadataDAO.updateTaskDef(taskDefinition);
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Service(com.netflix.conductor.annotations.Service)

Aggregations

TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)172 Test (org.junit.Test)128 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)121 Task (com.netflix.conductor.common.metadata.tasks.Task)77 Workflow (com.netflix.conductor.common.run.Workflow)76 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)73 HashMap (java.util.HashMap)56 ArrayList (java.util.ArrayList)32 ConstraintViolation (javax.validation.ConstraintViolation)31 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)30 UserTask (com.netflix.conductor.tests.utils.UserTask)28 LinkedList (java.util.LinkedList)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)27 List (java.util.List)22 Map (java.util.Map)19 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)18 Before (org.junit.Before)14 ExpectedException (org.junit.rules.ExpectedException)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 Collectors (java.util.stream.Collectors)11