Search in sources :

Example 21 with TaskDef

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

the class MetadataServiceImpl method registerTaskDef.

/**
 * @param taskDefinitions Task Definitions to register
 */
@Service
public void registerTaskDef(List<TaskDef> taskDefinitions) {
    for (TaskDef taskDefinition : taskDefinitions) {
        taskDefinition.setCreatedBy(WorkflowContext.get().getClientApp());
        taskDefinition.setCreateTime(System.currentTimeMillis());
        taskDefinition.setUpdatedBy(null);
        taskDefinition.setUpdateTime(null);
        metadataDAO.createTaskDef(taskDefinition);
    }
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Service(com.netflix.conductor.annotations.Service)

Example 22 with TaskDef

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

the class TestDeciderService method testCheckTaskPollTimeout.

@Test
public void testCheckTaskPollTimeout() {
    Counter counter = registry.counter("task_timeout", "class", "WorkflowMonitor", "taskType", "test");
    long counterCount = counter.count();
    TaskDef taskType = new TaskDef();
    taskType.setName("test");
    taskType.setTimeoutPolicy(TimeoutPolicy.RETRY);
    taskType.setPollTimeoutSeconds(1);
    Task task = new Task();
    task.setTaskType(taskType.getName());
    task.setScheduledTime(System.currentTimeMillis() - 2_000);
    task.setStatus(Status.SCHEDULED);
    deciderService.checkTaskPollTimeout(taskType, task);
    assertEquals(++counterCount, counter.count());
    assertEquals(Status.TIMED_OUT, task.getStatus());
    assertNotNull(task.getReasonForIncompletion());
    task.setScheduledTime(System.currentTimeMillis());
    task.setReasonForIncompletion(null);
    task.setStatus(Status.SCHEDULED);
    deciderService.checkTaskPollTimeout(taskType, task);
    assertEquals(counterCount, counter.count());
    assertEquals(Status.SCHEDULED, task.getStatus());
    assertNull(task.getReasonForIncompletion());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Counter(com.netflix.spectator.api.Counter) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Test(org.junit.Test)

Example 23 with TaskDef

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

the class TestDeciderService method createNestedWorkflow.

private WorkflowDef createNestedWorkflow() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("Nested Workflow");
    workflowDef.setDescription(workflowDef.getName());
    workflowDef.setVersion(1);
    workflowDef.setInputParameters(Arrays.asList("param1", "param2"));
    Map<String, Object> inputParams = new HashMap<>();
    inputParams.put("p1", "workflow.input.param1");
    inputParams.put("p2", "workflow.input.param2");
    List<WorkflowTask> tasks = new ArrayList<>(10);
    for (int i = 0; i < 10; i++) {
        WorkflowTask workflowTask = new WorkflowTask();
        workflowTask.setName("junit_task_" + i);
        workflowTask.setInputParameters(inputParams);
        workflowTask.setTaskReferenceName("t" + i);
        workflowTask.setTaskDefinition(new TaskDef("junit_task_" + i));
        tasks.add(workflowTask);
    }
    WorkflowTask decisionTask = new WorkflowTask();
    decisionTask.setType(TaskType.DECISION.name());
    decisionTask.setName("Decision");
    decisionTask.setTaskReferenceName("d1");
    decisionTask.setDefaultCase(Collections.singletonList(tasks.get(8)));
    decisionTask.setCaseValueParam("case");
    Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
    decisionCases.put("a", Arrays.asList(tasks.get(6), tasks.get(9)));
    decisionCases.put("b", Collections.singletonList(tasks.get(7)));
    decisionTask.setDecisionCases(decisionCases);
    WorkflowDef subWorkflowDef = createLinearWorkflow();
    WorkflowTask subWorkflow = new WorkflowTask();
    subWorkflow.setType(TaskType.SUB_WORKFLOW.name());
    subWorkflow.setName("sw1");
    SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
    subWorkflowParams.setName(subWorkflowDef.getName());
    subWorkflow.setSubWorkflowParam(subWorkflowParams);
    subWorkflow.setTaskReferenceName("sw1");
    WorkflowTask forkTask2 = new WorkflowTask();
    forkTask2.setType(TaskType.FORK_JOIN.name());
    forkTask2.setName("second fork");
    forkTask2.setTaskReferenceName("fork2");
    forkTask2.getForkTasks().add(Arrays.asList(tasks.get(2), tasks.get(4)));
    forkTask2.getForkTasks().add(Arrays.asList(tasks.get(3), decisionTask));
    WorkflowTask joinTask2 = new WorkflowTask();
    joinTask2.setName("join2");
    joinTask2.setType(TaskType.JOIN.name());
    joinTask2.setTaskReferenceName("join2");
    joinTask2.setJoinOn(Arrays.asList("t4", "d1"));
    WorkflowTask forkTask1 = new WorkflowTask();
    forkTask1.setType(TaskType.FORK_JOIN.name());
    forkTask1.setName("fork1");
    forkTask1.setTaskReferenceName("fork1");
    forkTask1.getForkTasks().add(Collections.singletonList(tasks.get(1)));
    forkTask1.getForkTasks().add(Arrays.asList(forkTask2, joinTask2));
    forkTask1.getForkTasks().add(Collections.singletonList(subWorkflow));
    WorkflowTask joinTask1 = new WorkflowTask();
    joinTask1.setName("join1");
    joinTask1.setType(TaskType.JOIN.name());
    joinTask1.setTaskReferenceName("join1");
    joinTask1.setJoinOn(Arrays.asList("t1", "fork2"));
    workflowDef.getTasks().add(forkTask1);
    workflowDef.getTasks().add(joinTask1);
    workflowDef.getTasks().add(tasks.get(5));
    return workflowDef;
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

Example 24 with TaskDef

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

the class TestDeciderService method testIsResponseTimedOut.

@Test
public void testIsResponseTimedOut() {
    TaskDef taskDef = new TaskDef();
    taskDef.setName("test_rt");
    taskDef.setResponseTimeoutSeconds(10);
    Task task = new Task();
    task.setTaskDefName("test_rt");
    task.setStatus(Status.IN_PROGRESS);
    task.setTaskId("aa");
    task.setTaskType(TaskType.TASK_TYPE_SIMPLE);
    task.setUpdateTime(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(11));
    assertTrue(deciderService.isResponseTimedOut(taskDef, task));
    // verify that sub workflow tasks are not response timed out
    task.setTaskType(TaskType.TASK_TYPE_SUB_WORKFLOW);
    assertFalse(deciderService.isResponseTimedOut(taskDef, task));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Test(org.junit.Test)

Example 25 with TaskDef

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

the class TestDeciderService method createConditionalWF.

private WorkflowDef createConditionalWF() {
    WorkflowTask workflowTask1 = new WorkflowTask();
    workflowTask1.setName("junit_task_1");
    Map<String, Object> inputParams1 = new HashMap<>();
    inputParams1.put("p1", "workflow.input.param1");
    inputParams1.put("p2", "workflow.input.param2");
    workflowTask1.setInputParameters(inputParams1);
    workflowTask1.setTaskReferenceName("t1");
    workflowTask1.setTaskDefinition(new TaskDef("junit_task_1"));
    WorkflowTask workflowTask2 = new WorkflowTask();
    workflowTask2.setName("junit_task_2");
    Map<String, Object> inputParams2 = new HashMap<>();
    inputParams2.put("tp1", "workflow.input.param1");
    workflowTask2.setInputParameters(inputParams2);
    workflowTask2.setTaskReferenceName("t2");
    workflowTask2.setTaskDefinition(new TaskDef("junit_task_2"));
    WorkflowTask workflowTask3 = new WorkflowTask();
    workflowTask3.setName("junit_task_3");
    Map<String, Object> inputParams3 = new HashMap<>();
    inputParams2.put("tp3", "workflow.input.param2");
    workflowTask3.setInputParameters(inputParams3);
    workflowTask3.setTaskReferenceName("t3");
    workflowTask3.setTaskDefinition(new TaskDef("junit_task_3"));
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("Conditional Workflow");
    workflowDef.setDescription("Conditional Workflow");
    workflowDef.setInputParameters(Arrays.asList("param1", "param2"));
    WorkflowTask decisionTask2 = new WorkflowTask();
    decisionTask2.setType(TaskType.DECISION.name());
    decisionTask2.setCaseValueParam("case");
    decisionTask2.setName("conditional2");
    decisionTask2.setTaskReferenceName("conditional2");
    Map<String, List<WorkflowTask>> dc = new HashMap<>();
    dc.put("one", Arrays.asList(workflowTask1, workflowTask3));
    dc.put("two", Collections.singletonList(workflowTask2));
    decisionTask2.setDecisionCases(dc);
    decisionTask2.getInputParameters().put("case", "workflow.input.param2");
    WorkflowTask decisionTask = new WorkflowTask();
    decisionTask.setType(TaskType.DECISION.name());
    decisionTask.setCaseValueParam("case");
    decisionTask.setName("conditional");
    decisionTask.setTaskReferenceName("conditional");
    Map<String, List<WorkflowTask>> decisionCases = new HashMap<>();
    decisionCases.put("nested", Collections.singletonList(decisionTask2));
    decisionCases.put("three", Collections.singletonList(workflowTask3));
    decisionTask.setDecisionCases(decisionCases);
    decisionTask.getInputParameters().put("case", "workflow.input.param1");
    decisionTask.getDefaultCase().add(workflowTask2);
    workflowDef.getTasks().add(decisionTask);
    WorkflowTask notifyTask = new WorkflowTask();
    notifyTask.setName("junit_task_4");
    notifyTask.setTaskReferenceName("junit_task_4");
    notifyTask.setTaskDefinition(new TaskDef("junit_task_4"));
    WorkflowTask finalDecisionTask = new WorkflowTask();
    finalDecisionTask.setName("finalcondition");
    finalDecisionTask.setTaskReferenceName("tf");
    finalDecisionTask.setType(TaskType.DECISION.name());
    finalDecisionTask.setCaseValueParam("finalCase");
    Map<String, Object> fi = new HashMap<>();
    fi.put("finalCase", "workflow.input.finalCase");
    finalDecisionTask.setInputParameters(fi);
    finalDecisionTask.getDecisionCases().put("notify", Collections.singletonList(notifyTask));
    workflowDef.getTasks().add(finalDecisionTask);
    return workflowDef;
}
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) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

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