Search in sources :

Example 1 with TaskMapperContext

use of com.netflix.conductor.core.execution.mapper.TaskMapperContext in project conductor by Netflix.

the class DeciderService method getTasksToBeScheduled.

public List<Task> getTasksToBeScheduled(Workflow workflow, WorkflowTask taskToSchedule, int retryCount, String retriedTaskId) {
    workflow = populateWorkflowAndTaskData(workflow);
    Map<String, Object> input = parametersUtils.getTaskInput(taskToSchedule.getInputParameters(), workflow, null, null);
    TaskType taskType = TaskType.USER_DEFINED;
    String type = taskToSchedule.getType();
    if (TaskType.isSystemTask(type)) {
        taskType = TaskType.valueOf(type);
    }
    // get tasks already scheduled (in progress/terminal) for  this workflow instance
    List<String> tasksInWorkflow = workflow.getTasks().stream().filter(runningTask -> runningTask.getStatus().equals(Status.IN_PROGRESS) || runningTask.getStatus().isTerminal()).map(Task::getReferenceTaskName).collect(Collectors.toList());
    String taskId = IDGenerator.generate();
    TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflow.getWorkflowDefinition()).withWorkflowInstance(workflow).withTaskDefinition(taskToSchedule.getTaskDefinition()).withTaskToSchedule(taskToSchedule).withTaskInput(input).withRetryCount(retryCount).withRetryTaskId(retriedTaskId).withTaskId(taskId).withDeciderService(this).build();
    // for static forks, each branch of the fork creates a join task upon completion
    // for dynamic forks, a join task is created with the fork and also with each branch of the fork
    // a new task must only be scheduled if a task with the same reference name is not already in this workflow instance
    List<Task> tasks = taskMappers.get(taskType.name()).getMappedTasks(taskMapperContext).stream().filter(task -> !tasksInWorkflow.contains(task.getReferenceTaskName())).collect(Collectors.toList());
    tasks.forEach(this::externalizeTaskData);
    return tasks;
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) TaskMapper(com.netflix.conductor.core.execution.mapper.TaskMapper) IDGenerator(com.netflix.conductor.core.utils.IDGenerator) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) LoggerFactory(org.slf4j.LoggerFactory) TaskMapperContext(com.netflix.conductor.core.execution.mapper.TaskMapperContext) HashMap(java.util.HashMap) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) LinkedHashMap(java.util.LinkedHashMap) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) COMPLETED_WITH_ERRORS(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS) ExternalPayloadStorageUtils(com.netflix.conductor.core.utils.ExternalPayloadStorageUtils) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) SKIPPED(com.netflix.conductor.common.metadata.tasks.Task.Status.SKIPPED) Operation(com.netflix.conductor.common.utils.ExternalPayloadStorage.Operation) Named(javax.inject.Named) LinkedList(java.util.LinkedList) Nullable(javax.annotation.Nullable) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Logger(org.slf4j.Logger) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) Predicate(java.util.function.Predicate) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Set(java.util.Set) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) Monitors(com.netflix.conductor.metrics.Monitors) TERMINATE(com.netflix.conductor.common.metadata.workflow.TaskType.TERMINATE) List(java.util.List) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) Optional(java.util.Optional) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Configuration(com.netflix.conductor.core.config.Configuration) PayloadType(com.netflix.conductor.common.utils.ExternalPayloadStorage.PayloadType) Collections(java.util.Collections) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) TaskMapperContext(com.netflix.conductor.core.execution.mapper.TaskMapperContext)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Task (com.netflix.conductor.common.metadata.tasks.Task)1 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)1 COMPLETED_WITH_ERRORS (com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS)1 IN_PROGRESS (com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS)1 SCHEDULED (com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED)1 SKIPPED (com.netflix.conductor.common.metadata.tasks.Task.Status.SKIPPED)1 TIMED_OUT (com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT)1 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)1 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)1 SUB_WORKFLOW (com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW)1 TERMINATE (com.netflix.conductor.common.metadata.workflow.TaskType.TERMINATE)1 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)1 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)1 Workflow (com.netflix.conductor.common.run.Workflow)1 WorkflowStatus (com.netflix.conductor.common.run.Workflow.WorkflowStatus)1 Operation (com.netflix.conductor.common.utils.ExternalPayloadStorage.Operation)1 PayloadType (com.netflix.conductor.common.utils.ExternalPayloadStorage.PayloadType)1 TaskUtils (com.netflix.conductor.common.utils.TaskUtils)1 Configuration (com.netflix.conductor.core.config.Configuration)1