use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class CassandraMetadataDAO method getTaskDefFromDB.
private TaskDef getTaskDefFromDB(String name) {
try {
ResultSet resultSet = session.execute(selectTaskDefStatement.bind(name));
recordCassandraDaoRequests("getTaskDef");
return Optional.ofNullable(resultSet.one()).map(row -> readValue(row.getString(TASK_DEFINITION_KEY), TaskDef.class)).orElse(null);
} catch (Exception e) {
Monitors.error(CLASS_NAME, "getTaskDef");
String errorMsg = String.format("Failed to get task def: %s", name);
LOGGER.error(errorMsg, e);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
}
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TestDeciderOutcomes method testOptional.
@Test
public void testOptional() {
WorkflowDef def = new WorkflowDef();
def.setName("test");
WorkflowTask task1 = new WorkflowTask();
task1.setName("task0");
task1.setType("SIMPLE");
task1.setTaskReferenceName("t0");
task1.getInputParameters().put("taskId", "${CPEWF_TASK_ID}");
task1.setOptional(true);
task1.setTaskDefinition(new TaskDef("task0"));
WorkflowTask task2 = new WorkflowTask();
task2.setName("task1");
task2.setType("SIMPLE");
task2.setTaskReferenceName("t1");
task2.setTaskDefinition(new TaskDef("task1"));
def.getTasks().add(task1);
def.getTasks().add(task2);
def.setSchemaVersion(2);
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(def);
workflow.setStartTime(System.currentTimeMillis());
DeciderOutcome outcome = deciderService.decide(workflow);
assertNotNull(outcome);
System.out.println("Schedule after starting: " + outcome.tasksToBeScheduled);
assertEquals(1, outcome.tasksToBeScheduled.size());
assertEquals(task1.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
System.out.println("TaskId of the scheduled task in input: " + outcome.tasksToBeScheduled.get(0).getInputData());
for (int i = 0; i < 3; i++) {
String task1Id = outcome.tasksToBeScheduled.get(0).getTaskId();
assertEquals(task1Id, outcome.tasksToBeScheduled.get(0).getInputData().get("taskId"));
workflow.getTasks().clear();
workflow.getTasks().addAll(outcome.tasksToBeScheduled);
workflow.getTasks().get(0).setStatus(Status.FAILED);
outcome = deciderService.decide(workflow);
assertNotNull(outcome);
System.out.println("Schedule: " + outcome.tasksToBeScheduled);
System.out.println("Update: " + outcome.tasksToBeUpdated);
assertEquals(1, outcome.tasksToBeUpdated.size());
assertEquals(1, outcome.tasksToBeScheduled.size());
assertEquals(Task.Status.FAILED, workflow.getTasks().get(0).getStatus());
assertEquals(task1Id, outcome.tasksToBeUpdated.get(0).getTaskId());
assertEquals(task1.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
assertEquals(i + 1, outcome.tasksToBeScheduled.get(0).getRetryCount());
}
String task1Id = outcome.tasksToBeScheduled.get(0).getTaskId();
workflow.getTasks().clear();
workflow.getTasks().addAll(outcome.tasksToBeScheduled);
workflow.getTasks().get(0).setStatus(Status.FAILED);
outcome = deciderService.decide(workflow);
assertNotNull(outcome);
System.out.println("Schedule: " + outcome.tasksToBeScheduled);
System.out.println("Update: " + outcome.tasksToBeUpdated);
assertEquals(1, outcome.tasksToBeUpdated.size());
assertEquals(1, outcome.tasksToBeScheduled.size());
assertEquals(Task.Status.COMPLETED_WITH_ERRORS, workflow.getTasks().get(0).getStatus());
assertEquals(task1Id, outcome.tasksToBeUpdated.get(0).getTaskId());
assertEquals(task2.getTaskReferenceName(), outcome.tasksToBeScheduled.get(0).getReferenceTaskName());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef 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.TaskDef in project conductor by Netflix.
the class TestDeciderService method testCustomRetryWithWorkflowTask.
@Test
public void testCustomRetryWithWorkflowTask() {
Workflow workflow = createDefaultWorkflow();
Task task = new Task();
task.setStatus(Status.FAILED);
task.setTaskId("t1");
task.setStartDelayInSeconds(30);
TaskDef taskDef = new TaskDef();
taskDef.setRetryDelaySeconds(60);
taskDef.setRetryLogic(TaskDef.RetryLogic.CUSTOM);
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.setRetryLogic(RetryLogic.FIXED);
workflowTask.setStartDelay(80);
// Retry delay from the task as tasDef retry policy is CUSTOM,
// but workflow task would be preferred which is FIXED (retryDelay will come from workflowTask)
Optional<Task> task2 = deciderService.retry(taskDef, workflowTask, task, workflow);
assertEquals(80, task2.get().getStartDelayInSeconds());
// Retry delay from the task as tasDef retry policy is CUSTOM,
// but workflow task would be preferred which is CUSTOM (retryDelay will be 0 since task.retryDelay = -1)
task2.get().setStartDelayInSeconds(-1);
workflowTask.setRetryLogic(RetryLogic.CUSTOM);
workflowTask.setStartDelay(90);
// Custom retry policy from Workflow,
Optional<Task> task3 = deciderService.retry(taskDef, workflowTask, task2.get(), workflow);
assertEquals(0, task3.get().getStartDelayInSeconds());
// Retry delay from the task as tasDef retry policy is CUSTOM,
// workflow task would be preferred which is CUSTOM (retryDelay will come from the workflowTask,
// since task.retryDelay = 0)
task3.get().setStartDelayInSeconds(0);
Optional<Task> task4 = deciderService.retry(taskDef, workflowTask, task3.get(), workflow);
assertEquals(90, task4.get().getCallbackAfterSeconds());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TestDeciderService method testGetTaskInputV2Partial.
@Test
public void testGetTaskInputV2Partial() {
Workflow workflow = createDefaultWorkflow();
System.setProperty("EC2_INSTANCE", "i-123abcdef990");
Map<String, Object> wfi = new HashMap<>();
Map<String, Object> wfmap = new HashMap<>();
wfmap.put("input", workflow.getInput());
wfmap.put("output", workflow.getOutput());
wfi.put("workflow", wfmap);
workflow.getTasks().stream().map(Task::getReferenceTaskName).forEach(ref -> {
Map<String, Object> taskInput = workflow.getTaskByRefName(ref).getInputData();
Map<String, Object> taskOutput = workflow.getTaskByRefName(ref).getOutputData();
Map<String, Object> io = new HashMap<>();
io.put("input", taskInput);
io.put("output", taskOutput);
wfi.put(ref, io);
});
workflow.getWorkflowDefinition().setSchemaVersion(2);
Map<String, Object> ip = new HashMap<>();
ip.put("workflowInputParam", "${workflow.input.requestId}");
ip.put("workfowOutputParam", "${workflow.output.name}");
ip.put("taskOutputParam", "${task2.output.location}");
ip.put("taskOutputParam2", "${task2.output.locationBad}");
ip.put("taskOutputParam3", "${task3.output.location}");
ip.put("constParam", "Some String value &");
ip.put("partial", "${task2.output.location}/something?host=${EC2_INSTANCE}");
ip.put("jsonPathExtracted", "${workflow.output.names[*].year}");
ip.put("secondName", "${workflow.output.names[1].name}");
ip.put("concatenatedName", "The Band is: ${workflow.output.names[1].name}-\t${EC2_INSTANCE}");
TaskDef taskDef = new TaskDef();
taskDef.getInputTemplate().put("opname", "${workflow.output.name}");
List<Object> listParams = new LinkedList<>();
List<Object> listParams2 = new LinkedList<>();
listParams2.add("${workflow.input.requestId}-10-${EC2_INSTANCE}");
listParams.add(listParams2);
Map<String, Object> map = new HashMap<>();
map.put("name", "${workflow.output.names[0].name}");
map.put("hasAwards", "${workflow.input.hasAwards}");
listParams.add(map);
taskDef.getInputTemplate().put("listValues", listParams);
Map<String, Object> taskInput = parametersUtils.getTaskInput(ip, workflow, taskDef, null);
assertNotNull(taskInput);
assertTrue(taskInput.containsKey("workflowInputParam"));
assertTrue(taskInput.containsKey("taskOutputParam"));
assertTrue(taskInput.containsKey("taskOutputParam2"));
assertTrue(taskInput.containsKey("taskOutputParam3"));
assertNull(taskInput.get("taskOutputParam2"));
assertNotNull(taskInput.get("jsonPathExtracted"));
assertTrue(taskInput.get("jsonPathExtracted") instanceof List);
assertNotNull(taskInput.get("secondName"));
assertTrue(taskInput.get("secondName") instanceof String);
assertEquals("The Doors", taskInput.get("secondName"));
assertEquals("The Band is: The Doors-\ti-123abcdef990", taskInput.get("concatenatedName"));
assertEquals("request id 001", taskInput.get("workflowInputParam"));
assertEquals("http://location", taskInput.get("taskOutputParam"));
assertNull(taskInput.get("taskOutputParam3"));
assertNotNull(taskInput.get("partial"));
assertEquals("http://location/something?host=i-123abcdef990", taskInput.get("partial"));
}
Aggregations