use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class ContribsModule method getQueues.
@Provides
public Map<Status, ObservableQueue> getQueues(Configuration config, AWSCredentialsProvider acp) {
String stack = "";
if (config.getStack() != null && config.getStack().length() > 0) {
stack = config.getStack() + "_";
}
Status[] statuses = new Status[] { Status.COMPLETED, Status.FAILED };
Map<Status, ObservableQueue> queues = new HashMap<>();
for (Status status : statuses) {
String queueName = config.getProperty("workflow.listener.queue.prefix", config.getAppId() + "_sqs_notify_" + stack + status.name());
AmazonSQSClient client = new AmazonSQSClient(acp);
Builder builder = new SQSObservableQueue.Builder().withClient(client).withQueueName(queueName);
String auth = config.getProperty("workflow.listener.queue.authorizedAccounts", "");
String[] accounts = auth.split(",");
for (String accountToAuthorize : accounts) {
accountToAuthorize = accountToAuthorize.trim();
if (accountToAuthorize.length() > 0) {
builder.addAccountToAuthorize(accountToAuthorize.trim());
}
}
ObservableQueue queue = builder.build();
queues.put(status, queue);
}
return queues;
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class TaskTest method test.
@Test
public void test() {
Task task = new Task();
task.setStatus(Status.FAILED);
assertEquals(Status.FAILED, task.getStatus());
Set<String> resultStatues = Arrays.stream(TaskResult.Status.values()).map(Enum::name).collect(Collectors.toSet());
for (Status status : Status.values()) {
if (resultStatues.contains(status.name())) {
TaskResult.Status trStatus = TaskResult.Status.valueOf(status.name());
assertEquals(status.name(), trStatus.name());
task = new Task();
task.setStatus(status);
assertEquals(status, task.getStatus());
}
}
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class DeciderService method checkForWorkflowCompletion.
@VisibleForTesting
boolean checkForWorkflowCompletion(final Workflow workflow) throws TerminateWorkflowException {
List<Task> allTasks = workflow.getTasks();
if (allTasks.isEmpty()) {
return false;
}
if (containsSuccessfulTerminateTask.test(workflow)) {
return true;
}
Map<String, Status> taskStatusMap = new HashMap<>();
workflow.getTasks().forEach(task -> taskStatusMap.put(task.getReferenceTaskName(), task.getStatus()));
List<WorkflowTask> workflowTasks = workflow.getWorkflowDefinition().getTasks();
boolean allCompletedSuccessfully = workflowTasks.stream().parallel().allMatch(wftask -> {
Status status = taskStatusMap.get(wftask.getTaskReferenceName());
return status != null && status.isSuccessful() && status.isTerminal();
});
boolean noPendingTasks = taskStatusMap.values().stream().allMatch(Status::isTerminal);
boolean noPendingSchedule = workflow.getTasks().stream().parallel().noneMatch(wftask -> {
String next = getNextTasksToBeScheduled(workflow, wftask);
return next != null && !taskStatusMap.containsKey(next);
});
return allCompletedSuccessfully && noPendingTasks && noPendingSchedule;
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class Join method execute.
@Override
@SuppressWarnings("unchecked")
public boolean execute(Workflow workflow, Task task, WorkflowExecutor provider) {
boolean allDone = true;
boolean hasFailures = false;
StringBuilder failureReason = new StringBuilder();
List<String> joinOn = (List<String>) task.getInputData().get("joinOn");
if (task.isLoopOverTask()) {
// If join is part of loop over task, wait for specific iteration to get complete
joinOn = joinOn.stream().map(name -> TaskUtils.appendIteration(name, task.getIteration())).collect(Collectors.toList());
}
for (String joinOnRef : joinOn) {
Task forkedTask = workflow.getTaskByRefName(joinOnRef);
if (forkedTask == null) {
// Task is not even scheduled yet
allDone = false;
break;
}
Status taskStatus = forkedTask.getStatus();
hasFailures = !taskStatus.isSuccessful() && !forkedTask.getWorkflowTask().isOptional();
if (hasFailures) {
failureReason.append(forkedTask.getReasonForIncompletion()).append(" ");
}
task.getOutputData().put(joinOnRef, forkedTask.getOutputData());
if (!taskStatus.isTerminal()) {
allDone = false;
}
if (hasFailures) {
break;
}
}
if (allDone || hasFailures) {
if (hasFailures) {
task.setReasonForIncompletion(failureReason.toString());
task.setStatus(Status.FAILED);
} else {
task.setStatus(Status.COMPLETED);
}
return true;
}
return false;
}
use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.
the class TestQueueManager method testFailure.
@Test(expected = IllegalArgumentException.class)
public void testFailure() throws Exception {
Map<Status, ObservableQueue> queues = new HashMap<>();
queues.put(Status.COMPLETED, queue);
QueueManager qm = new QueueManager(queues, es, objectMapper);
qm.updateByTaskRefName("v_1", "t1", new HashMap<>(), Status.CANCELED);
Uninterruptibles.sleepUninterruptibly(1_000, TimeUnit.MILLISECONDS);
}
Aggregations