use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TestDeciderService method testTaskRetry.
@SuppressWarnings("unchecked")
@Test
public void testTaskRetry() {
Workflow workflow = createDefaultWorkflow();
workflow.getWorkflowDefinition().setSchemaVersion(2);
Map<String, Object> inputParams = new HashMap<>();
inputParams.put("workflowInputParam", "${workflow.input.requestId}");
inputParams.put("taskOutputParam", "${task2.output.location}");
inputParams.put("constParam", "Some String value");
inputParams.put("nullValue", null);
inputParams.put("task2Status", "${task2.status}");
inputParams.put("null", null);
inputParams.put("task_id", "${CPEWF_TASK_ID}");
Map<String, Object> env = new HashMap<>();
env.put("env_task_id", "${CPEWF_TASK_ID}");
inputParams.put("env", env);
Map<String, Object> taskInput = parametersUtils.getTaskInput(inputParams, workflow, null, "t1");
Task task = new Task();
task.getInputData().putAll(taskInput);
task.setStatus(Status.FAILED);
task.setTaskId("t1");
TaskDef taskDef = new TaskDef();
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.getInputParameters().put("task_id", "${CPEWF_TASK_ID}");
workflowTask.getInputParameters().put("env", env);
Optional<Task> task2 = deciderService.retry(taskDef, workflowTask, task, workflow);
assertEquals("t1", task.getInputData().get("task_id"));
assertEquals("t1", ((Map<String, Object>) task.getInputData().get("env")).get("env_task_id"));
assertNotSame(task.getTaskId(), task2.get().getTaskId());
assertEquals(task2.get().getTaskId(), task2.get().getInputData().get("task_id"));
assertEquals(task2.get().getTaskId(), ((Map<String, Object>) task2.get().getInputData().get("env")).get("env_task_id"));
Task task3 = new Task();
task3.getInputData().putAll(taskInput);
task3.setStatus(Status.FAILED_WITH_TERMINAL_ERROR);
task3.setTaskId("t1");
when(metadataDAO.getWorkflowDef(anyString(), anyInt())).thenReturn(Optional.of(new WorkflowDef()));
exception.expect(TerminateWorkflowException.class);
deciderService.retry(taskDef, workflowTask, task3, workflow);
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TestDeciderService method testWorkflowTaskRetry.
@Test
public void testWorkflowTaskRetry() {
Workflow workflow = createDefaultWorkflow();
workflow.getWorkflowDefinition().setSchemaVersion(2);
Map<String, Object> inputParams = new HashMap<>();
inputParams.put("workflowInputParam", "${workflow.input.requestId}");
inputParams.put("taskOutputParam", "${task2.output.location}");
inputParams.put("constParam", "Some String value");
inputParams.put("nullValue", null);
inputParams.put("task2Status", "${task2.status}");
inputParams.put("null", null);
inputParams.put("task_id", "${CPEWF_TASK_ID}");
Map<String, Object> env = new HashMap<>();
env.put("env_task_id", "${CPEWF_TASK_ID}");
inputParams.put("env", env);
Map<String, Object> taskInput = parametersUtils.getTaskInput(inputParams, workflow, null, "t1");
// Create a first failed task
Task task = new Task();
task.getInputData().putAll(taskInput);
task.setStatus(Status.FAILED);
task.setTaskId("t1");
TaskDef taskDef = new TaskDef();
assertEquals(3, taskDef.getRetryCount());
WorkflowTask workflowTask = new WorkflowTask();
workflowTask.getInputParameters().put("task_id", "${CPEWF_TASK_ID}");
workflowTask.getInputParameters().put("env", env);
workflowTask.setRetryCount(1);
// Retry the failed task and assert that a new one has been created
Optional<Task> task2 = deciderService.retry(taskDef, workflowTask, task, workflow);
assertEquals("t1", task.getInputData().get("task_id"));
assertEquals("t1", ((Map<String, Object>) task.getInputData().get("env")).get("env_task_id"));
assertNotSame(task.getTaskId(), task2.get().getTaskId());
assertEquals(task2.get().getTaskId(), task2.get().getInputData().get("task_id"));
assertEquals(task2.get().getTaskId(), ((Map<String, Object>) task2.get().getInputData().get("env")).get("env_task_id"));
// Set the retried task to FAILED, retry it again and assert that the workflow failed
task2.get().setStatus(Status.FAILED);
exception.expect(TerminateWorkflowException.class);
final Optional<Task> task3 = deciderService.retry(taskDef, workflowTask, task2.get(), workflow);
assertFalse(task3.isPresent());
assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TestDeciderService method createLinearWorkflow.
private WorkflowDef createLinearWorkflow() {
Map<String, Object> inputParams = new HashMap<>();
inputParams.put("p1", "workflow.input.param1");
inputParams.put("p2", "workflow.input.param2");
WorkflowTask workflowTask1 = new WorkflowTask();
workflowTask1.setName("junit_task_l1");
workflowTask1.setInputParameters(inputParams);
workflowTask1.setTaskReferenceName("s1");
workflowTask1.setTaskDefinition(new TaskDef("junit_task_l1"));
WorkflowTask workflowTask2 = new WorkflowTask();
workflowTask2.setName("junit_task_l2");
workflowTask2.setInputParameters(inputParams);
workflowTask2.setTaskReferenceName("s2");
workflowTask2.setTaskDefinition(new TaskDef("junit_task_l2"));
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setSchemaVersion(2);
workflowDef.setInputParameters(Arrays.asList("param1", "param2"));
workflowDef.setName("Linear Workflow");
workflowDef.getTasks().addAll(Arrays.asList(workflowTask1, workflowTask2));
return workflowDef;
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TestDeciderService method testExponentialBackoff.
@Test
public void testExponentialBackoff() {
Workflow workflow = createDefaultWorkflow();
Task task = new Task();
task.setStatus(Status.FAILED);
task.setTaskId("t1");
TaskDef taskDef = new TaskDef();
taskDef.setRetryDelaySeconds(60);
taskDef.setRetryLogic(TaskDef.RetryLogic.EXPONENTIAL_BACKOFF);
WorkflowTask workflowTask = new WorkflowTask();
Optional<Task> task2 = deciderService.retry(taskDef, workflowTask, task, workflow);
assertEquals(60, task2.get().getCallbackAfterSeconds());
Optional<Task> task3 = deciderService.retry(taskDef, workflowTask, task2.get(), workflow);
assertEquals(120, task3.get().getCallbackAfterSeconds());
Optional<Task> task4 = deciderService.retry(taskDef, workflowTask, task3.get(), workflow);
assertEquals(240, task4.get().getCallbackAfterSeconds());
taskDef.setRetryCount(Integer.MAX_VALUE);
task4.get().setRetryCount(Integer.MAX_VALUE - 100);
Optional<Task> task5 = deciderService.retry(taskDef, workflowTask, task4.get(), workflow);
assertEquals(Integer.MAX_VALUE, task5.get().getCallbackAfterSeconds());
}
use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.
the class TestDeciderService method testConcurrentTaskInputCalc.
@SuppressWarnings("unchecked")
@Test
public void testConcurrentTaskInputCalc() throws InterruptedException {
TaskDef def = new TaskDef();
Map<String, Object> inputMap = new HashMap<>();
inputMap.put("path", "${workflow.input.inputLocation}");
inputMap.put("type", "${workflow.input.sourceType}");
inputMap.put("channelMapping", "${workflow.input.channelMapping}");
List<Map<String, Object>> input = new LinkedList<>();
input.add(inputMap);
Map<String, Object> body = new HashMap<>();
body.put("input", input);
def.getInputTemplate().putAll(body);
ExecutorService es = Executors.newFixedThreadPool(10);
final int[] result = new int[10];
CountDownLatch latch = new CountDownLatch(10);
for (int i = 0; i < 10; i++) {
final int x = i;
es.submit(() -> {
try {
Map<String, Object> workflowInput = new HashMap<>();
workflowInput.put("outputLocation", "baggins://outputlocation/" + x);
workflowInput.put("inputLocation", "baggins://inputlocation/" + x);
workflowInput.put("sourceType", "MuxedSource");
workflowInput.put("channelMapping", x);
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("testConcurrentTaskInputCalc");
workflowDef.setVersion(1);
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(workflowDef);
workflow.setInput(workflowInput);
Map<String, Object> taskInput = parametersUtils.getTaskInputV2(new HashMap<>(), workflow, null, def);
Object reqInputObj = taskInput.get("input");
assertNotNull(reqInputObj);
assertTrue(reqInputObj instanceof List);
List<Map<String, Object>> reqInput = (List<Map<String, Object>>) reqInputObj;
Object cmObj = reqInput.get(0).get("channelMapping");
assertNotNull(cmObj);
if (!(cmObj instanceof Number)) {
result[x] = -1;
} else {
Number channelMapping = (Number) cmObj;
result[x] = channelMapping.intValue();
}
latch.countDown();
} catch (Exception e) {
e.printStackTrace();
}
});
}
latch.await(1, TimeUnit.MINUTES);
if (latch.getCount() > 0) {
fail("Executions did not complete in a minute. Something wrong with the build server?");
}
es.shutdownNow();
for (int i = 0; i < result.length; i++) {
assertEquals(i, result[i]);
}
}
Aggregations