Search in sources :

Example 1 with TaskDef

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

the class TaskTest method testTaskDefinitionIfAvailable.

@Test
public void testTaskDefinitionIfAvailable() {
    Task task = new Task();
    task.setStatus(Status.FAILED);
    assertEquals(Status.FAILED, task.getStatus());
    assertNull(task.getWorkflowTask());
    assertFalse(task.getTaskDefinition().isPresent());
    WorkflowTask workflowTask = new WorkflowTask();
    TaskDef taskDefinition = new TaskDef();
    workflowTask.setTaskDefinition(taskDefinition);
    task.setWorkflowTask(workflowTask);
    assertTrue(task.getTaskDefinition().isPresent());
    assertEquals(taskDefinition, task.getTaskDefinition().get());
}
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 2 with TaskDef

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

the class TaskDefTest method testTaskDef.

@Test
public void testTaskDef() {
    TaskDef taskDef = new TaskDef();
    taskDef.setName("task1");
    taskDef.setRetryCount(-1);
    taskDef.setTimeoutSeconds(1000);
    taskDef.setResponseTimeoutSeconds(1001);
    taskDef.setRetryLogic(RetryLogic.FIXED);
    taskDef.setRetryDelaySeconds(10);
    Set<ConstraintViolation<Object>> result = validator.validate(taskDef);
    assertEquals(3, result.size());
    List<String> validationErrors = new ArrayList<>();
    result.forEach(e -> validationErrors.add(e.getMessage()));
    assertTrue(validationErrors.contains("TaskDef: task1 responseTimeoutSeconds: 1001 must be less than timeoutSeconds: 1000"));
    assertTrue(validationErrors.contains("TaskDef retryCount: 0 must be >= 0"));
    assertTrue(validationErrors.contains("ownerEmail cannot be empty"));
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 3 with TaskDef

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

the class SimpleTaskMapperTest method getMappedTasksException.

@Test
public void getMappedTasksException() throws Exception {
    // Given
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setName("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();
    // then
    expectedException.expect(TerminateWorkflowException.class);
    expectedException.expectMessage(String.format("Invalid task. Task %s does not have a definition", taskToSchedule.getName()));
    // when
    simpleTaskMapper.getMappedTasks(taskMapperContext);
}
Also used : 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 4 with TaskDef

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

the class TerminateTaskMapperTest method getMappedTasks.

@Test
public void getMappedTasks() throws Exception {
    WorkflowTask taskToSchedule = new WorkflowTask();
    taskToSchedule.setType(TaskType.TASK_TYPE_TERMINATE);
    String taskId = IDGenerator.generate();
    WorkflowDef workflowDef = new WorkflowDef();
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withRetryCount(0).withTaskId(taskId).build();
    List<Task> mappedTasks = new TerminateTaskMapper(parametersUtils).getMappedTasks(taskMapperContext);
    Assert.assertNotNull(mappedTasks);
    Assert.assertEquals(1, mappedTasks.size());
    Assert.assertEquals(TaskType.TASK_TYPE_TERMINATE, 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 5 with TaskDef

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

the class TestWorkflowExecutor method testRestartWorkflow.

@Test
public void testRestartWorkflow() {
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("test_task");
    workflowTask.setTaskReferenceName("task_ref");
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("testDef");
    workflowDef.setVersion(1);
    workflowDef.setRestartable(true);
    workflowDef.getTasks().addAll(Collections.singletonList(workflowTask));
    Task task_1 = new Task();
    task_1.setTaskId(UUID.randomUUID().toString());
    task_1.setSeq(1);
    task_1.setStatus(Status.FAILED);
    task_1.setTaskDefName(workflowTask.getName());
    task_1.setReferenceTaskName(workflowTask.getTaskReferenceName());
    Task task_2 = new Task();
    task_2.setTaskId(UUID.randomUUID().toString());
    task_2.setSeq(2);
    task_2.setStatus(Status.FAILED);
    task_2.setTaskDefName(workflowTask.getName());
    task_2.setReferenceTaskName(workflowTask.getTaskReferenceName());
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.setWorkflowId("test-workflow-id");
    workflow.getTasks().addAll(Arrays.asList(task_1, task_2));
    workflow.setStatus(Workflow.WorkflowStatus.FAILED);
    when(executionDAOFacade.getWorkflowById(anyString(), anyBoolean())).thenReturn(workflow);
    doNothing().when(executionDAOFacade).removeTask(any());
    when(metadataDAO.getWorkflowDef(workflow.getWorkflowName(), workflow.getWorkflowVersion())).thenReturn(Optional.of(workflowDef));
    when(metadataDAO.getTaskDef(workflowTask.getName())).thenReturn(new TaskDef());
    when(executionDAOFacade.updateWorkflow(any())).thenReturn("");
    workflowExecutor.rewind(workflow.getWorkflowId(), false);
    assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
    verify(metadataDAO, never()).getLatestWorkflowDef(any());
    ArgumentCaptor<Workflow> argumentCaptor = ArgumentCaptor.forClass(Workflow.class);
    verify(executionDAOFacade, times(1)).createWorkflow(argumentCaptor.capture());
    assertEquals(workflow.getWorkflowId(), argumentCaptor.getAllValues().get(0).getWorkflowId());
    assertEquals(workflow.getWorkflowDefinition(), argumentCaptor.getAllValues().get(0).getWorkflowDefinition());
    // add a new version of the workflow definition and restart with latest
    workflow.setStatus(Workflow.WorkflowStatus.COMPLETED);
    workflowDef = new WorkflowDef();
    workflowDef.setName("testDef");
    workflowDef.setVersion(2);
    workflowDef.setRestartable(true);
    workflowDef.getTasks().addAll(Collections.singletonList(workflowTask));
    when(metadataDAO.getLatestWorkflowDef(workflow.getWorkflowName())).thenReturn(Optional.of(workflowDef));
    workflowExecutor.rewind(workflow.getWorkflowId(), true);
    assertEquals(Workflow.WorkflowStatus.RUNNING, workflow.getStatus());
    verify(metadataDAO, times(1)).getLatestWorkflowDef(anyString());
    argumentCaptor = ArgumentCaptor.forClass(Workflow.class);
    verify(executionDAOFacade, times(2)).createWorkflow(argumentCaptor.capture());
    assertEquals(workflow.getWorkflowId(), argumentCaptor.getAllValues().get(1).getWorkflowId());
    assertEquals(workflowDef, argumentCaptor.getAllValues().get(1).getWorkflowDefinition());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowSystemTask(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) 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)

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