Search in sources :

Example 96 with Task

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

the class LambdaTaskMapper method getMappedTasks.

@Override
public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) {
    LOGGER.debug("TaskMapperContext {} in LambdaTaskMapper", taskMapperContext);
    WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule();
    Workflow workflowInstance = taskMapperContext.getWorkflowInstance();
    String taskId = taskMapperContext.getTaskId();
    TaskDef taskDefinition = Optional.ofNullable(taskMapperContext.getTaskDefinition()).orElseGet(() -> Optional.ofNullable(metadataDAO.getTaskDef(taskToSchedule.getName())).orElse(null));
    Map<String, Object> taskInput = parametersUtils.getTaskInputV2(taskMapperContext.getTaskToSchedule().getInputParameters(), workflowInstance, taskId, taskDefinition);
    Task lambdaTask = new Task();
    lambdaTask.setTaskType(Lambda.TASK_NAME);
    lambdaTask.setTaskDefName(taskMapperContext.getTaskToSchedule().getName());
    lambdaTask.setReferenceTaskName(taskMapperContext.getTaskToSchedule().getTaskReferenceName());
    lambdaTask.setWorkflowInstanceId(workflowInstance.getWorkflowId());
    lambdaTask.setWorkflowType(workflowInstance.getWorkflowName());
    lambdaTask.setCorrelationId(workflowInstance.getCorrelationId());
    lambdaTask.setStartTime(System.currentTimeMillis());
    lambdaTask.setScheduledTime(System.currentTimeMillis());
    lambdaTask.setInputData(taskInput);
    lambdaTask.setTaskId(taskId);
    lambdaTask.setStatus(Task.Status.IN_PROGRESS);
    lambdaTask.setWorkflowTask(taskToSchedule);
    lambdaTask.setWorkflowPriority(workflowInstance.getPriority());
    return Collections.singletonList(lambdaTask);
}
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) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 97 with Task

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

the class SimpleTaskMapper method getMappedTasks.

/**
 * This method maps a {@link WorkflowTask} of type {@link TaskType#SIMPLE}
 * to a {@link Task}
 *
 * @param taskMapperContext: A wrapper class containing the {@link WorkflowTask}, {@link WorkflowDef}, {@link Workflow} and a string representation of the TaskId
 * @throws TerminateWorkflowException In case if the task definition does not exist
 * @return: a List with just one simple task
 */
@Override
public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) throws TerminateWorkflowException {
    logger.debug("TaskMapperContext {} in SimpleTaskMapper", taskMapperContext);
    WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule();
    Workflow workflowInstance = taskMapperContext.getWorkflowInstance();
    int retryCount = taskMapperContext.getRetryCount();
    String retriedTaskId = taskMapperContext.getRetryTaskId();
    TaskDef taskDefinition = Optional.ofNullable(taskToSchedule.getTaskDefinition()).orElseThrow(() -> {
        String reason = String.format("Invalid task. Task %s does not have a definition", taskToSchedule.getName());
        return new TerminateWorkflowException(reason);
    });
    Map<String, Object> input = parametersUtils.getTaskInput(taskToSchedule.getInputParameters(), workflowInstance, taskDefinition, taskMapperContext.getTaskId());
    Task simpleTask = new Task();
    simpleTask.setStartDelayInSeconds(taskToSchedule.getStartDelay());
    simpleTask.setTaskId(taskMapperContext.getTaskId());
    simpleTask.setReferenceTaskName(taskToSchedule.getTaskReferenceName());
    simpleTask.setInputData(input);
    simpleTask.setWorkflowInstanceId(workflowInstance.getWorkflowId());
    simpleTask.setWorkflowType(workflowInstance.getWorkflowName());
    simpleTask.setStatus(Task.Status.SCHEDULED);
    simpleTask.setTaskType(taskToSchedule.getName());
    simpleTask.setTaskDefName(taskToSchedule.getName());
    simpleTask.setCorrelationId(workflowInstance.getCorrelationId());
    simpleTask.setScheduledTime(System.currentTimeMillis());
    simpleTask.setRetryCount(retryCount);
    simpleTask.setCallbackAfterSeconds(taskToSchedule.getStartDelay());
    simpleTask.setResponseTimeoutSeconds(taskDefinition.getResponseTimeoutSeconds());
    simpleTask.setWorkflowTask(taskToSchedule);
    simpleTask.setRetriedTaskId(retriedTaskId);
    simpleTask.setWorkflowPriority(workflowInstance.getPriority());
    simpleTask.setRateLimitPerFrequency(taskDefinition.getRateLimitPerFrequency());
    simpleTask.setRateLimitFrequencyInSeconds(taskDefinition.getRateLimitFrequencyInSeconds());
    return Collections.singletonList(simpleTask);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) TerminateWorkflowException(com.netflix.conductor.core.execution.TerminateWorkflowException) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask)

Example 98 with Task

use of com.netflix.conductor.common.metadata.tasks.Task 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 99 with Task

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

the class TestElasticSearchRestDAOV6 method shouldIndexTaskAsync.

@Test
public void shouldIndexTaskAsync() throws Exception {
    Workflow workflow = TestUtils.loadWorkflowSnapshot("workflow");
    Task task = workflow.getTasks().get(0);
    TaskSummary summary = new TaskSummary(task);
    indexDAO.asyncIndexTask(task).get();
    List<String> tasks = tryFindResults(() -> searchTasks(workflow));
    assertEquals(summary.getTaskId(), tasks.get(0));
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) TaskSummary(com.netflix.conductor.common.run.TaskSummary) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 100 with Task

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

the class TestKafkaPublishTask method kafkaPublishSuccess_Completed.

@Test
public void kafkaPublishSuccess_Completed() throws ExecutionException, InterruptedException {
    Task task = getTask();
    KafkaProducerManager producerManager = Mockito.mock(KafkaProducerManager.class);
    KafkaPublishTask kPublishTask = new KafkaPublishTask(new SystemPropertiesConfiguration(), producerManager, objectMapper);
    Producer producer = Mockito.mock(Producer.class);
    Mockito.when(producerManager.getProducer(Mockito.any())).thenReturn(producer);
    Mockito.when(producer.send(Mockito.any())).thenReturn(Mockito.mock(Future.class));
    kPublishTask.start(Mockito.mock(Workflow.class), task, Mockito.mock(WorkflowExecutor.class));
    Assert.assertEquals(Task.Status.COMPLETED, task.getStatus());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) Producer(org.apache.kafka.clients.producer.Producer) Future(java.util.concurrent.Future) Workflow(com.netflix.conductor.common.run.Workflow) SystemPropertiesConfiguration(com.netflix.conductor.core.config.SystemPropertiesConfiguration) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) Test(org.junit.Test)

Aggregations

Task (com.netflix.conductor.common.metadata.tasks.Task)357 Workflow (com.netflix.conductor.common.run.Workflow)249 Test (org.junit.Test)248 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)227 HashMap (java.util.HashMap)147 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)121 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)110 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)95 UserTask (com.netflix.conductor.tests.utils.UserTask)73 Map (java.util.Map)53 LinkedList (java.util.LinkedList)51 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)45 List (java.util.List)45 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)41 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)39 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)38 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)29 Collectors (java.util.stream.Collectors)29 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)28