Search in sources :

Example 66 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class TerminateTaskMapper method getMappedTasks.

@Override
public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) {
    logger.debug("TaskMapperContext {} in TerminateTaskMapper", taskMapperContext);
    WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule();
    Workflow workflowInstance = taskMapperContext.getWorkflowInstance();
    String taskId = taskMapperContext.getTaskId();
    Map<String, Object> taskInput = parametersUtils.getTaskInputV2(taskMapperContext.getTaskToSchedule().getInputParameters(), workflowInstance, taskId, null);
    Task task = new Task();
    task.setTaskType(Terminate.TASK_NAME);
    task.setTaskDefName(taskToSchedule.getName());
    task.setReferenceTaskName(taskToSchedule.getTaskReferenceName());
    task.setWorkflowInstanceId(workflowInstance.getWorkflowId());
    task.setWorkflowType(workflowInstance.getWorkflowName());
    task.setCorrelationId(workflowInstance.getCorrelationId());
    task.setScheduledTime(System.currentTimeMillis());
    task.setStartTime(System.currentTimeMillis());
    task.setInputData(taskInput);
    task.setTaskId(taskId);
    task.setStatus(Task.Status.IN_PROGRESS);
    task.setWorkflowTask(taskToSchedule);
    task.setWorkflowPriority(workflowInstance.getPriority());
    return singletonList(task);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 67 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class ExecutionDAOTest method testTaskExceedsLimit.

@Test
public void testTaskExceedsLimit() {
    TaskDef taskDefinition = new TaskDef();
    taskDefinition.setName("task1");
    taskDefinition.setConcurrentExecLimit(1);
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("task1");
    workflowTask.setTaskDefinition(taskDefinition);
    workflowTask.setTaskDefinition(taskDefinition);
    List<Task> tasks = new LinkedList<>();
    for (int i = 0; i < 15; i++) {
        Task task = new Task();
        task.setScheduledTime(1L);
        task.setSeq(i + 1);
        task.setTaskId("t_" + i);
        task.setWorkflowInstanceId("workflow_" + i);
        task.setReferenceTaskName("task1");
        task.setTaskDefName("task1");
        tasks.add(task);
        task.setStatus(Task.Status.SCHEDULED);
        task.setWorkflowTask(workflowTask);
    }
    getExecutionDAO().createTasks(tasks);
    assertFalse(getExecutionDAO().exceedsInProgressLimit(tasks.get(0)));
    tasks.get(0).setStatus(Task.Status.IN_PROGRESS);
    getExecutionDAO().updateTask(tasks.get(0));
    for (Task task : tasks) {
        assertTrue(getExecutionDAO().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) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 68 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class MetadataMapperServiceTest method testShouldNotPopulateTaskDefinition.

@Test
public void testShouldNotPopulateTaskDefinition() {
    WorkflowTask workflowTask = createWorkflowTask("");
    assertFalse(metadataMapperService.shouldPopulateTaskDefinition(workflowTask));
}
Also used : WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 69 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class MetadataMapperServiceTest method testVersionPopulationForSubworkflowTaskIfVersionIsNotAvailable.

@Test
public void testVersionPopulationForSubworkflowTaskIfVersionIsNotAvailable() {
    String nameTaskDefinition = "taskSubworkflow6";
    String workflowDefinitionName = "subworkflow";
    Integer version = 3;
    WorkflowDef subWorkflowDefinition = createWorkflowDefinition("workflowDefinitionName");
    subWorkflowDefinition.setVersion(version);
    WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition);
    workflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW);
    SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
    subWorkflowParams.setName(workflowDefinitionName);
    workflowTask.setSubWorkflowParam(subWorkflowParams);
    WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation");
    workflowDefinition.setTasks(ImmutableList.of(workflowTask));
    when(metadataDAO.getLatestWorkflowDef(workflowDefinitionName)).thenReturn(Optional.of(subWorkflowDefinition));
    metadataMapperService.populateTaskDefinitions(workflowDefinition);
    assertEquals(1, workflowDefinition.getTasks().size());
    List<WorkflowTask> workflowTasks = workflowDefinition.getTasks();
    SubWorkflowParams params = workflowTasks.get(0).getSubWorkflowParam();
    assertEquals(workflowDefinitionName, params.getName());
    assertEquals(version, params.getVersion());
    verify(metadataDAO).getLatestWorkflowDef(workflowDefinitionName);
    verify(metadataDAO).getTaskDef(nameTaskDefinition);
    verifyNoMoreInteractions(metadataDAO);
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 70 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class MetadataMapperServiceTest method createWorkflowTask.

private WorkflowTask createWorkflowTask(String name) {
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName(name);
    workflowTask.setType(TaskType.SIMPLE.name());
    return workflowTask;
}
Also used : WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Aggregations

WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)244 Test (org.junit.Test)166 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)148 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)106 Workflow (com.netflix.conductor.common.run.Workflow)106 HashMap (java.util.HashMap)103 Task (com.netflix.conductor.common.metadata.tasks.Task)98 ArrayList (java.util.ArrayList)52 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)44 ConstraintViolation (javax.validation.ConstraintViolation)41 LinkedList (java.util.LinkedList)40 List (java.util.List)36 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)32 Map (java.util.Map)26 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)25 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)18 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)14 UserTask (com.netflix.conductor.tests.utils.UserTask)14 ValidatorFactory (javax.validation.ValidatorFactory)13 VisibleForTesting (com.google.common.annotations.VisibleForTesting)11