use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class TestSimpleActionProcessor method testCompleteTaskByTaskId.
@Test
public void testCompleteTaskByTaskId() throws Exception {
TaskDetails taskDetails = new TaskDetails();
taskDetails.setWorkflowId("${workflowId}");
taskDetails.setTaskId("${taskId}");
Action action = new Action();
action.setAction(Type.complete_task);
action.setComplete_task(taskDetails);
Object payload = objectMapper.readValue("{\"workflowId\":\"workflow_1\", \"taskId\":\"task_1\"}", Object.class);
Task task = new Task();
task.setTaskId("task_1");
task.setReferenceTaskName("testTask");
when(workflowExecutor.getTask(eq("task_1"))).thenReturn(task);
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("task_1", argumentCaptor.getValue().getOutputData().get("taskId"));
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class SimpleActionProcessor method completeTask.
private Map<String, Object> completeTask(Action action, Object payload, TaskDetails taskDetails, Status status, String event, String messageId) {
Map<String, Object> input = new HashMap<>();
input.put("workflowId", taskDetails.getWorkflowId());
input.put("taskId", taskDetails.getTaskId());
input.put("taskRefName", taskDetails.getTaskRefName());
input.putAll(taskDetails.getOutput());
Map<String, Object> replaced = parametersUtils.replace(input, payload);
String workflowId = (String) replaced.get("workflowId");
String taskId = (String) replaced.get("taskId");
String taskRefName = (String) replaced.get("taskRefName");
Task task = null;
if (StringUtils.isNotEmpty(taskId)) {
task = executor.getTask(taskId);
} else if (StringUtils.isNotEmpty(workflowId) && StringUtils.isNotEmpty(taskRefName)) {
Workflow workflow = executor.getWorkflow(workflowId, true);
if (workflow == null) {
replaced.put("error", "No workflow found with ID: " + workflowId);
return replaced;
}
task = workflow.getTaskByRefName(taskRefName);
}
if (task == null) {
replaced.put("error", "No task found with taskId: " + taskId + ", reference name: " + taskRefName + ", workflowId: " + workflowId);
return replaced;
}
task.setStatus(status);
task.setOutputData(replaced);
task.setOutputMessage(taskDetails.getOutputMessage());
task.getOutputData().put("conductor.event.messageId", messageId);
task.getOutputData().put("conductor.event.name", event);
try {
executor.updateTask(new TaskResult(task));
logger.debug("Updated task: {} in workflow:{} with status: {} for event: {} for message:{}", taskId, workflowId, status, event, messageId);
} catch (RuntimeException e) {
Monitors.recordEventActionError(action.getAction().name(), task.getTaskType(), event);
logger.error("Error updating task: {} in workflow: {} in action: {} for event: {} for message: {}", taskDetails.getTaskRefName(), taskDetails.getWorkflowId(), action.getAction(), event, messageId, e);
replaced.put("error", e.getMessage());
throw e;
}
return replaced;
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class TaskServiceTest method testUpdateTaskInValid.
@Test(expected = ConstraintViolationException.class)
public void testUpdateTaskInValid() {
try {
TaskResult taskResult = new TaskResult();
taskService.updateTask(taskResult);
} catch (ConstraintViolationException ex) {
assertEquals(2, ex.getConstraintViolations().size());
Set<String> messages = getConstraintViolationMessages(ex.getConstraintViolations());
assertTrue(messages.contains("Workflow Id cannot be null or empty"));
assertTrue(messages.contains("Task ID cannot be null or empty"));
throw ex;
}
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testKafkaTaskDefTemplateSuccess.
@Test
public void testKafkaTaskDefTemplateSuccess() throws Exception {
try {
registerKafkaWorkflow();
} catch (ApplicationException e) {
}
Map<String, Object> input = getKafkaInput();
String workflowInstanceId = startOrLoadWorkflowExecution("template_kafka_workflow", 1, "testTaskDefTemplate", input, null, null);
assertNotNull(workflowInstanceId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowInstanceId, true);
assertNotNull(workflow);
assertTrue(workflow.getReasonForIncompletion(), !workflow.getStatus().isTerminal());
assertEquals(1, workflow.getTasks().size());
Task task = workflow.getTasks().get(0);
Map<String, Object> taskInput = task.getInputData();
assertNotNull(taskInput);
assertTrue(taskInput.containsKey("kafka_request"));
assertTrue(taskInput.get("kafka_request") instanceof Map);
String expected = "{\"kafka_request\":{\"topic\":\"test_kafka_topic\",\"bootStrapServers\":\"localhost:9092\",\"value\":{\"requestDetails\":{\"key1\":\"value1\",\"key2\":42},\"outputPath\":\"s3://bucket/outputPath\",\"inputPaths\":[\"file://path1\",\"file://path2\"]}}}";
assertEquals(expected, objectMapper.writeValueAsString(taskInput));
TaskResult taskResult = new TaskResult(task);
taskResult.setStatus(TaskResult.Status.COMPLETED);
// Polling for the first task
Task task1 = workflowExecutionService.poll("KAFKA_PUBLISH", "test");
assertNotNull(task1);
assertTrue(workflowExecutionService.ackTaskReceived(task1.getTaskId()));
assertEquals(workflowInstanceId, task1.getWorkflowInstanceId());
workflowExecutionService.updateTask(taskResult);
workflowExecutor.decide(workflowInstanceId);
workflow = workflowExecutionService.getExecutionStatus(workflowInstanceId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testWait.
@Test
public void testWait() {
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("test_wait");
workflowDef.setSchemaVersion(2);
WorkflowTask waitWorkflowTask = new WorkflowTask();
waitWorkflowTask.setWorkflowTaskType(TaskType.WAIT);
waitWorkflowTask.setName("wait");
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());
Task waitTask = workflow.getTasks().get(0);
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());
}
Aggregations