use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class ExclusiveJoinEndToEndTest method testDecision1TrueAndDecision2Default.
@Test
public void testDecision1TrueAndDecision2Default() {
workflowInput.put("decision_1", "true");
workflowInput.put("decision_2", "null");
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(CONDUCTOR_WORKFLOW_DEF_NAME).withCorrelationId("").withInput(workflowInput).withVersion(1);
String wfInstanceId = workflowClient.startWorkflow(startWorkflowRequest);
String taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task1").getTaskId();
taskOutput.put("taskReferenceName", "task1");
TaskResult taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
taskClient.updateTask(taskResult);
taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task2").getTaskId();
taskOutput.put("taskReferenceName", "task2");
taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
taskClient.updateTask(taskResult);
Workflow workflow = workflowClient.getWorkflow(wfInstanceId, true);
String taskReferenceName = workflow.getTaskByRefName("exclusiveJoin").getOutputData().get("taskReferenceName").toString();
assertEquals("task2", taskReferenceName);
assertEquals(Workflow.WorkflowStatus.COMPLETED, workflow.getStatus());
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class ExclusiveJoinEndToEndTest method testDecision1FalseAndDecision3Default.
@Test
public void testDecision1FalseAndDecision3Default() {
workflowInput.put("decision_1", "false");
workflowInput.put("decision_3", "null");
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(CONDUCTOR_WORKFLOW_DEF_NAME).withCorrelationId("").withInput(workflowInput).withVersion(1);
String wfInstanceId = workflowClient.startWorkflow(startWorkflowRequest);
String taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task1").getTaskId();
taskOutput.put("taskReferenceName", "task1");
TaskResult taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
taskClient.updateTask(taskResult);
taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task4").getTaskId();
taskOutput.put("taskReferenceName", "task4");
taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
taskClient.updateTask(taskResult);
Workflow workflow = workflowClient.getWorkflow(wfInstanceId, true);
String taskReferenceName = workflow.getTaskByRefName("exclusiveJoin").getOutputData().get("taskReferenceName").toString();
assertEquals("task4", taskReferenceName);
assertEquals(Workflow.WorkflowStatus.COMPLETED, workflow.getStatus());
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class ExclusiveJoinEndToEndTest method testDecision1Default.
@Test
public void testDecision1Default() {
workflowInput.put("decision_1", "null");
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(CONDUCTOR_WORKFLOW_DEF_NAME).withCorrelationId("").withInput(workflowInput).withVersion(1);
String wfInstanceId = workflowClient.startWorkflow(startWorkflowRequest);
String taskId = taskClient.getPendingTaskForWorkflow(wfInstanceId, "task1").getTaskId();
taskOutput.put("taskReferenceName", "task1");
TaskResult taskResult = setTaskResult(wfInstanceId, taskId, TaskResult.Status.COMPLETED, taskOutput);
taskClient.updateTask(taskResult);
Workflow workflow = workflowClient.getWorkflow(wfInstanceId, true);
String taskReferenceName = workflow.getTaskByRefName("exclusiveJoin").getOutputData().get("taskReferenceName").toString();
assertEquals("task1", taskReferenceName);
assertEquals(Workflow.WorkflowStatus.COMPLETED, workflow.getStatus());
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class AbstractWorkflowServiceTest method testSimpleWorkflowWithOptionalTask.
@Test
public void testSimpleWorkflowWithOptionalTask() throws Exception {
createOptionalTaskWorkflow();
metadataService.getWorkflowDef(WORKFLOW_WITH_OPTIONAL_TASK, 1);
String correlationId = "unit_test_1";
Map<String, Object> workflowInput = new HashMap<>();
String inputParam1 = "p1 value";
workflowInput.put("param1", inputParam1);
workflowInput.put("param2", "p2 value");
String workflowId = startOrLoadWorkflowExecution(WORKFLOW_WITH_OPTIONAL_TASK, 1, correlationId, workflowInput, null, null);
logger.debug("testSimpleWorkflowWithOptionalTask.wfid=" + workflowId);
assertNotNull(workflowId);
Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
// The very first task is the one that should be scheduled.
assertEquals(1, workflow.getTasks().size());
assertEquals(1, queueDAO.getSize("task_optional"));
// Polling for the first task should return the first task
Task task = workflowExecutionService.poll("task_optional", "task1.junit.worker.optional");
assertNotNull(task);
assertEquals("task_optional", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
assertEquals(workflowId, task.getWorkflowInstanceId());
// As the task_optional is out of the queue, the next poll should not get it
Task nullTask = workflowExecutionService.poll("task_optional", "task1.junit.worker.optional");
assertNull(nullTask);
TaskResult taskResult = new TaskResult(task);
taskResult.setReasonForIncompletion("NETWORK ERROR");
taskResult.setStatus(TaskResult.Status.FAILED);
workflowExecutionService.updateTask(taskResult);
workflowExecutor.decide(workflowId);
assertEquals(1, queueDAO.getSize("task_optional"));
// The first task would be failed and a new task will be scheduled
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(RUNNING, workflow.getStatus());
assertEquals(2, workflow.getTasks().size());
assertTrue(workflow.getTasks().stream().allMatch(t -> t.getReferenceTaskName().equals("task_optional_t1")));
assertEquals(FAILED, workflow.getTasks().get(0).getStatus());
assertEquals(SCHEDULED, workflow.getTasks().get(1).getStatus());
// Polling now should get the same task back because it should have been put back in the queue
Task taskAgain = workflowExecutionService.poll("task_optional", "task1.junit.worker");
assertNotNull(taskAgain);
Thread.sleep(5000);
// The second task would be timed-out and completed with errors
workflowExecutor.decide(workflowId);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(0, queueDAO.getSize("task_optional"));
assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
System.out.println(workflow.getTasks());
System.out.println(workflow.getTasks().get(1));
System.out.println(workflow.getTasks().get(2));
assertEquals(3, workflow.getTasks().size());
assertEquals(COMPLETED_WITH_ERRORS, workflow.getTasks().get(1).getStatus());
// poll for next task
task = workflowExecutionService.poll("junit_task_2", "task2.junit.worker.testTimeout");
assertNotNull(task);
assertEquals("junit_task_2", task.getTaskType());
assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
task.setStatus(COMPLETED);
task.setReasonForIncompletion("unit test failure");
workflowExecutionService.updateTask(task);
workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
}
use of com.netflix.conductor.common.metadata.tasks.TaskResult in project conductor by Netflix.
the class AbstractHttpEndToEndTest method testAll.
@Test
public void testAll() throws Exception {
createAndRegisterTaskDefinitions("t", 5);
WorkflowDef def = new WorkflowDef();
def.setName("test");
def.setOwnerEmail(DEFAULT_EMAIL_ADDRESS);
WorkflowTask t0 = new WorkflowTask();
t0.setName("t0");
t0.setWorkflowTaskType(TaskType.SIMPLE);
t0.setTaskReferenceName("t0");
WorkflowTask t1 = new WorkflowTask();
t1.setName("t1");
t1.setWorkflowTaskType(TaskType.SIMPLE);
t1.setTaskReferenceName("t1");
def.getTasks().add(t0);
def.getTasks().add(t1);
metadataClient.registerWorkflowDef(def);
WorkflowDef workflowDefinitionFromSystem = metadataClient.getWorkflowDef(def.getName(), null);
assertNotNull(workflowDefinitionFromSystem);
assertEquals(def, workflowDefinitionFromSystem);
String correlationId = "test_corr_id";
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(def.getName()).withCorrelationId(correlationId).withPriority(50).withInput(new HashMap<>());
String workflowId = workflowClient.startWorkflow(startWorkflowRequest);
assertNotNull(workflowId);
Workflow workflow = workflowClient.getWorkflow(workflowId, false);
assertEquals(0, workflow.getTasks().size());
assertEquals(workflowId, workflow.getWorkflowId());
Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
List<Workflow> workflowList = workflowClient.getWorkflows(def.getName(), correlationId, false, false);
assertEquals(1, workflowList.size());
assertEquals(workflowId, workflowList.get(0).getWorkflowId());
});
workflow = workflowClient.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(1, workflow.getTasks().size());
assertEquals(t0.getTaskReferenceName(), workflow.getTasks().get(0).getReferenceTaskName());
assertEquals(workflowId, workflow.getWorkflowId());
int queueSize = taskClient.getQueueSizeForTask(workflow.getTasks().get(0).getTaskType());
assertEquals(1, queueSize);
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());
workflow = workflowClient.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(2, workflow.getTasks().size());
assertEquals(t0.getTaskReferenceName(), workflow.getTasks().get(0).getReferenceTaskName());
assertEquals(t1.getTaskReferenceName(), workflow.getTasks().get(1).getReferenceTaskName());
assertEquals(Task.Status.COMPLETED, workflow.getTasks().get(0).getStatus());
assertEquals(Task.Status.SCHEDULED, workflow.getTasks().get(1).getStatus());
Task taskById = taskClient.getTaskDetails(task.getTaskId());
assertNotNull(taskById);
assertEquals(task.getTaskId(), taskById.getTaskId());
queueSize = taskClient.getQueueSizeForTask(workflow.getTasks().get(1).getTaskType());
assertEquals(1, queueSize);
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(workflow.getWorkflowId(), searchResult.getResults().get(0).getWorkflowId());
SearchResult<Workflow> searchResultV2 = workflowClient.searchV2("workflowType='" + def.getName() + "'");
assertNotNull(searchResultV2);
assertEquals(1, searchResultV2.getTotalHits());
assertEquals(workflow.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(workflow.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(workflow.getWorkflowId(), searchResultV2Advanced.getResults().get(0).getWorkflowId());
workflowClient.terminateWorkflow(workflowId, "terminate reason");
workflow = workflowClient.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.TERMINATED, workflow.getStatus());
workflowClient.restart(workflowId, false);
workflow = workflowClient.getWorkflow(workflowId, true);
assertNotNull(workflow);
assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
assertEquals(1, workflow.getTasks().size());
workflowClient.skipTaskFromWorkflow(workflowId, "t1");
}
Aggregations