use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class TestSimpleActionProcessor method testCompleteTask.
@Test
public void testCompleteTask() throws Exception {
TaskDetails taskDetails = new TaskDetails();
taskDetails.setWorkflowId("${workflowId}");
taskDetails.setTaskRefName("testTask");
taskDetails.getOutput().put("someNEKey", "${Message.someNEKey}");
taskDetails.getOutput().put("someKey", "${Message.someKey}");
taskDetails.getOutput().put("someNullKey", "${Message.someNullKey}");
Action action = new Action();
action.setAction(Type.complete_task);
action.setComplete_task(taskDetails);
String payloadJson = "{\"workflowId\":\"workflow_1\",\"Message\":{\"someKey\":\"someData\",\"someNullKey\":null}}";
Object payload = objectMapper.readValue(payloadJson, Object.class);
Task task = new Task();
task.setReferenceTaskName("testTask");
Workflow workflow = new Workflow();
workflow.getTasks().add(task);
when(workflowExecutor.getWorkflow(eq("workflow_1"), anyBoolean())).thenReturn(workflow);
actionProcessor.execute(action, payload, "testEvent", "testMessage");
ArgumentCaptor<TaskResult> argumentCaptor = ArgumentCaptor.forClass(TaskResult.class);
verify(workflowExecutor).updateTask(argumentCaptor.capture());
assertEquals(Status.COMPLETED, argumentCaptor.getValue().getStatus());
assertEquals("testMessage", argumentCaptor.getValue().getOutputData().get("conductor.event.messageId"));
assertEquals("testEvent", argumentCaptor.getValue().getOutputData().get("conductor.event.name"));
assertEquals("workflow_1", argumentCaptor.getValue().getOutputData().get("workflowId"));
assertEquals("testTask", argumentCaptor.getValue().getOutputData().get("taskRefName"));
assertEquals("someData", argumentCaptor.getValue().getOutputData().get("someKey"));
// Assert values not in message are evaluated to null
assertTrue("testTask", argumentCaptor.getValue().getOutputData().containsKey("someNEKey"));
// Assert null values from message are kept
assertTrue("testTask", argumentCaptor.getValue().getOutputData().containsKey("someNullKey"));
assertNull("testTask", argumentCaptor.getValue().getOutputData().get("someNullKey"));
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testWaitTimeout.
@Test
public void testWaitTimeout() throws Exception {
TaskDef taskDef = new TaskDef();
taskDef.setName("waitTimeout");
taskDef.setTimeoutSeconds(2);
taskDef.setRetryCount(1);
taskDef.setTimeoutPolicy(TimeoutPolicy.RETRY);
taskDef.setRetryDelaySeconds(10);
metadataService.registerTaskDef(Collections.singletonList(taskDef));
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("test_wait_timeout");
workflowDef.setSchemaVersion(2);
WorkflowTask waitWorkflowTask = new WorkflowTask();
waitWorkflowTask.setWorkflowTaskType(TaskType.WAIT);
waitWorkflowTask.setName("waitTimeout");
waitWorkflowTask.setTaskReferenceName("wait0");
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setName("junit_task_1");
workflowTask.setTaskReferenceName("t1");
workflowDef.getTasks().add(waitWorkflowTask);
workflowDef.getTasks().add(workflowTask);
metadataService.registerWorkflowDef(workflowDef);
String workflowId = startOrLoadWorkflowExecution(workflowDef.getName(), workflowDef.getVersion(), "", new HashMap<>(), null, null);
Workflow workflow = workflowExecutor.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(1, workflow.getTasks().size());
assertEquals(RUNNING, workflow.getStatus());
// timeout the wait task and ensure it is retried
Thread.sleep(3000);
workflowExecutor.decide(workflowId);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertEquals(RUNNING, workflow.getStatus());
assertEquals(2, workflow.getTasks().size());
assertEquals(TIMED_OUT, workflow.getTasks().get(0).getStatus());
assertEquals(IN_PROGRESS, workflow.getTasks().get(1).getStatus());
Task waitTask = workflow.getTasks().get(1);
assertEquals(TaskType.WAIT.name(), waitTask.getTaskType());
waitTask.setStatus(COMPLETED);
workflowExecutor.updateTask(new TaskResult(waitTask));
Task task = workflowExecutionService.poll("junit_task_1", "test");
assertNotNull(task);
task.setStatus(Status.COMPLETED);
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals("tasks:" + workflow.getTasks(), WorkflowStatus.COMPLETED, workflow.getStatus());
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testForkJoinWithOptionalSubworkflows.
@Test
public void testForkJoinWithOptionalSubworkflows() {
createForkJoinWorkflowWithOptionalSubworkflowForks();
Map<String, Object> workflowInput = new HashMap<>();
workflowInput.put("param1", "p1 value");
workflowInput.put("param2", "p2 value");
String workflowId = startOrLoadWorkflowExecution(WORKFLOW_FORK_JOIN_OPTIONAL_SW, 1, "", workflowInput, null, null);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
assertEquals("found " + workflow.getTasks().stream().map(Task::toString).collect(Collectors.toList()), 4, workflow.getTasks().size());
// Simulating SystemTaskWorkerCoordinator to execute async system tasks
String subWorkflowTaskId1 = workflow.getTaskByRefName("st1").getTaskId();
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId1, 1);
String subWorkflowTaskId2 = workflow.getTaskByRefName("st2").getTaskId();
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId2, 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
String subWorkflowId1 = workflow.getTasks().get(1).getSubWorkflowId();
Workflow subWorkflow1 = workflowExecutionService.getExecutionStatus(subWorkflowId1, true);
assertNotNull(subWorkflow1);
assertEquals(RUNNING, subWorkflow1.getStatus());
assertEquals(1, subWorkflow1.getTasks().size());
String subWorkflowId2 = workflow.getTasks().get(2).getSubWorkflowId();
Workflow subWorkflow2 = workflowExecutionService.getExecutionStatus(subWorkflowId2, true);
assertNotNull(subWorkflow2);
assertEquals(RUNNING, subWorkflow2.getStatus());
assertEquals(1, subWorkflow2.getTasks().size());
// fail sub-workflow 1
Task task = new Task();
while (!subWorkflowId1.equals(task.getWorkflowInstanceId())) {
task = workflowExecutionService.poll("simple_task_in_sub_wf", "junit.worker");
}
assertNotNull(task);
assertEquals("simple_task_in_sub_wf", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertEquals(subWorkflowId1, task.getWorkflowInstanceId());
TaskResult taskResult = new TaskResult(task);
taskResult.setReasonForIncompletion("fail task 1");
taskResult.setStatus(TaskResult.Status.FAILED);
workflowExecutionService.updateTask(taskResult);
subWorkflow1 = workflowExecutionService.getExecutionStatus(subWorkflowId1, true);
assertNotNull(subWorkflow1);
assertEquals(WorkflowStatus.FAILED, subWorkflow1.getStatus());
subWorkflow2 = workflowExecutionService.getExecutionStatus(subWorkflowId2, true);
assertNotNull(subWorkflow2);
assertEquals(RUNNING, subWorkflow2.getStatus());
// Execute again to re-evaluate the Subworkflow task.
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId1, 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(1).getStatus());
assertEquals(IN_PROGRESS, workflow.getTasks().get(2).getStatus());
// fail sub workflow 2
task = new Task();
while (!subWorkflowId2.equals(task.getWorkflowInstanceId())) {
task = workflowExecutionService.poll("simple_task_in_sub_wf", "junit.worker");
}
assertNotNull(task);
assertEquals("simple_task_in_sub_wf", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertEquals(subWorkflowId2, task.getWorkflowInstanceId());
taskResult = new TaskResult(task);
taskResult.setReasonForIncompletion("fail task 2");
taskResult.setStatus(TaskResult.Status.FAILED);
workflowExecutionService.updateTask(taskResult);
subWorkflow1 = workflowExecutionService.getExecutionStatus(subWorkflowId1, true);
assertNotNull(subWorkflow1);
assertEquals(WorkflowStatus.FAILED, subWorkflow1.getStatus());
subWorkflow2 = workflowExecutionService.getExecutionStatus(subWorkflowId2, true);
assertNotNull(subWorkflow2);
assertEquals(WorkflowStatus.FAILED, subWorkflow2.getStatus());
// Execute again to re-evaluate the Subworkflow task.
workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId2, 1);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
assertEquals(4, workflow.getTasks().size());
assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(1).getStatus());
assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(2).getStatus());
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class AbstractGrpcEndToEndTest method testAll.
@Test
public void testAll() throws Exception {
assertNotNull(taskClient);
List<TaskDef> defs = new LinkedList<>();
for (int i = 0; i < 5; i++) {
TaskDef def = new TaskDef("t" + i, "task " + i, DEFAULT_EMAIL_ADDRESS, 3, 60, 60);
def.setTimeoutPolicy(TimeoutPolicy.RETRY);
defs.add(def);
}
metadataClient.registerTaskDefs(defs);
for (int i = 0; i < 5; i++) {
final String taskName = "t" + i;
TaskDef def = metadataClient.getTaskDef(taskName);
assertNotNull(def);
assertEquals(taskName, def.getName());
}
WorkflowDef def = createWorkflowDefinition("test");
WorkflowTask t0 = createWorkflowTask("t0");
WorkflowTask t1 = createWorkflowTask("t1");
def.getTasks().add(t0);
def.getTasks().add(t1);
metadataClient.registerWorkflowDef(def);
WorkflowDef found = metadataClient.getWorkflowDef(def.getName(), null);
assertNotNull(found);
assertEquals(def, found);
String correlationId = "test_corr_id";
StartWorkflowRequest startWf = new StartWorkflowRequest();
startWf.setName(def.getName());
startWf.setCorrelationId(correlationId);
String workflowId = workflowClient.startWorkflow(startWf);
assertNotNull(workflowId);
System.out.println("Started workflow id=" + workflowId);
Workflow wf = workflowClient.getWorkflow(workflowId, false);
assertEquals(0, wf.getTasks().size());
assertEquals(workflowId, wf.getWorkflowId());
wf = workflowClient.getWorkflow(workflowId, true);
assertNotNull(wf);
assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
assertEquals(1, wf.getTasks().size());
assertEquals(t0.getTaskReferenceName(), wf.getTasks().get(0).getReferenceTaskName());
assertEquals(workflowId, wf.getWorkflowId());
List<String> runningIds = workflowClient.getRunningWorkflow(def.getName(), def.getVersion());
assertNotNull(runningIds);
assertEquals(1, runningIds.size());
assertEquals(workflowId, runningIds.get(0));
List<Task> polled = taskClient.batchPollTasksByTaskType("non existing task", "test", 1, 100);
assertNotNull(polled);
assertEquals(0, polled.size());
polled = taskClient.batchPollTasksByTaskType(t0.getName(), "test", 1, 100);
assertNotNull(polled);
assertEquals(1, polled.size());
assertEquals(t0.getName(), polled.get(0).getTaskDefName());
Task task = polled.get(0);
Boolean acked = taskClient.ack(task.getTaskId(), "test");
assertNotNull(acked);
assertTrue(acked);
task.getOutputData().put("key1", "value1");
task.setStatus(Status.COMPLETED);
taskClient.updateTask(new TaskResult(task));
polled = taskClient.batchPollTasksByTaskType(t0.getName(), "test", 1, 100);
assertNotNull(polled);
assertTrue(polled.toString(), polled.isEmpty());
wf = workflowClient.getWorkflow(workflowId, true);
assertNotNull(wf);
assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
assertEquals(2, wf.getTasks().size());
assertEquals(t0.getTaskReferenceName(), wf.getTasks().get(0).getReferenceTaskName());
assertEquals(t1.getTaskReferenceName(), wf.getTasks().get(1).getReferenceTaskName());
assertEquals(Status.COMPLETED, wf.getTasks().get(0).getStatus());
assertEquals(Status.SCHEDULED, wf.getTasks().get(1).getStatus());
Task taskById = taskClient.getTaskDetails(task.getTaskId());
assertNotNull(taskById);
assertEquals(task.getTaskId(), taskById.getTaskId());
List<Task> getTasks = taskClient.getPendingTasksByType(t0.getName(), null, 1);
assertNotNull(getTasks);
// getTasks only gives pending tasks
assertEquals(0, getTasks.size());
getTasks = taskClient.getPendingTasksByType(t1.getName(), null, 1);
assertNotNull(getTasks);
assertEquals(1, getTasks.size());
Task pending = taskClient.getPendingTaskForWorkflow(workflowId, t1.getTaskReferenceName());
assertNotNull(pending);
assertEquals(t1.getTaskReferenceName(), pending.getReferenceTaskName());
assertEquals(workflowId, pending.getWorkflowInstanceId());
Thread.sleep(1000);
SearchResult<WorkflowSummary> searchResult = workflowClient.search("workflowType='" + def.getName() + "'");
assertNotNull(searchResult);
assertEquals(1, searchResult.getTotalHits());
assertEquals(wf.getWorkflowId(), searchResult.getResults().get(0).getWorkflowId());
SearchResult<Workflow> searchResultV2 = workflowClient.searchV2("workflowType='" + def.getName() + "'");
assertNotNull(searchResultV2);
assertEquals(1, searchResultV2.getTotalHits());
assertEquals(wf.getWorkflowId(), searchResultV2.getResults().get(0).getWorkflowId());
SearchResult<WorkflowSummary> searchResultAdvanced = workflowClient.search(0, 1, null, null, "workflowType='" + def.getName() + "'");
assertNotNull(searchResultAdvanced);
assertEquals(1, searchResultAdvanced.getTotalHits());
assertEquals(wf.getWorkflowId(), searchResultAdvanced.getResults().get(0).getWorkflowId());
SearchResult<Workflow> searchResultV2Advanced = workflowClient.searchV2(0, 1, null, null, "workflowType='" + def.getName() + "'");
assertNotNull(searchResultV2Advanced);
assertEquals(1, searchResultV2Advanced.getTotalHits());
assertEquals(wf.getWorkflowId(), searchResultV2Advanced.getResults().get(0).getWorkflowId());
workflowClient.terminateWorkflow(workflowId, "terminate reason");
wf = workflowClient.getWorkflow(workflowId, true);
assertNotNull(wf);
assertEquals(WorkflowStatus.TERMINATED, wf.getStatus());
workflowClient.restart(workflowId, false);
wf = workflowClient.getWorkflow(workflowId, true);
assertNotNull(wf);
assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
assertEquals(1, wf.getTasks().size());
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSimpleWorkflowFailureWithTerminalError.
@Test
public void testSimpleWorkflowFailureWithTerminalError() throws Exception {
clearWorkflows();
TaskDef taskDef = notFoundSafeGetTaskDef("junit_task_1");
taskDef.setRetryCount(1);
metadataService.updateTaskDef(taskDef);
WorkflowDef workflowDef = metadataService.getWorkflowDef(LINEAR_WORKFLOW_T1_T2, 1);
assertNotNull(workflowDef);
Map<String, Object> outputParameters = workflowDef.getOutputParameters();
outputParameters.put("validationErrors", "${t1.output.ErrorMessage}");
metadataService.updateWorkflowDef(workflowDef);
String correlationId = "unit_test_1";
Map<String, Object> input = new HashMap<>();
input.put("param1", "p1 value");
input.put("param2", "p2 value");
String workflowInstanceId = startOrLoadWorkflowExecution("simpleWorkflowFailureWithTerminalError", LINEAR_WORKFLOW_T1_T2, 1, correlationId, input, null, null);
assertNotNull(workflowInstanceId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowInstanceId, true);
assertNotNull(workflow);
assertEquals(workflow.getReasonForIncompletion(), RUNNING, workflow.getStatus());
// The very first task is the one that should be scheduled.
assertEquals(1, workflow.getTasks().size());
boolean failed = false;
try {
workflowExecutor.rewind(workflowInstanceId, false);
} catch (ApplicationException ae) {
failed = true;
}
assertTrue(failed);
// Polling for the first task should return the same task as before
Task task = workflowExecutionService.poll("junit_task_1", "task1.junit.worker");
assertNotNull(task);
assertEquals("junit_task_1", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertEquals(workflowInstanceId, task.getWorkflowInstanceId());
TaskResult taskResult = new TaskResult(task);
taskResult.setReasonForIncompletion("NON TRANSIENT ERROR OCCURRED: An integration point required to complete the task is down");
taskResult.setStatus(TaskResult.Status.FAILED_WITH_TERMINAL_ERROR);
taskResult.addOutputData("TERMINAL_ERROR", "Integration endpoint down: FOOBAR");
taskResult.addOutputData("ErrorMessage", "There was a terminal error");
workflowExecutionService.updateTask(taskResult);
workflowExecutor.decide(workflowInstanceId);
workflow = workflowExecutionService.getExecutionStatus(workflowInstanceId, true);
TaskDef junit_task_1 = notFoundSafeGetTaskDef("junit_task_1");
Task t1 = workflow.getTaskByRefName("t1");
assertNotNull(workflow);
assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
assertEquals("NON TRANSIENT ERROR OCCURRED: An integration point required to complete the task is down", workflow.getReasonForIncompletion());
// Configured retries at the task definition level
assertEquals(1, junit_task_1.getRetryCount());
// Actual retries done on the task
assertEquals(0, t1.getRetryCount());
assertTrue(workflow.getOutput().containsKey("o1"));
assertEquals("p1 value", workflow.getOutput().get("o1"));
assertEquals(workflow.getOutput().get("validationErrors").toString(), "There was a terminal error");
outputParameters.remove("validationErrors");
metadataService.updateWorkflowDef(workflowDef);
}
Aggregations