Search in sources :

Example 71 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testRateLimiting.

@Test
public void testRateLimiting() {
    // Create a dynamic workflow definition with one simple task
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test_concurrency_limits");
    workflowDef.setVersion(1);
    TaskDef taskDef = new TaskDef();
    taskDef.setName("test_task_with_ratelimits");
    taskDef.setRateLimitFrequencyInSeconds(600);
    taskDef.setRateLimitPerFrequency(1);
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setTaskReferenceName("test_task_with_ratelimits");
    workflowTask.setName("test_task_with_ratelimits");
    workflowTask.setType(UserTask.NAME);
    workflowTask.setTaskDefinition(taskDef);
    Map<String, Object> userIP = new HashMap<>();
    workflowDef.setTasks(Arrays.asList(workflowTask));
    String workflowInstanceId1 = workflowExecutor.startWorkflow(workflowDef, new HashMap<>(), "", "", 0, "", "", "", new HashMap<>());
    assertNotNull(workflowInstanceId1);
    Workflow workflow1 = workflowExecutionService.getExecutionStatus(workflowInstanceId1, true);
    assertNotNull(workflow1);
    assertEquals(RUNNING, workflow1.getStatus());
    // The very first task is the one that should be scheduled.
    assertEquals(1, workflow1.getTasks().size());
    UserTask userTask = new UserTask();
    Task task = workflow1.getTasks().get(0);
    workflowExecutor.executeSystemTask(userTask, task.getTaskId(), 30);
    workflow1 = workflowExecutionService.getExecutionStatus(workflowInstanceId1, true);
    String workflowInstanceId2 = workflowExecutor.startWorkflow(workflowDef, new HashMap<>(), "", "", 0, "", "", "", new HashMap<>());
    assertNotNull(workflowInstanceId2);
    Workflow workflow2 = workflowExecutionService.getExecutionStatus(workflowInstanceId2, true);
    assertNotNull(workflow2);
    assertEquals(RUNNING, workflow2.getStatus());
    // The very first task is the one that should be scheduled.
    assertEquals(1, workflow2.getTasks().size());
    // Try to execute second task
    Task task2 = workflow2.getTasks().get(0);
    workflowExecutor.executeSystemTask(userTask, task2.getTaskId(), 30);
    workflow2 = workflowExecutionService.getExecutionStatus(workflowInstanceId2, true);
    task2 = workflow2.getTasks().get(0);
    assertEquals(SCHEDULED, task2.getStatus());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) UserTask(com.netflix.conductor.tests.utils.UserTask) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 72 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testDoWhileTwoIteration.

@Test
public void testDoWhileTwoIteration() throws Exception {
    try {
        createDoWhileWorkflowWithIteration(2, false, true);
    } catch (Exception e) {
    }
    TaskDef taskDef = new TaskDef();
    taskDef.setName("http1");
    taskDef.setTimeoutSeconds(5);
    taskDef.setRetryCount(1);
    taskDef.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskDef.setRetryDelaySeconds(10);
    metadataService.registerTaskDef(Arrays.asList(taskDef));
    TaskDef taskDef2 = new TaskDef();
    taskDef2.setName("http0");
    taskDef2.setTimeoutSeconds(5);
    taskDef2.setRetryCount(1);
    taskDef2.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskDef2.setRetryDelaySeconds(10);
    metadataService.registerTaskDef(Arrays.asList(taskDef2));
    TaskDef taskDef1 = new TaskDef();
    taskDef1.setName("http2");
    taskDef1.setTimeoutSeconds(5);
    taskDef1.setRetryCount(1);
    taskDef1.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskDef1.setRetryDelaySeconds(10);
    metadataService.registerTaskDef(Arrays.asList(taskDef1));
    TaskDef taskDef3 = new TaskDef();
    taskDef1.setName("http3");
    taskDef1.setTimeoutSeconds(5);
    taskDef1.setRetryCount(1);
    taskDef1.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskDef1.setRetryDelaySeconds(10);
    metadataService.registerTaskDef(Arrays.asList(taskDef3));
    Map<String, Object> input = new HashMap<>();
    String workflowId = startOrLoadWorkflowExecution(DO_WHILE_WF + "_2", 1, "looptest", input, null, null);
    System.out.println("testDoWhile.wfid=" + workflowId);
    printTaskStatuses(workflowId, "initiated");
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks(), RUNNING, workflow.getStatus());
    Task task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("FORK_JOIN", "test");
    // fork task is completed
    assertNull(task);
    task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("JOIN", "test");
    // Both HTTP task completed.
    assertNull(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks(), RUNNING, workflow.getStatus());
    task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("FORK_JOIN", "test");
    // fork task is completed.
    assertNull(task);
    task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("JOIN", "test");
    assertNull(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks(), RUNNING, workflow.getStatus());
    task = workflowExecutionService.poll("HTTP", "test");
    assertNotNull(task);
    assertTrue(task.getReferenceTaskName().endsWith(TaskUtils.getLoopOverTaskRefNameSuffix(task.getIteration())));
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("Found " + workflow.getTasks(), WorkflowStatus.COMPLETED, workflow.getStatus());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) ExpectedException(org.junit.rules.ExpectedException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Test(org.junit.Test)

Example 73 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class WorkflowStatusPublisherIntegrationTest method setUp.

@Before
public void setUp() {
    TaskDef task = new TaskDef();
    task.setName("junit_task_1");
    task.setTimeoutSeconds(120);
    task.setRetryCount(1);
    metadataService.registerTaskDef(Collections.singletonList(task));
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Before(org.junit.Before)

Example 74 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testSubWorkflowRetry.

@Test
public void testSubWorkflowRetry() {
    String taskName = "junit_task_1";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    int retryCount = notFoundSafeGetTaskDef(taskName).getRetryCount();
    taskDef.setRetryCount(0);
    metadataService.updateTaskDef(taskDef);
    // create a workflow with sub-workflow
    createSubWorkflow();
    WorkflowDef found = metadataService.getWorkflowDef(WF_WITH_SUB_WF, 1);
    WorkflowTask workflowTask = found.getTasks().stream().filter(t -> t.getType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
    // Set subworkflow task retry count to 1.
    TaskDef subWorkflowTaskDef = new TaskDef();
    subWorkflowTaskDef.setRetryCount(1);
    subWorkflowTaskDef.setName("test_subworkflow_task");
    subWorkflowTaskDef.setOwnerEmail("test@qbc.com");
    workflowTask.setTaskDefinition(subWorkflowTaskDef);
    metadataService.updateWorkflowDef(found);
    // start the workflow
    Map<String, Object> workflowInputParams = new HashMap<>();
    workflowInputParams.put("param1", "param 1");
    workflowInputParams.put("param3", "param 2");
    workflowInputParams.put("wfName", LINEAR_WORKFLOW_T1_T2);
    String workflowId = startOrLoadWorkflowExecution(WF_WITH_SUB_WF, 1, "test", workflowInputParams, null, null);
    assertNotNull(workflowId);
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    // poll and complete first task
    Task task = workflowExecutionService.poll("junit_task_5", "test");
    assertNotNull(task);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    // Simulating SystemTaskWorkerCoordinator to execute async system tasks
    String subWorkflowTaskId = workflow.getTaskByRefName("a2").getTaskId();
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertNotNull(workflow.getTasks());
    assertEquals(2, workflow.getTasks().size());
    task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
    assertNotNull(task);
    assertNotNull(task.getOutputData());
    assertNotNull("Output: " + task.getOutputData().toString() + ", status: " + task.getStatus(), task.getSubWorkflowId());
    String subWorkflowId = task.getSubWorkflowId();
    workflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(workflow);
    assertNotNull(workflow.getTasks());
    assertEquals(workflowId, workflow.getParentWorkflowId());
    assertEquals(RUNNING, workflow.getStatus());
    // poll and fail the first task in sub-workflow
    task = workflowExecutionService.poll("junit_task_1", "test");
    task.setStatus(FAILED);
    workflowExecutionService.updateTask(task);
    Workflow subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(WorkflowStatus.FAILED, subWorkflow.getStatus());
    subWorkflowTaskId = subWorkflow.getParentWorkflowTaskId();
    workflowExecutor.executeSystemTask(subworkflow, subWorkflowTaskId, 1);
    // Ensure failed Subworkflow task is rescheduled.
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).filter(t -> t.getStatus().equals(SCHEDULED)).findAny().orElse(null);
    assertNotNull(task);
    subWorkflowTaskId = task.getTaskId();
    workflowExecutor.executeSystemTask(subworkflow, task.getTaskId(), 1);
    // Get the latest workflow and task, and then acquire latest subWorkflowId
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).filter(t -> t.getStatus().equals(IN_PROGRESS)).findAny().orElse(null);
    assertNotNull(task);
    assertNotNull("Retried task in scheduled state shouldn't have a SubworkflowId yet", task.getSubWorkflowId());
    subWorkflowId = task.getSubWorkflowId();
    // poll and fail the first task in sub-workflow
    task = workflowExecutionService.poll("junit_task_1", "test");
    task.setStatus(FAILED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.FAILED, workflow.getStatus());
    // Retry the failed sub workflow
    workflowExecutor.retry(subWorkflowId, false);
    task = workflowExecutionService.poll("junit_task_1", "test");
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(RUNNING, subWorkflow.getStatus());
    task = workflowExecutionService.poll("junit_task_2", "test");
    assertEquals(subWorkflowId, task.getWorkflowInstanceId());
    String uuid = UUID.randomUUID().toString();
    task.getOutputData().put("uuid", uuid);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(WorkflowStatus.COMPLETED, subWorkflow.getStatus());
    assertNotNull(subWorkflow.getOutput());
    assertTrue(subWorkflow.getOutput().containsKey("o1"));
    assertTrue(subWorkflow.getOutput().containsKey("o2"));
    assertEquals("sub workflow input param1", subWorkflow.getOutput().get("o1"));
    assertEquals(uuid, subWorkflow.getOutput().get("o2"));
    // Simulating SystemTaskWorkerCoordinator
    workflowExecutor.executeSystemTask(subworkflow, subWorkflow.getParentWorkflowTaskId(), 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    task = workflowExecutionService.poll("junit_task_6", "test");
    assertNotNull(task);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    // reset retry count
    taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(retryCount);
    metadataService.updateTaskDef(taskDef);
    workflowTask = found.getTasks().stream().filter(t -> t.getType().equals(SUB_WORKFLOW.name())).findAny().orElse(null);
    workflowTask.setTaskDefinition(null);
    metadataService.updateWorkflowDef(found);
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) MethodSorters(org.junit.runners.MethodSorters) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Arrays(java.util.Arrays) TimeoutPolicy(com.netflix.conductor.common.metadata.tasks.TaskDef.TimeoutPolicy) TEMP_FILE_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TEMP_FILE_PATH) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) Future(java.util.concurrent.Future) COMPLETED_WITH_ERRORS(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) After(org.junit.After) PollData(com.netflix.conductor.common.metadata.tasks.PollData) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) TASK_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TASK_OUTPUT_PATH) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) WorkflowRepairService(com.netflix.conductor.core.execution.WorkflowRepairService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Executors(java.util.concurrent.Executors) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) QueueDAO(com.netflix.conductor.dao.QueueDAO) INPUT_PAYLOAD_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INPUT_PAYLOAD_PATH) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) Assert.assertFalse(org.junit.Assert.assertFalse) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) COMPLETED(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED) ExecutionService(com.netflix.conductor.service.ExecutionService) FixMethodOrder(org.junit.FixMethodOrder) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) MetadataService(com.netflix.conductor.service.MetadataService) WorkflowContext(com.netflix.conductor.core.WorkflowContext) BeforeClass(org.junit.BeforeClass) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) LinkedList(java.util.LinkedList) ExpectedException(org.junit.rules.ExpectedException) RUNNING(com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) TERMINATED(com.netflix.conductor.common.run.Workflow.WorkflowStatus.TERMINATED) INITIAL_WORKFLOW_INPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INITIAL_WORKFLOW_INPUT_PATH) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) WorkflowSweeper(com.netflix.conductor.core.execution.WorkflowSweeper) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTask(com.netflix.conductor.tests.utils.UserTask) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) WORKFLOW_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.WORKFLOW_OUTPUT_PATH) TimeUnit(java.util.concurrent.TimeUnit) DECISION(com.netflix.conductor.common.metadata.workflow.TaskType.DECISION) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Ignore(org.junit.Ignore) RetryLogic(com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 75 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class AbstractWorkflowServiceTest method registerKafkaWorkflow.

private void registerKafkaWorkflow() {
    System.setProperty("STACK_KAFKA", "test_kafka_topic");
    TaskDef templatedTask = new TaskDef();
    templatedTask.setName("templated_kafka_task");
    templatedTask.setRetryCount(0);
    Map<String, Object> kafkaRequest = new HashMap<>();
    kafkaRequest.put("topic", "${STACK_KAFKA}");
    kafkaRequest.put("bootStrapServers", "localhost:9092");
    Map<String, Object> value = new HashMap<>();
    value.put("inputPaths", Arrays.asList("${workflow.input.path1}", "${workflow.input.path2}"));
    value.put("requestDetails", "${workflow.input.requestDetails}");
    value.put("outputPath", "${workflow.input.outputPath}");
    kafkaRequest.put("value", value);
    templatedTask.getInputTemplate().put("kafka_request", kafkaRequest);
    metadataService.registerTaskDef(Arrays.asList(templatedTask));
    WorkflowDef templateWf = new WorkflowDef();
    templateWf.setName("template_kafka_workflow");
    WorkflowTask wft = new WorkflowTask();
    wft.setName(templatedTask.getName());
    wft.setWorkflowTaskType(TaskType.KAFKA_PUBLISH);
    wft.setTaskReferenceName("t0");
    templateWf.getTasks().add(wft);
    templateWf.setSchemaVersion(2);
    metadataService.registerWorkflowDef(templateWf);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Aggregations

TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)172 Test (org.junit.Test)128 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)121 Task (com.netflix.conductor.common.metadata.tasks.Task)77 Workflow (com.netflix.conductor.common.run.Workflow)76 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)73 HashMap (java.util.HashMap)56 ArrayList (java.util.ArrayList)32 ConstraintViolation (javax.validation.ConstraintViolation)31 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)30 UserTask (com.netflix.conductor.tests.utils.UserTask)28 LinkedList (java.util.LinkedList)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)27 List (java.util.List)22 Map (java.util.Map)19 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)18 Before (org.junit.Before)14 ExpectedException (org.junit.rules.ExpectedException)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 Collectors (java.util.stream.Collectors)11