Search in sources :

Example 1 with Status

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;
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) SQSObservableQueue(com.netflix.conductor.contribs.queue.sqs.SQSObservableQueue) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Builder(com.netflix.conductor.contribs.queue.sqs.SQSObservableQueue.Builder) AmazonSQSClient(com.amazonaws.services.sqs.AmazonSQSClient) Provides(com.google.inject.Provides)

Example 2 with Status

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());
        }
    }
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Example 3 with Status

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;
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 4 with Status

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;
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) Task(com.netflix.conductor.common.metadata.tasks.Task) List(java.util.List)

Example 5 with Status

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);
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) QueueManager(com.netflix.conductor.contribs.queue.QueueManager) Test(org.junit.Test)

Aggregations

Status (com.netflix.conductor.common.metadata.tasks.Task.Status)14 HashMap (java.util.HashMap)12 Task (com.netflix.conductor.common.metadata.tasks.Task)11 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 Workflow (com.netflix.conductor.common.run.Workflow)7 ExecutionService (com.netflix.conductor.service.ExecutionService)7 List (java.util.List)7 Test (org.junit.Test)7 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)6 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)6 JsonMapperProvider (com.netflix.conductor.common.utils.JsonMapperProvider)6 ObservableQueue (com.netflix.conductor.core.events.queue.ObservableQueue)6 Map (java.util.Map)6 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)5 WorkflowStatus (com.netflix.conductor.common.run.Workflow.WorkflowStatus)5 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)5 LinkedList (java.util.LinkedList)5 TimeUnit (java.util.concurrent.TimeUnit)5 Assert.assertNotNull (org.junit.Assert.assertNotNull)5 Assert.assertTrue (org.junit.Assert.assertTrue)5