Search in sources :

Example 6 with Status

use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.

the class TestQueueManager method test.

@Test
public void test() throws Exception {
    Map<Status, ObservableQueue> queues = new HashMap<>();
    queues.put(Status.COMPLETED, queue);
    QueueManager qm = new QueueManager(queues, es, objectMapper);
    qm.updateByTaskRefName("v_0", "t0", new HashMap<>(), Status.COMPLETED);
    Uninterruptibles.sleepUninterruptibly(1_000, TimeUnit.MILLISECONDS);
    assertTrue(updatedTasks.stream().anyMatch(task -> task.getTaskId().equals("t0")));
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeClass(org.junit.BeforeClass) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) Wait(com.netflix.conductor.core.execution.tasks.Wait) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Task(com.netflix.conductor.common.metadata.tasks.Task) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Workflow(com.netflix.conductor.common.run.Workflow) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) LinkedList(java.util.LinkedList) Mockito.doReturn(org.mockito.Mockito.doReturn) Message(com.netflix.conductor.core.events.queue.Message) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) QueueManager(com.netflix.conductor.contribs.queue.QueueManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ExecutionService(com.netflix.conductor.service.ExecutionService) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) QueueManager(com.netflix.conductor.contribs.queue.QueueManager) Test(org.junit.Test)

Example 7 with Status

use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.

the class TestQueueManager method testWithTaskId.

@Test
public void testWithTaskId() throws Exception {
    Map<Status, ObservableQueue> queues = new HashMap<>();
    queues.put(Status.COMPLETED, queue);
    QueueManager qm = new QueueManager(queues, es, objectMapper);
    qm.updateByTaskId("v_2", "t2", new HashMap<>(), Status.COMPLETED);
    Uninterruptibles.sleepUninterruptibly(1_000, TimeUnit.MILLISECONDS);
    assertTrue(updatedTasks.stream().anyMatch(task -> task.getTaskId().equals("t2")));
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeClass(org.junit.BeforeClass) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) Wait(com.netflix.conductor.core.execution.tasks.Wait) ArgumentMatchers.anyBoolean(org.mockito.ArgumentMatchers.anyBoolean) Task(com.netflix.conductor.common.metadata.tasks.Task) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Workflow(com.netflix.conductor.common.run.Workflow) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) LinkedList(java.util.LinkedList) Mockito.doReturn(org.mockito.Mockito.doReturn) Message(com.netflix.conductor.core.events.queue.Message) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) QueueManager(com.netflix.conductor.contribs.queue.QueueManager) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) ExecutionService(com.netflix.conductor.service.ExecutionService) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Mockito.mock(org.mockito.Mockito.mock) HashMap(java.util.HashMap) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) QueueManager(com.netflix.conductor.contribs.queue.QueueManager) Test(org.junit.Test)

Example 8 with Status

use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.

the class QueueManager method queues.

public Map<Status, String> queues() {
    Map<Status, String> size = new HashMap<>();
    queues.entrySet().forEach(e -> {
        ObservableQueue queue = e.getValue();
        size.put(e.getKey(), queue.getURI());
    });
    return size;
}
Also used : Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue)

Example 9 with Status

use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.

the class QueueManager method startMonitor.

private void startMonitor(Status status, ObservableQueue queue) {
    queue.observe().subscribe((Message msg) -> {
        try {
            logger.debug("Got message {}", msg.getPayload());
            String payload = msg.getPayload();
            JsonNode payloadJSON = objectMapper.readTree(payload);
            String externalId = getValue("externalId", payloadJSON);
            if (externalId == null || "".equals(externalId)) {
                logger.error("No external Id found in the payload {}", payload);
                queue.ack(Collections.singletonList(msg));
                return;
            }
            JsonNode json = objectMapper.readTree(externalId);
            String workflowId = getValue("workflowId", json);
            String taskRefName = getValue("taskRefName", json);
            String taskId = getValue("taskId", json);
            if (workflowId == null || "".equals(workflowId)) {
                // This is a bad message, we cannot process it
                logger.error("No workflow id found in the message. {}", payload);
                queue.ack(Collections.singletonList(msg));
                return;
            }
            Workflow workflow = executionService.getExecutionStatus(workflowId, true);
            Optional<Task> taskOptional;
            if (StringUtils.isNotEmpty(taskId)) {
                taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskId().equals(taskId)).findFirst();
            } else if (StringUtils.isEmpty(taskRefName)) {
                logger.error("No taskRefName found in the message. If there is only one WAIT task, will mark it as completed. {}", payload);
                taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getTaskType().equals(Wait.NAME)).findFirst();
            } else {
                taskOptional = workflow.getTasks().stream().filter(task -> !task.getStatus().isTerminal() && task.getReferenceTaskName().equals(taskRefName)).findFirst();
            }
            if (!taskOptional.isPresent()) {
                logger.error("No matching tasks found to be marked as completed for workflow {}, taskRefName {}, taskId {}", workflowId, taskRefName, taskId);
                queue.ack(Collections.singletonList(msg));
                return;
            }
            Task task = taskOptional.get();
            task.setStatus(status);
            task.getOutputData().putAll(objectMapper.convertValue(payloadJSON, _mapType));
            executionService.updateTask(task);
            List<String> failures = queue.ack(Collections.singletonList(msg));
            if (!failures.isEmpty()) {
                logger.error("Not able to ack the messages {}", failures.toString());
            }
        } catch (JsonParseException e) {
            logger.error("Bad message? : {} ", msg, e);
            queue.ack(Collections.singletonList(msg));
        } catch (ApplicationException e) {
            if (e.getCode().equals(Code.NOT_FOUND)) {
                logger.error("Workflow ID specified is not valid for this environment");
                queue.ack(Collections.singletonList(msg));
            }
            logger.error("Error processing message: {}", msg, e);
        } catch (Exception e) {
            logger.error("Error processing message: {}", msg, e);
        }
    }, (Throwable t) -> {
        logger.error(t.getMessage(), t);
    });
    logger.info("QueueListener::STARTED...listening for " + queue.getName());
}
Also used : Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) Wait(com.netflix.conductor.core.execution.tasks.Wait) Singleton(javax.inject.Singleton) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) Inject(javax.inject.Inject) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) TypeReference(com.fasterxml.jackson.core.type.TypeReference) JsonParseException(com.fasterxml.jackson.core.JsonParseException) Code(com.netflix.conductor.core.execution.ApplicationException.Code) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Message(com.netflix.conductor.core.events.queue.Message) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UUID(java.util.UUID) List(java.util.List) Optional(java.util.Optional) ExecutionService(com.netflix.conductor.service.ExecutionService) Collections(java.util.Collections) ObservableQueue(com.netflix.conductor.core.events.queue.ObservableQueue) Task(com.netflix.conductor.common.metadata.tasks.Task) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Message(com.netflix.conductor.core.events.queue.Message) Workflow(com.netflix.conductor.common.run.Workflow) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonParseException(com.fasterxml.jackson.core.JsonParseException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 10 with Status

use of com.netflix.conductor.common.metadata.tasks.Task.Status in project conductor by Netflix.

the class AbstractWorkflowServiceTest method testSubWorkflowTaskToDomainWildcard.

@Test
public void testSubWorkflowTaskToDomainWildcard() {
    Map<String, String> taskToDomain = new HashMap<>();
    taskToDomain.put("*", "unittest");
    createSubWorkflow(taskToDomain);
    metadataService.getWorkflowDef(WF_WITH_SUB_WF, 1);
    Map<String, Object> input = new HashMap<>();
    input.put("param1", "param 1 value");
    input.put("param3", "param 2 value");
    input.put("wfName", LINEAR_WORKFLOW_T1_T2);
    String workflowId = startOrLoadWorkflowExecution(WF_WITH_SUB_WF, 1, "test", input, null, null);
    assertNotNull(workflowId);
    Workflow workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    Task task = workflowExecutionService.poll("junit_task_5", "test");
    assertNotNull(task);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertNotNull(workflow.getTasks());
    // Simulating SystemTaskWorkerCoordinator to execute async system tasks
    String subWorkflowTaskId = workflow.getTaskByRefName("a2").getTaskId();
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    task = workflow.getTasks().stream().filter(t -> t.getTaskType().equals(SUB_WORKFLOW.name())).findAny().get();
    assertNotNull(task);
    assertNotNull(task.getOutputData());
    assertNotNull("Output: " + task.getOutputData().toString() + ", status: " + task.getStatus(), task.getSubWorkflowId());
    assertNotNull(task.getInputData());
    assertTrue(task.getInputData().containsKey("workflowInput"));
    assertEquals(42, ((Map<String, Object>) task.getInputData().get("workflowInput")).get("param2"));
    String subWorkflowId = task.getSubWorkflowId();
    Workflow subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertNotNull(subWorkflow.getTasks());
    assertEquals(workflowId, subWorkflow.getParentWorkflowId());
    assertEquals(RUNNING, subWorkflow.getStatus());
    task = workflowExecutionService.poll("junit_task_1", "test", "unittest");
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("junit_task_2", "test", "unittest");
    assertEquals(subWorkflowId, task.getWorkflowInstanceId());
    String uuid = UUID.randomUUID().toString();
    task.getOutputData().put("uuid", uuid);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    subWorkflow = workflowExecutionService.getExecutionStatus(subWorkflowId, true);
    assertNotNull(subWorkflow);
    assertEquals(WorkflowStatus.COMPLETED, subWorkflow.getStatus());
    assertNotNull(subWorkflow.getOutput());
    assertTrue(subWorkflow.getOutput().containsKey("o1"));
    assertTrue(subWorkflow.getOutput().containsKey("o2"));
    assertEquals("sub workflow input param1", subWorkflow.getOutput().get("o1"));
    assertEquals(uuid, subWorkflow.getOutput().get("o2"));
    assertEquals(taskToDomain, subWorkflow.getTaskToDomain());
    // Execute again to re-evaluate the Subworkflow task.
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
    task = workflowExecutionService.poll("junit_task_6", "test");
    assertNotNull(task);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) MethodSorters(org.junit.runners.MethodSorters) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Arrays(java.util.Arrays) TimeoutPolicy(com.netflix.conductor.common.metadata.tasks.TaskDef.TimeoutPolicy) TEMP_FILE_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TEMP_FILE_PATH) LoggerFactory(org.slf4j.LoggerFactory) Task(com.netflix.conductor.common.metadata.tasks.Task) StringUtils(org.apache.commons.lang3.StringUtils) Future(java.util.concurrent.Future) COMPLETED_WITH_ERRORS(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS) RerunWorkflowRequest(com.netflix.conductor.common.metadata.workflow.RerunWorkflowRequest) Workflow(com.netflix.conductor.common.run.Workflow) IN_PROGRESS(com.netflix.conductor.common.metadata.tasks.Task.Status.IN_PROGRESS) Map(java.util.Map) After(org.junit.After) PollData(com.netflix.conductor.common.metadata.tasks.PollData) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) TASK_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.TASK_OUTPUT_PATH) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) WorkflowRepairService(com.netflix.conductor.core.execution.WorkflowRepairService) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Set(java.util.Set) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Executors(java.util.concurrent.Executors) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) QueueDAO(com.netflix.conductor.dao.QueueDAO) INPUT_PAYLOAD_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INPUT_PAYLOAD_PATH) List(java.util.List) DynamicForkJoinTaskList(com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList) Assert.assertFalse(org.junit.Assert.assertFalse) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) COMPLETED(com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED) ExecutionService(com.netflix.conductor.service.ExecutionService) FixMethodOrder(org.junit.FixMethodOrder) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) MetadataService(com.netflix.conductor.service.MetadataService) WorkflowContext(com.netflix.conductor.core.WorkflowContext) BeforeClass(org.junit.BeforeClass) SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) LinkedList(java.util.LinkedList) ExpectedException(org.junit.rules.ExpectedException) RUNNING(com.netflix.conductor.common.run.Workflow.WorkflowStatus.RUNNING) ExecutorService(java.util.concurrent.ExecutorService) Before(org.junit.Before) TERMINATED(com.netflix.conductor.common.run.Workflow.WorkflowStatus.TERMINATED) INITIAL_WORKFLOW_INPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.INITIAL_WORKFLOW_INPUT_PATH) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Uninterruptibles(com.google.common.util.concurrent.Uninterruptibles) Logger(org.slf4j.Logger) WorkflowSweeper(com.netflix.conductor.core.execution.WorkflowSweeper) Assert.assertNotNull(org.junit.Assert.assertNotNull) UserTask(com.netflix.conductor.tests.utils.UserTask) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FileOutputStream(java.io.FileOutputStream) Test(org.junit.Test) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) WORKFLOW_OUTPUT_PATH(com.netflix.conductor.tests.utils.MockExternalPayloadStorage.WORKFLOW_OUTPUT_PATH) TimeUnit(java.util.concurrent.TimeUnit) DECISION(com.netflix.conductor.common.metadata.workflow.TaskType.DECISION) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) Ignore(org.junit.Ignore) RetryLogic(com.netflix.conductor.common.metadata.tasks.TaskDef.RetryLogic) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) UserTask(com.netflix.conductor.tests.utils.UserTask) HashMap(java.util.HashMap) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) 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