Search in sources :

Example 61 with TaskDef

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

the class AbstractWorkflowServiceTest method testExecutionTimes.

@Test
public void testExecutionTimes() {
    String taskName = "junit_task_1";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setTimeoutSeconds(10);
    metadataService.updateTaskDef(taskDef);
    metadataService.registerTaskDef(Collections.singletonList(taskDef));
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test_execution_times_wf");
    workflowDef.setSchemaVersion(2);
    WorkflowTask workflowTask1 = new WorkflowTask();
    workflowTask1.setName("junit_task_1");
    workflowTask1.setTaskReferenceName("task1");
    WorkflowTask workflowTask2 = new WorkflowTask();
    workflowTask2.setName("junit_task_1");
    workflowTask2.setTaskReferenceName("task2");
    WorkflowTask workflowTask3 = new WorkflowTask();
    workflowTask3.setName("junit_task_1");
    workflowTask3.setTaskReferenceName("task3");
    WorkflowTask forkTask = new WorkflowTask();
    forkTask.setType(TaskType.FORK_JOIN.name());
    forkTask.setName("forktask1");
    forkTask.setTaskReferenceName("forktask1");
    forkTask.getForkTasks().add(Collections.singletonList(workflowTask2));
    forkTask.getForkTasks().add(Collections.singletonList(workflowTask3));
    WorkflowTask joinTask = new WorkflowTask();
    joinTask.setType(TaskType.JOIN.name());
    joinTask.setTaskReferenceName("jointask");
    joinTask.setJoinOn(Arrays.asList("task2", "task3"));
    Map<String, Object> decisionInputParameters = new HashMap<>();
    decisionInputParameters.put("case", "a");
    WorkflowTask decisionTask = new WorkflowTask();
    decisionTask.setType(TaskType.DECISION.name());
    decisionTask.setName("decision1");
    decisionTask.setTaskReferenceName("decision1");
    decisionTask.setInputParameters(decisionInputParameters);
    decisionTask.setDefaultCase(Collections.singletonList(workflowTask1));
    decisionTask.setCaseValueParam("case");
    Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
    decisionCases.put("a", Arrays.asList(forkTask, joinTask));
    decisionTask.setDecisionCases(decisionCases);
    workflowDef.getTasks().add(decisionTask);
    assertNotNull(workflowDef);
    metadataService.registerWorkflowDef(workflowDef);
    Map workflowInput = Collections.emptyMap();
    // noinspection unchecked
    String workflowId = startOrLoadWorkflowExecution(workflowDef.getName(), workflowDef.getVersion(), "test", workflowInput, null, null);
    Workflow workflow = workflowExecutor.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(5, workflow.getTasks().size());
    Task task = workflowExecutionService.poll("junit_task_1", "test");
    assertNotNull(task);
    task.setStatus(Status.COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("junit_task_1", "test");
    assertNotNull(task);
    task.setStatus(Status.COMPLETED);
    workflowExecutionService.updateTask(task);
    workflowExecutor.decide(workflowId);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    workflow.getTasks().forEach(workflowTask -> {
        assertTrue(workflowTask.getScheduledTime() <= workflowTask.getStartTime());
        assertTrue("" + (workflowTask.getStartTime() - workflowTask.getEndTime()), workflowTask.getStartTime() <= workflowTask.getEndTime());
    });
    assertEquals("decision1", workflow.getTasks().get(0).getReferenceTaskName());
    assertEquals("forktask1", workflow.getTasks().get(1).getReferenceTaskName());
    assertEquals("task2", workflow.getTasks().get(2).getReferenceTaskName());
    assertEquals("task3", workflow.getTasks().get(3).getReferenceTaskName());
    assertEquals("jointask", workflow.getTasks().get(4).getReferenceTaskName());
    metadataService.unregisterWorkflowDef(workflowDef.getName(), 1);
}
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) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) LinkedList(java.util.LinkedList) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 62 with TaskDef

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

the class AbstractWorkflowServiceTest method testEventWorkflow.

@Test
public void testEventWorkflow() {
    TaskDef taskDef = new TaskDef();
    taskDef.setName("eventX");
    taskDef.setTimeoutSeconds(1);
    metadataService.registerTaskDef(Collections.singletonList(taskDef));
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test_event");
    workflowDef.setSchemaVersion(2);
    WorkflowTask eventWorkflowTask = new WorkflowTask();
    eventWorkflowTask.setWorkflowTaskType(TaskType.EVENT);
    eventWorkflowTask.setName("eventX");
    eventWorkflowTask.setTaskReferenceName("wait0");
    eventWorkflowTask.setSink("conductor");
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("junit_task_1");
    workflowTask.setTaskReferenceName("t1");
    workflowDef.getTasks().add(eventWorkflowTask);
    workflowDef.getTasks().add(workflowTask);
    metadataService.registerWorkflowDef(workflowDef);
    String workflowId = startOrLoadWorkflowExecution(workflowDef.getName(), workflowDef.getVersion(), "", new HashMap<>(), null, null);
    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
    Workflow workflow = workflowExecutor.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    Task eventTask = workflow.getTasks().get(0);
    assertEquals(TaskType.EVENT.name(), eventTask.getTaskType());
    assertEquals(COMPLETED, eventTask.getStatus());
    assertFalse(eventTask.getOutputData().isEmpty());
    assertNotNull(eventTask.getOutputData().get("event_produced"));
    Task task = workflowExecutionService.poll("junit_task_1", "test");
    assertNotNull(task);
    task.setStatus(Status.COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals("tasks:" + 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) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) 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 63 with TaskDef

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

the class RedisMetadataDAOTest method testTaskDefOperations.

@Test
public void testTaskDefOperations() {
    TaskDef def = new TaskDef("taskA");
    def.setDescription("description");
    def.setCreatedBy("unit_test");
    def.setCreateTime(1L);
    def.setInputKeys(Arrays.asList("a", "b", "c"));
    def.setOutputKeys(Arrays.asList("01", "o2"));
    def.setOwnerApp("ownerApp");
    def.setRetryCount(3);
    def.setRetryDelaySeconds(100);
    def.setRetryLogic(RetryLogic.FIXED);
    def.setTimeoutPolicy(TimeoutPolicy.ALERT_ONLY);
    def.setUpdatedBy("unit_test2");
    def.setUpdateTime(2L);
    def.setRateLimitPerFrequency(50);
    def.setRateLimitFrequencyInSeconds(1);
    redisMetadataDAO.createTaskDef(def);
    TaskDef found = redisMetadataDAO.getTaskDef(def.getName());
    assertTrue(EqualsBuilder.reflectionEquals(def, found));
    def.setDescription("updated description");
    redisMetadataDAO.updateTaskDef(def);
    found = redisMetadataDAO.getTaskDef(def.getName());
    assertTrue(EqualsBuilder.reflectionEquals(def, found));
    assertEquals("updated description", found.getDescription());
    for (int i = 0; i < 9; i++) {
        TaskDef tdf = new TaskDef("taskA" + i);
        redisMetadataDAO.createTaskDef(tdf);
    }
    List<TaskDef> all = redisMetadataDAO.getAllTaskDefs();
    assertNotNull(all);
    assertEquals(10, all.size());
    Set<String> allnames = all.stream().map(TaskDef::getName).collect(Collectors.toSet());
    assertEquals(10, allnames.size());
    List<String> sorted = allnames.stream().sorted().collect(Collectors.toList());
    assertEquals(def.getName(), sorted.get(0));
    for (int i = 0; i < 9; i++) {
        assertEquals(def.getName() + i, sorted.get(i + 1));
    }
    for (int i = 0; i < 9; i++) {
        redisMetadataDAO.removeTaskDef(def.getName() + i);
    }
    all = redisMetadataDAO.getAllTaskDefs();
    assertNotNull(all);
    assertEquals(1, all.size());
    assertEquals(def.getName(), all.get(0).getName());
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Test(org.junit.Test)

Example 64 with TaskDef

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

the class RedisRateLimitDaoTest method testExceedsRateLimitOutOfLimit.

@Test
public void testExceedsRateLimitOutOfLimit() {
    TaskDef taskDef = new TaskDef("TestTaskDefinition");
    taskDef.setRateLimitFrequencyInSeconds(60);
    taskDef.setRateLimitPerFrequency(1);
    Task task = new Task();
    task.setTaskId(UUID.randomUUID().toString());
    task.setTaskDefName(taskDef.getName());
    assertFalse(rateLimitingDao.exceedsRateLimitPerFrequency(task, taskDef));
    assertTrue(rateLimitingDao.exceedsRateLimitPerFrequency(task, taskDef));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Test(org.junit.Test)

Example 65 with TaskDef

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

the class AbstractWorkflowServiceTest method testCustomRetryPolicyWithWorkflowTask.

@Test
public void testCustomRetryPolicyWithWorkflowTask() {
    String taskName = "junit_task_2";
    TaskDef taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(2);
    taskDef.setRetryLogic(RetryLogic.CUSTOM);
    taskDef.setRetryDelaySeconds(2);
    metadataService.updateTaskDef(taskDef);
    taskName = "junit_task_3";
    taskDef = notFoundSafeGetTaskDef(taskName);
    taskDef.setRetryCount(2);
    taskDef.setRetryLogic(RetryLogic.CUSTOM);
    taskDef.setRetryDelaySeconds(2);
    metadataService.updateTaskDef(taskDef);
    metadataService.getWorkflowDef(TEST_WORKFLOW, 1);
    String correlationId = "unit_test_1";
    Map<String, Object> input = new HashMap<String, Object>();
    String inputParam1 = "p1 value";
    input.put("param1", inputParam1);
    input.put("param2", "p2 value");
    String wfid = startOrLoadWorkflowExecution(TEST_WORKFLOW, 1, correlationId, input, null, null);
    System.out.println("testRetries.wfid=" + wfid);
    assertNotNull(wfid);
    List<String> ids = workflowExecutionService.getRunningWorkflows(TEST_WORKFLOW, 1);
    assertNotNull(ids);
    // if there are concurrent tests running, this would be more than 1
    assertTrue("found no ids: " + ids, ids.size() > 0);
    boolean foundId = false;
    for (String id : ids) {
        if (id.equals(wfid)) {
            foundId = true;
        }
    }
    assertTrue(foundId);
    Workflow es = workflowExecutionService.getExecutionStatus(wfid, true);
    assertNotNull(es);
    assertEquals(RUNNING, es.getStatus());
    Task task = workflowExecutionService.poll("junit_task_1", "task1.junit.worker");
    assertNotNull(task);
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    verifyRetriedTask(wfid, "junit_task_2", "task2.junit.worker", true, -1, false, true, 3);
    // Should have not delay since retry delay < 0, but since wfTask has fixed retry delay,
    // it will be retried after 3 seconds
    Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
    verifyRetriedTask(wfid, "junit_task_2", "task2.junit.worker", false, -1, false, true, 3);
    verifyRetriedTask(wfid, "junit_task_3", "task3.junit.worker", true, 0, true, true, 3);
    // Should use retry from task definition since retry delay = 0, but since wfTask has fixed retry delay,
    // it will be retried after 3 seconds
    Uninterruptibles.sleepUninterruptibly(3, TimeUnit.SECONDS);
    verifyRetriedTask(wfid, "junit_task_3", "task3.junit.worker", false, 0, true, true, 3);
    es = workflowExecutionService.getExecutionStatus(wfid, true);
    assertEquals(5, es.getTasks().size());
    assertEquals(COMPLETED, es.getTasks().get(0).getStatus());
    assertEquals(FAILED, es.getTasks().get(1).getStatus());
    assertEquals(COMPLETED, es.getTasks().get(2).getStatus());
    assertEquals(FAILED, es.getTasks().get(3).getStatus());
    assertEquals(COMPLETED, es.getTasks().get(4).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) Test(org.junit.Test)

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