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);
}
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);
}
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);
}
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));
}
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());
}
Aggregations