use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class CassandraExecutionDAO method createWorkflow.
@Override
public String createWorkflow(Workflow workflow) {
try {
List<Task> tasks = workflow.getTasks();
workflow.setTasks(new LinkedList<>());
String payload = toJson(workflow);
recordCassandraDaoRequests("createWorkflow", "n/a", workflow.getWorkflowName());
recordCassandraDaoPayloadSize("createWorkflow", payload.length(), "n/a", workflow.getWorkflowName());
session.execute(insertWorkflowStatement.bind(UUID.fromString(workflow.getWorkflowId()), 1, "", payload, 0, 1));
workflow.setTasks(tasks);
return workflow.getWorkflowId();
} catch (Exception e) {
Monitors.error(CLASS_NAME, "createWorkflow");
String errorMsg = String.format("Error creating workflow: %s", workflow.getWorkflowId());
LOGGER.error(errorMsg, e);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
}
}
use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class TaskClient method pollTask.
/**
* Perform a poll for a task of a specific task type.
*
* @param taskType The taskType to poll for
* @param domain The domain of the task type
* @param workerId Name of the client worker. Used for logging.
* @return Task waiting to be executed.
*/
public Task pollTask(String taskType, String workerId, String domain) {
Preconditions.checkArgument(StringUtils.isNotBlank(taskType), "Task type cannot be blank");
Preconditions.checkArgument(StringUtils.isNotBlank(workerId), "Worker id cannot be blank");
Object[] params = new Object[] { "workerid", workerId, "domain", domain };
Task task = Optional.ofNullable(getForEntity("tasks/poll/{taskType}", params, Task.class, taskType)).orElse(new Task());
populateTaskPayloads(task);
return task;
}
use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class TestDeciderOutcomes method testOptionalWithDynamicFork.
@Test
public void testOptionalWithDynamicFork() {
WorkflowDef def = new WorkflowDef();
def.setName("test");
WorkflowTask task1 = new WorkflowTask();
task1.setName("fork0");
task1.setWorkflowTaskType(TaskType.FORK_JOIN_DYNAMIC);
task1.setTaskReferenceName("fork0");
task1.setDynamicForkTasksInputParamName("forkedInputs");
task1.setDynamicForkTasksParam("forks");
task1.getInputParameters().put("forks", "${workflow.input.forks}");
task1.getInputParameters().put("forkedInputs", "${workflow.input.forkedInputs}");
WorkflowTask task2 = new WorkflowTask();
task2.setName("join0");
task2.setType("JOIN");
task2.setTaskReferenceName("join0");
def.getTasks().add(task1);
def.getTasks().add(task2);
def.setSchemaVersion(2);
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(def);
List<WorkflowTask> forks = new LinkedList<>();
Map<String, Map<String, Object>> forkedInputs = new HashMap<>();
for (int i = 0; i < 3; i++) {
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setName("f" + i);
workflowTask.setTaskReferenceName("f" + i);
workflowTask.setWorkflowTaskType(TaskType.SIMPLE);
workflowTask.setOptional(true);
workflowTask.setTaskDefinition(new TaskDef("f" + i));
forks.add(workflowTask);
forkedInputs.put(workflowTask.getTaskReferenceName(), new HashMap<>());
}
workflow.getInput().put("forks", forks);
workflow.getInput().put("forkedInputs", forkedInputs);
workflow.setStartTime(System.currentTimeMillis());
DeciderOutcome outcome = deciderService.decide(workflow);
assertNotNull(outcome);
assertEquals(5, outcome.tasksToBeScheduled.size());
assertEquals(0, outcome.tasksToBeUpdated.size());
assertEquals(SystemTaskType.FORK.name(), outcome.tasksToBeScheduled.get(0).getTaskType());
assertEquals(Task.Status.COMPLETED, outcome.tasksToBeScheduled.get(0).getStatus());
for (int retryCount = 0; retryCount < 4; retryCount++) {
for (Task taskToBeScheduled : outcome.tasksToBeScheduled) {
if (taskToBeScheduled.getTaskDefName().equals("join0")) {
assertEquals(Task.Status.IN_PROGRESS, taskToBeScheduled.getStatus());
} else if (taskToBeScheduled.getTaskType().matches("(f0|f1|f2)")) {
assertEquals(Task.Status.SCHEDULED, taskToBeScheduled.getStatus());
taskToBeScheduled.setStatus(Status.FAILED);
}
taskToBeScheduled.setUpdateTime(System.currentTimeMillis());
}
workflow.getTasks().addAll(outcome.tasksToBeScheduled);
outcome = deciderService.decide(workflow);
assertNotNull(outcome);
}
assertEquals(SystemTaskType.JOIN.name(), outcome.tasksToBeScheduled.get(0).getTaskType());
for (int i = 0; i < 3; i++) {
assertEquals(Task.Status.COMPLETED_WITH_ERRORS, outcome.tasksToBeUpdated.get(i).getStatus());
assertEquals("f" + (i), outcome.tasksToBeUpdated.get(i).getTaskDefName());
}
assertEquals(Task.Status.IN_PROGRESS, outcome.tasksToBeScheduled.get(0).getStatus());
new Join().execute(workflow, outcome.tasksToBeScheduled.get(0), null);
assertEquals(Task.Status.COMPLETED, outcome.tasksToBeScheduled.get(0).getStatus());
outcome.tasksToBeScheduled.stream().map(task -> task.getStatus() + ":" + task.getTaskType() + ":").forEach(System.out::println);
outcome.tasksToBeUpdated.stream().map(task -> task.getStatus() + ":" + task.getTaskType() + ":").forEach(System.out::println);
}
use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class TestDeciderService method testGetTaskInput.
@SuppressWarnings("unchecked")
@Test
public void testGetTaskInput() {
Map<String, Object> ip = new HashMap<>();
ip.put("workflowInputParam", "${workflow.input.requestId}");
ip.put("taskOutputParam", "${task2.output.location}");
List<Map<String, Object>> json = new LinkedList<>();
Map<String, Object> m1 = new HashMap<>();
m1.put("name", "person name");
m1.put("city", "New York");
m1.put("phone", 2120001234);
m1.put("status", "${task2.output.isPersonActive}");
Map<String, Object> m2 = new HashMap<>();
m2.put("employer", "City Of New York");
m2.put("color", "purple");
m2.put("requestId", "${workflow.input.requestId}");
json.add(m1);
json.add(m2);
ip.put("complexJson", json);
WorkflowDef def = new WorkflowDef();
def.setName("testGetTaskInput");
def.setSchemaVersion(2);
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(def);
workflow.getInput().put("requestId", "request id 001");
Task task = new Task();
task.setReferenceTaskName("task2");
task.getOutputData().put("location", "http://location");
task.getOutputData().put("isPersonActive", true);
workflow.getTasks().add(task);
Map<String, Object> taskInput = parametersUtils.getTaskInput(ip, workflow, null, null);
assertNotNull(taskInput);
assertTrue(taskInput.containsKey("workflowInputParam"));
assertTrue(taskInput.containsKey("taskOutputParam"));
assertEquals("request id 001", taskInput.get("workflowInputParam"));
assertEquals("http://location", taskInput.get("taskOutputParam"));
assertNotNull(taskInput.get("complexJson"));
assertTrue(taskInput.get("complexJson") instanceof List);
List<Map<String, Object>> resolvedInput = (List<Map<String, Object>>) taskInput.get("complexJson");
assertEquals(2, resolvedInput.size());
}
use of com.netflix.conductor.common.metadata.tasks.Task in project conductor by Netflix.
the class TestDeciderService method testDeciderGetNextTask.
@Test
public void testDeciderGetNextTask() {
WorkflowDef workflowDef = createDoWhileInForkWorkflow();
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(workflowDef);
Task task1 = new Task();
task1.setReferenceTaskName("fork");
task1.setStatus(Status.COMPLETED);
task1.setTaskId("task1");
Task task2 = new Task();
task2.setReferenceTaskName("loopTask");
task2.setStatus(Status.SCHEDULED);
task2.setTaskId("task2");
task2.setIteration(1);
Task task3 = new Task();
task3.setReferenceTaskName("junit_task_0__1");
task3.setStatus(Status.COMPLETED);
task3.setTaskId("task3");
task3.setIteration(1);
Task task4 = new Task();
task4.setReferenceTaskName("junit_task_3");
task4.setStatus(Status.COMPLETED);
task4.setTaskId("task4");
Task task5 = new Task();
task5.setReferenceTaskName("join");
task5.setStatus(Status.IN_PROGRESS);
task5.setTaskId("task5");
workflow.setTasks(Arrays.asList(task1, task2, task3, task4, task5));
// verify the next task of first task in DoWhile
List<Task> nextTask1 = deciderService.getNextTask(workflow, task3);
assertEquals(1, nextTask1.size());
assertEquals("junit_task_1", nextTask1.get(0).getReferenceTaskName());
Task task6 = new Task();
task6.setReferenceTaskName("junit_task_1__1");
task6.setStatus(Status.COMPLETED);
task6.setTaskId("task6");
task6.setIteration(1);
workflow.setTasks(Arrays.asList(task1, task2, task3, task4, task5, task6));
// verify the next task of last task in DoWhile
List<Task> nextTask2 = deciderService.getNextTask(workflow, task6);
assertEquals(0, nextTask2.size());
task2.setStatus(Status.COMPLETED);
task2.setIteration(10);
// verify the next task of DoWhile
List<Task> nextTask3 = deciderService.getNextTask(workflow, task2);
assertEquals(1, nextTask3.size());
assertEquals("junit_task_2", nextTask3.get(0).getReferenceTaskName());
}
Aggregations