Search in sources :

Example 11 with TaskDef

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

the class SimpleTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setName("simple_task");
    taskToSchedule.setTaskDefinition(new TaskDef("simple_task"));
    String taskId = IDGenerator.generate();
    String retriedTaskId = IDGenerator.generate();
    WorkflowDef wd = new WorkflowDef();
    Workflow w = new Workflow();
    w.setWorkflowDefinition(wd);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withTaskInput(new HashMap<>()).withRetryCount(0).withRetryTaskId(retriedTaskId).withTaskId(taskId).build();
    List<Task> mappedTasks = simpleTaskMapper.getMappedTasks(taskMapperContext);
    assertNotNull(mappedTasks);
    assertEquals(1, mappedTasks.size());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 12 with TaskDef

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

the class EventTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    ParametersUtils parametersUtils = Mockito.mock(ParametersUtils.class);
    EventTaskMapper eventTaskMapper = new EventTaskMapper(parametersUtils);
    WorkflowTask taskToBeScheduled = new WorkflowTask();
    taskToBeScheduled.setSink("SQSSINK");
    String taskId = IDGenerator.generate();
    Map<String, Object> eventTaskInput = new HashMap<>();
    eventTaskInput.put("sink", "SQSSINK");
    when(parametersUtils.getTaskInput(anyMap(), any(Workflow.class), any(TaskDef.class), anyString())).thenReturn(eventTaskInput);
    WorkflowDef wd = new WorkflowDef();
    Workflow w = new Workflow();
    w.setWorkflowDefinition(wd);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToBeScheduled).withRetryCount(0).withTaskId(taskId).build();
    List<Task> mappedTasks = eventTaskMapper.getMappedTasks(taskMapperContext);
    assertEquals(1, mappedTasks.size());
    Task eventTask = mappedTasks.get(0);
    assertEquals(taskId, eventTask.getTaskId());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ParametersUtils(com.netflix.conductor.core.execution.ParametersUtils) Test(org.junit.Test)

Example 13 with TaskDef

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

the class HTTPTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() {
    // Given
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setName("http_task");
    taskToSchedule.setType(TaskType.HTTP.name());
    taskToSchedule.setTaskDefinition(new TaskDef("http_task"));
    String taskId = IDGenerator.generate();
    String retriedTaskId = IDGenerator.generate();
    Workflow workflow = new Workflow();
    WorkflowDef workflowDef = new WorkflowDef();
    workflow.setWorkflowDefinition(workflowDef);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withTaskInput(new HashMap<>()).withRetryCount(0).withRetryTaskId(retriedTaskId).withTaskId(taskId).build();
    // when
    List<Task> mappedTasks = httpTaskMapper.getMappedTasks(taskMapperContext);
    // Then
    assertEquals(1, mappedTasks.size());
    assertEquals(TaskType.HTTP.name(), mappedTasks.get(0).getTaskType());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 14 with TaskDef

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

the class CassandraDAOTest method testTaskDefLimitCRUD.

@Test
public void testTaskDefLimitCRUD() {
    String taskDefName = "test_task_def";
    String taskId = IDGenerator.generate();
    TaskDef taskDef = new TaskDef();
    taskDef.setConcurrentExecLimit(1);
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setTaskDefinition(taskDef);
    Task task = new Task();
    task.setTaskDefName(taskDefName);
    task.setTaskId(taskId);
    task.setWorkflowInstanceId(IDGenerator.generate());
    task.setWorkflowTask(workflowTask);
    task.setTaskType("test_task");
    task.setWorkflowType("test_workflow");
    task.setStatus(Task.Status.SCHEDULED);
    Task newTask = new Task();
    newTask.setTaskDefName(taskDefName);
    newTask.setTaskId(IDGenerator.generate());
    newTask.setWorkflowInstanceId(IDGenerator.generate());
    newTask.setWorkflowTask(workflowTask);
    newTask.setTaskType("test_task");
    newTask.setWorkflowType("test_workflow");
    newTask.setStatus(Task.Status.SCHEDULED);
    // no tasks are IN_PROGRESS
    executionDAO.updateTaskDefLimit(task, false);
    assertFalse(executionDAO.exceedsInProgressLimit(task));
    // set a task to IN_PROGRESS
    task.setStatus(Status.IN_PROGRESS);
    executionDAO.updateTaskDefLimit(task, false);
    // when same task is checked
    assertFalse(executionDAO.exceedsInProgressLimit(task));
    // check if new task can be added
    assertTrue(executionDAO.exceedsInProgressLimit(newTask));
    // set IN_PROGRESS task to COMPLETED
    task.setStatus(Status.COMPLETED);
    executionDAO.updateTaskDefLimit(task, false);
    // check new task again
    assertFalse(executionDAO.exceedsInProgressLimit(newTask));
    // set new task to IN_PROGRESS
    newTask.setStatus(Status.IN_PROGRESS);
    executionDAO.updateTaskDefLimit(newTask, false);
    // check new task again
    assertFalse(executionDAO.exceedsInProgressLimit(newTask));
    // force remove from task def limit
    executionDAO.updateTaskDefLimit(newTask, true);
    assertFalse(executionDAO.exceedsInProgressLimit(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) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 15 with TaskDef

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

the class CassandraDAOTest method testTaskDefCrud.

@Test
public void testTaskDefCrud() {
    String task1Name = "task1";
    String task2Name = "task2";
    // fetch all task defs
    List<TaskDef> taskDefList = metadataDAO.getAllTaskDefs();
    assertNotNull(taskDefList);
    assertEquals(0, taskDefList.size());
    TaskDef taskDef = new TaskDef();
    taskDef.setName(task1Name);
    // register a task definition
    metadataDAO.createTaskDef(taskDef);
    // fetch all task defs
    taskDefList = metadataDAO.getAllTaskDefs();
    assertNotNull(taskDefList);
    assertEquals(1, taskDefList.size());
    // fetch the task def
    TaskDef def = metadataDAO.getTaskDef(task1Name);
    assertEquals(taskDef, def);
    // register another task definition
    TaskDef taskDef1 = new TaskDef();
    taskDef1.setName(task2Name);
    metadataDAO.createTaskDef(taskDef1);
    // fetch all task defs
    taskDefList = metadataDAO.getAllTaskDefs();
    assertNotNull(taskDefList);
    assertEquals(2, taskDefList.size());
    // update task def
    taskDef.setOwnerEmail("juni@test.com");
    metadataDAO.updateTaskDef(taskDef);
    def = metadataDAO.getTaskDef(task1Name);
    assertEquals(taskDef, def);
    // delete task def
    metadataDAO.removeTaskDef(task2Name);
    taskDefList = metadataDAO.getAllTaskDefs();
    assertNotNull(taskDefList);
    assertEquals(1, taskDefList.size());
    // fetch deleted task def
    def = metadataDAO.getTaskDef(task2Name);
    assertNull(def);
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) 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