Search in sources :

Example 66 with TaskDef

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

the class AbstractWorkflowServiceTest method testRetry.

@Test
public void testRetry() {
    String taskName = "junit_task_1";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    int retryCount = taskDef.getRetryCount();
    taskDef.setRetryCount(1);
    int retryDelay = taskDef.getRetryDelaySeconds();
    taskDef.setRetryDelaySeconds(0);
    metadataService.updateTaskDef(taskDef);
    WorkflowDef workflowDef = metadataService.getWorkflowDef(LINEAR_WORKFLOW_T1_T2, 1);
    assertNotNull(workflowDef.getFailureWorkflow());
    assertFalse(StringUtils.isBlank(workflowDef.getFailureWorkflow()));
    String correlationId = "retry_test_" + UUID.randomUUID().toString();
    Map<String, Object> input = new HashMap<>();
    input.put("param1", "p1 value");
    input.put("param2", "p2 value");
    String workflowId = startOrLoadWorkflowExecution("retry", LINEAR_WORKFLOW_T1_T2, 1, correlationId, input, null, null);
    assertNotNull(workflowId);
    printTaskStatuses(workflowId, "initial");
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(1, workflow.getTasks().size());
    Task task = getTask("junit_task_1");
    assertNotNull(task);
    task.setStatus(FAILED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(2, workflow.getTasks().size());
    task = getTask("junit_task_1");
    assertNotNull(task);
    task.setStatus(FAILED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
    assertEquals(2, workflow.getTasks().size());
    printTaskStatuses(workflowId, "before retry");
    workflowExecutor.retry(workflowId, false);
    printTaskStatuses(workflowId, "after retry");
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(3, workflow.getTasks().size());
    task = getTask("junit_task_1");
    assertNotNull(task);
    assertEquals(workflowId, task.getWorkflowInstanceId());
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    assertEquals(4, workflow.getTasks().size());
    task = getTask("junit_task_2");
    assertNotNull(task);
    assertEquals(workflowId, task.getWorkflowInstanceId());
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    assertEquals(4, workflow.getTasks().size());
    assertEquals(3, workflow.getTasks().stream().filter(t -> t.getTaskType().equals("junit_task_1")).count());
    taskDef.setRetryCount(retryCount);
    taskDef.setRetryDelaySeconds(retryDelay);
    metadataService.updateTaskDef(taskDef);
    printTaskStatuses(workflowId, "final");
}
Also used : 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) Test(org.junit.Test)

Example 67 with TaskDef

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

the class AbstractWorkflowServiceTest method testTaskSkipping.

@Test
public void testTaskSkipping() {
    String taskName = "junit_task_1";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(0);
    taskDef.setTimeoutSeconds(0);
    metadataService.updateTaskDef(taskDef);
    metadataService.getWorkflowDef(TEST_WORKFLOW, 1);
    String correlationId = "unit_test_1" + UUID.randomUUID().toString();
    Map<String, Object> input = new HashMap<String, Object>();
    String inputParam1 = "p1 value";
    input.put("param1", inputParam1);
    input.put("param2", "p2 value");
    String wfid = startOrLoadWorkflowExecution(TEST_WORKFLOW, 1, correlationId, input, null, null);
    assertNotNull(wfid);
    // Now Skip the second task
    workflowExecutor.skipTaskFromWorkflow(wfid, "t2", null);
    Workflow es = workflowExecutionService.getExecutionStatus(wfid, true);
    assertNotNull(es);
    assertEquals(RUNNING, es.getStatus());
    // Check the tasks, at this time there should be 3 task
    assertEquals(2, es.getTasks().size());
    assertEquals(SCHEDULED, es.getTasks().stream().filter(task -> "t1".equals(task.getReferenceTaskName())).findFirst().orElse(null).getStatus());
    assertEquals(Status.SKIPPED, es.getTasks().stream().filter(task -> "t2".equals(task.getReferenceTaskName())).findFirst().orElse(null).getStatus());
    Task task = workflowExecutionService.poll("junit_task_1", "task1.junit.worker");
    assertNotNull(task);
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals("t1", task.getReferenceTaskName());
    String param1 = (String) task.getInputData().get("p1");
    String param2 = (String) task.getInputData().get("p2");
    assertNotNull(param1);
    assertNotNull(param2);
    assertEquals("p1 value", param1);
    assertEquals("p2 value", param2);
    String task1Op = "task1.output->" + param1 + "." + param2;
    task.getOutputData().put("op", task1Op);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    // If we get the full workflow here then, last task should be completed and the next task should be scheduled
    es = workflowExecutionService.getExecutionStatus(wfid, true);
    es.getTasks().forEach(wfTask -> {
        if (wfTask.getReferenceTaskName().equals("t1")) {
            assertEquals(COMPLETED, wfTask.getStatus());
        } else if (wfTask.getReferenceTaskName().equals("t2")) {
            assertEquals(Status.SKIPPED, wfTask.getStatus());
        } else {
            assertEquals(SCHEDULED, wfTask.getStatus());
        }
    });
    task = workflowExecutionService.poll("junit_task_3", "task3.junit.worker");
    assertNotNull(task);
    assertEquals(IN_PROGRESS, task.getStatus());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    es = workflowExecutionService.getExecutionStatus(wfid, true);
    assertNotNull(es);
    assertEquals(WorkflowStatus.COMPLETED, es.getStatus());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) 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) Test(org.junit.Test)

Example 68 with TaskDef

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

the class AbstractWorkflowServiceTest method testForkJoinFailure.

@Test
public void testForkJoinFailure() {
    try {
        createForkJoinWorkflow();
    } catch (Exception e) {
    }
    String taskName = "junit_task_2";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    int retryCount = taskDef.getRetryCount();
    taskDef.setRetryCount(0);
    metadataService.updateTaskDef(taskDef);
    Map<String, Object> input = new HashMap<String, Object>();
    String wfid = startOrLoadWorkflowExecution(FORK_JOIN_WF, 1, "fanouttest", input, null, null);
    System.out.println("testForkJoinFailure.wfid=" + wfid);
    Task t1 = workflowExecutionService.poll("junit_task_2", "test");
    assertNotNull(t1);
    assertTrue(workflowExecutionService.ackTaskReceived(t1.getTaskId()));
    Task t2 = workflowExecutionService.poll("junit_task_1", "test");
    assertTrue(workflowExecutionService.ackTaskReceived(t2.getTaskId()));
    Task t3 = workflowExecutionService.poll("junit_task_3", "test");
    assertNull(t3);
    assertNotNull(t1);
    assertNotNull(t2);
    t1.setStatus(FAILED);
    t2.setStatus(COMPLETED);
    workflowExecutionService.updateTask(t2);
    Workflow wf = workflowExecutionService.getExecutionStatus(wfid, true);
    assertNotNull(wf);
    assertEquals("Found " + wf.getTasks(), RUNNING, wf.getStatus());
    t3 = workflowExecutionService.poll("junit_task_3", "test");
    assertNotNull(t3);
    workflowExecutionService.updateTask(t1);
    wf = workflowExecutionService.getExecutionStatus(wfid, true);
    assertNotNull(wf);
    assertEquals("Found " + wf.getTasks(), WorkflowStatus.FAILED, wf.getStatus());
    taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(retryCount);
    metadataService.updateTaskDef(taskDef);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) 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) ExpectedException(org.junit.rules.ExpectedException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Test(org.junit.Test)

Example 69 with TaskDef

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

the class AbstractWorkflowServiceTest method testRetryWorkflowUsingExternalPayloadStorage.

@Test
public void testRetryWorkflowUsingExternalPayloadStorage() {
    WorkflowDef found = metadataService.getWorkflowDef(LINEAR_WORKFLOW_T1_T2, 1);
    assertNotNull(found);
    Map<String, Object> outputParameters = found.getOutputParameters();
    outputParameters.put("workflow_output", "${t1.output.op}");
    metadataService.updateWorkflowDef(found);
    String taskName = "junit_task_2";
    TaskDef taskDef = metadataService.getTaskDef(taskName);
    taskDef.setRetryCount(2);
    taskDef.setRetryDelaySeconds(0);
    metadataService.updateTaskDef(taskDef);
    String workflowInputPath = INITIAL_WORKFLOW_INPUT_PATH;
    String correlationId = "wf_external_storage";
    String workflowId = workflowExecutor.startWorkflow(LINEAR_WORKFLOW_T1_T2, 1, correlationId, null, workflowInputPath, null, null);
    assertNotNull(workflowId);
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertTrue("The workflow input should not be persisted", workflow.getInput().isEmpty());
    assertEquals(workflowInputPath, workflow.getExternalInputPayloadStoragePath());
    assertEquals(workflow.getReasonForIncompletion(), WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(1, workflow.getTasks().size());
    // Polling for the first task
    Task task = workflowExecutionService.poll("junit_task_1", "task1.junit.worker");
    assertNotNull(task);
    assertEquals("junit_task_1", task.getTaskType());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(workflowId, task.getWorkflowInstanceId());
    // update first task with COMPLETED
    String taskOutputPath = TASK_OUTPUT_PATH;
    task.setOutputData(null);
    task.setExternalOutputPayloadStoragePath(taskOutputPath);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    // Polling for the second task
    task = workflowExecutionService.poll("junit_task_2", "task2.junit.worker");
    assertNotNull(task);
    assertEquals("junit_task_2", task.getTaskType());
    assertTrue(task.getInputData().isEmpty());
    assertNotNull(task.getExternalInputPayloadStoragePath());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(workflowId, task.getWorkflowInstanceId());
    // update second task with FAILED
    task.getOutputData().put("op", "failed_task2");
    task.setStatus(FAILED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertTrue("The workflow input should not be persisted", workflow.getInput().isEmpty());
    assertEquals(workflowInputPath, workflow.getExternalInputPayloadStoragePath());
    assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
    // Polling again for the second task
    task = workflowExecutionService.poll("junit_task_2", "task2.junit.worker");
    assertNotNull(task);
    assertEquals("junit_task_2", task.getTaskType());
    assertTrue(task.getInputData().isEmpty());
    assertNotNull(task.getExternalInputPayloadStoragePath());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(workflowId, task.getWorkflowInstanceId());
    // update second task with COMPLETED
    task.getOutputData().put("op", "success_task2");
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertTrue("The workflow input should not be persisted", workflow.getInput().isEmpty());
    assertEquals(workflowInputPath, workflow.getExternalInputPayloadStoragePath());
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    assertEquals(3, workflow.getTasks().size());
    assertTrue("The first task output should not be persisted", workflow.getTasks().get(0).getOutputData().isEmpty());
    assertTrue("The second task input should not be persisted", workflow.getTasks().get(1).getInputData().isEmpty());
    assertTrue("The second task input should not be persisted", workflow.getTasks().get(2).getInputData().isEmpty());
    assertEquals(taskOutputPath, workflow.getTasks().get(0).getExternalOutputPayloadStoragePath());
    assertEquals(INPUT_PAYLOAD_PATH, workflow.getTasks().get(1).getExternalInputPayloadStoragePath());
    assertEquals(INPUT_PAYLOAD_PATH, workflow.getTasks().get(2).getExternalInputPayloadStoragePath());
    assertTrue(workflow.getOutput().isEmpty());
    assertNotNull(workflow.getExternalOutputPayloadStoragePath());
    assertEquals(WORKFLOW_OUTPUT_PATH, workflow.getExternalOutputPayloadStoragePath());
}
Also used : 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) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 70 with TaskDef

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

the class AbstractWorkflowServiceTest method testLoopConditionWithInputParamter.

@Test
public void testLoopConditionWithInputParamter() throws Exception {
    try {
        createDoWhileWorkflowWithIteration(2, true, true);
    } catch (Exception e) {
    }
    TaskDef taskDef = new TaskDef();
    taskDef.setName("http1");
    taskDef.setTimeoutSeconds(2);
    taskDef.setRetryCount(1);
    taskDef.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskDef.setRetryDelaySeconds(10);
    metadataService.registerTaskDef(Arrays.asList(taskDef));
    TaskDef taskDef2 = new TaskDef();
    taskDef2.setName("http0");
    taskDef2.setTimeoutSeconds(2);
    taskDef2.setRetryCount(1);
    taskDef2.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskDef2.setRetryDelaySeconds(10);
    metadataService.registerTaskDef(Arrays.asList(taskDef2));
    TaskDef taskDef1 = new TaskDef();
    taskDef1.setName("http2");
    taskDef1.setTimeoutSeconds(2);
    taskDef1.setRetryCount(1);
    taskDef1.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskDef1.setRetryDelaySeconds(10);
    metadataService.registerTaskDef(Arrays.asList(taskDef1));
    Map<String, Object> input = new HashMap<>();
    String workflowId = startOrLoadWorkflowExecution(DO_WHILE_WF + "_3", 1, "looptest", input, null, null);
    System.out.println("testDoWhile.wfid=" + workflowId);
    printTaskStatuses(workflowId, "initiated");
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks(), RUNNING, workflow.getStatus());
    Task task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("FORK_JOIN", "test");
    // fork task is completed
    assertNull(task);
    task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("JOIN", "test");
    // Both HTTP task completed.
    assertNull(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks(), WorkflowStatus.COMPLETED, workflow.getStatus());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) 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) ExpectedException(org.junit.rules.ExpectedException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Test(org.junit.Test)

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