use of com.netflix.conductor.common.run.Workflow 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.run.Workflow 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.run.Workflow in project conductor by Netflix.
the class SubWorkflow method execute.
@Override
public boolean execute(Workflow workflow, Task task, WorkflowExecutor provider) {
String workflowId = task.getSubWorkflowId();
if (StringUtils.isEmpty(workflowId)) {
return false;
}
Workflow subWorkflow = provider.getWorkflow(workflowId, false);
WorkflowStatus subWorkflowStatus = subWorkflow.getStatus();
if (!subWorkflowStatus.isTerminal()) {
return false;
}
updateTaskStatus(subWorkflow, task);
return true;
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class ElasticSearchRestDAOV7 method updateWorkflow.
@Override
public void updateWorkflow(String workflowInstanceId, String[] keys, Object[] values) {
if (keys.length != values.length) {
throw new ApplicationException(ApplicationException.Code.INVALID_INPUT, "Number of keys and values do not match");
}
long startTime = Instant.now().toEpochMilli();
UpdateRequest request = new UpdateRequest(workflowIndexName, workflowInstanceId);
Map<String, Object> source = IntStream.range(0, keys.length).boxed().collect(Collectors.toMap(i -> keys[i], i -> values[i]));
request.doc(source);
logger.debug("Updating workflow {} with {}", workflowInstanceId, source);
new RetryUtil<UpdateResponse>().retryOnException(() -> {
try {
return elasticSearchClient.update(request, RequestOptions.DEFAULT);
} catch (IOException e) {
throw new RuntimeException(e);
}
}, null, null, RETRY_COUNT, "Updating workflow document: " + workflowInstanceId, "updateWorkflow");
long endTime = Instant.now().toEpochMilli();
logger.debug("Time taken {} for updating workflow: {}", endTime - startTime, workflowInstanceId);
Monitors.recordESIndexTime("update_workflow", WORKFLOW_DOC_TYPE, endTime - startTime);
Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size());
}
use of com.netflix.conductor.common.run.Workflow in project conductor by Netflix.
the class TestElasticSearchRestDAOV6 method shouldSearchRecentRunningWorkflows.
@Test
public void shouldSearchRecentRunningWorkflows() throws Exception {
Workflow oldWorkflow = TestUtils.loadWorkflowSnapshot("workflow");
oldWorkflow.setStatus(Workflow.WorkflowStatus.RUNNING);
oldWorkflow.setUpdateTime(new DateTime().minusHours(2).toDate().getTime());
Workflow recentWorkflow = TestUtils.loadWorkflowSnapshot("workflow");
recentWorkflow.setStatus(Workflow.WorkflowStatus.RUNNING);
recentWorkflow.setUpdateTime(new DateTime().minusHours(1).toDate().getTime());
Workflow tooRecentWorkflow = TestUtils.loadWorkflowSnapshot("workflow");
tooRecentWorkflow.setStatus(Workflow.WorkflowStatus.RUNNING);
tooRecentWorkflow.setUpdateTime(new DateTime().toDate().getTime());
indexDAO.indexWorkflow(oldWorkflow);
indexDAO.indexWorkflow(recentWorkflow);
indexDAO.indexWorkflow(tooRecentWorkflow);
Thread.sleep(1000);
List<String> ids = indexDAO.searchRecentRunningWorkflows(2, 1);
assertEquals(1, ids.size());
assertEquals(recentWorkflow.getWorkflowId(), ids.get(0));
}
Aggregations