Search in sources :

Example 6 with PollData

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

the class PostgresExecutionDAO method getAllPollData.

@Override
public List<PollData> getAllPollData() {
    try (Connection tx = dataSource.getConnection()) {
        boolean previousAutoCommitMode = tx.getAutoCommit();
        tx.setAutoCommit(true);
        try {
            String GET_ALL_POLL_DATA = "SELECT json_data FROM poll_data ORDER BY queue_name";
            return query(tx, GET_ALL_POLL_DATA, q -> q.executeAndFetch(PollData.class));
        } catch (Throwable th) {
            throw new ApplicationException(BACKEND_ERROR, th.getMessage(), th);
        } finally {
            tx.setAutoCommit(previousAutoCommitMode);
        }
    } catch (SQLException ex) {
        throw new ApplicationException(BACKEND_ERROR, ex.getMessage(), ex);
    }
}
Also used : ApplicationException(com.netflix.conductor.core.execution.ApplicationException) SQLException(java.sql.SQLException) PollData(com.netflix.conductor.common.metadata.tasks.PollData) Connection(java.sql.Connection)

Example 7 with PollData

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

the class AbstractWorkflowServiceTest method testSimpleWorkflowWithTaskSpecificDomain.

@Test
public void testSimpleWorkflowWithTaskSpecificDomain() throws Exception {
    long startTimeTimestamp = System.currentTimeMillis();
    clearWorkflows();
    createWorkflowWithSubWorkflow();
    metadataService.getWorkflowDef(LINEAR_WORKFLOW_T1_T2_SW, 1);
    String correlationId = "unit_test_sw";
    Map<String, Object> input = new HashMap<>();
    String inputParam1 = "p1 value";
    input.put("param1", inputParam1);
    input.put("param2", "p2 value");
    Map<String, String> taskToDomain = new HashMap<>();
    taskToDomain.put("junit_task_3", "domain1");
    taskToDomain.put("junit_task_2", "domain1");
    // Poll before so that a polling for this task is "active"
    Task task = workflowExecutionService.poll("junit_task_3", "task1.junit.worker", "domain1");
    assertNull(task);
    task = workflowExecutionService.poll("junit_task_2", "task1.junit.worker", "domain1");
    assertNull(task);
    String workflowId = startOrLoadWorkflowExecution("simpleWorkflowWithTaskSpecificDomain", LINEAR_WORKFLOW_T1_T2_SW, 1, correlationId, input, null, taskToDomain);
    assertNotNull(workflowId);
    Workflow workflow = workflowExecutor.getWorkflow(workflowId, false);
    assertNotNull(workflow);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(workflow.getReasonForIncompletion(), RUNNING, workflow.getStatus());
    assertEquals(RUNNING, workflow.getStatus());
    // The very first task is the one that should be scheduled.
    assertEquals(1, workflow.getTasks().size());
    // Check Size
    Map<String, Integer> sizes = workflowExecutionService.getTaskQueueSizes(Arrays.asList("domain1:junit_task_3", "junit_task_3"));
    assertEquals(sizes.get("domain1:junit_task_3").intValue(), 1);
    assertEquals(sizes.get("junit_task_3").intValue(), 0);
    // Polling for the first task
    task = workflowExecutionService.poll("junit_task_3", "task1.junit.worker");
    assertNull(task);
    task = workflowExecutionService.poll("junit_task_3", "task1.junit.worker", "domain1");
    assertNotNull(task);
    assertEquals("junit_task_3", task.getTaskType());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertEquals(workflowId, task.getWorkflowInstanceId());
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    List<Task> tasks = workflowExecutionService.getTasks(task.getTaskType(), null, 10);
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    task = tasks.get(0);
    assertEquals(workflowId, task.getWorkflowInstanceId());
    String task1Op = "task1.Done";
    task.getOutputData().put("op", task1Op);
    task.setStatus(COMPLETED);
    workflowExecutionService.updateTask(task);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(RUNNING, workflow.getStatus());
    // Simulating SystemTaskWorkerCoordinator to execute async system tasks
    String subWorkflowTaskId = workflow.getTaskByRefName("sw1").getTaskId();
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
    task = workflowExecutionService.poll("junit_task_1", "task1.junit.worker");
    assertNotNull(task);
    assertEquals("junit_task_1", task.getTaskType());
    workflow = workflowExecutionService.getExecutionStatus(workflowId, false);
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    assertNotNull(workflow.getTaskToDomain());
    assertEquals(workflow.getTaskToDomain().size(), 2);
    task.setStatus(COMPLETED);
    task.setReasonForIncompletion("unit test failure");
    workflowExecutionService.updateTask(task);
    task = workflowExecutionService.poll("junit_task_2", "task2.junit.worker", "domain1");
    assertNotNull(task);
    assertEquals("junit_task_2", task.getTaskType());
    assertTrue(workflowExecutionService.ackTaskReceived(task.getTaskId()));
    task.setStatus(COMPLETED);
    task.setReasonForIncompletion("unit test failure");
    workflowExecutionService.updateTask(task);
    // Execute again to re-evaluate the Subworkflow task.
    workflowExecutor.executeSystemTask(dummySubWorkflowSystemTask, subWorkflowTaskId, 1);
    workflow = workflowExecutionService.getExecutionStatus(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.COMPLETED, workflow.getStatus());
    tasks = workflow.getTasks();
    assertNotNull(tasks);
    assertEquals(2, tasks.size());
    assertTrue("Found " + workflow.getOutput().toString(), workflow.getOutput().containsKey("o3"));
    assertEquals("task1.Done", workflow.getOutput().get("o3"));
    Predicate<PollData> pollDataWithinTestTimes = pollData -> pollData.getLastPollTime() != 0 && pollData.getLastPollTime() > startTimeTimestamp;
    List<PollData> pollData = workflowExecutionService.getPollData("junit_task_3").stream().filter(pollDataWithinTestTimes).collect(Collectors.toList());
    assertEquals(2, pollData.size());
    for (PollData pd : pollData) {
        assertEquals(pd.getQueueName(), "junit_task_3");
        assertEquals(pd.getWorkerId(), "task1.junit.worker");
        assertTrue(pd.getLastPollTime() != 0);
        if (pd.getDomain() != null) {
            assertEquals(pd.getDomain(), "domain1");
        }
    }
    List<PollData> pdList = workflowExecutionService.getAllPollData().stream().filter(pollDataWithinTestTimes).collect(Collectors.toList());
    int count = 0;
    for (PollData pd : pdList) {
        if (pd.getQueueName().equals("junit_task_3")) {
            count++;
        }
    }
    assertEquals(2, count);
}
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) PollData(com.netflix.conductor.common.metadata.tasks.PollData) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 8 with PollData

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

the class TestWorkflowExecutor method testDefaultDomain.

@Test
public void testDefaultDomain() {
    String taskType = "test-task";
    String[] domains = new String[] { "domain1", "domain2", "NO_DOMAIN" };
    PollData pollData1 = new PollData("queue1", domains[0], "worker1", System.currentTimeMillis() - 99 * 10000);
    when(executionDAOFacade.getTaskPollDataByDomain(taskType, domains[0])).thenReturn(pollData1);
    when(executionDAOFacade.getTaskPollDataByDomain(taskType, domains[1])).thenReturn(null);
    String activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertNull(activeDomain);
}
Also used : PollData(com.netflix.conductor.common.metadata.tasks.PollData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 9 with PollData

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

the class TestWorkflowExecutor method testGetActiveDomain.

@Test
public void testGetActiveDomain() {
    String taskType = "test-task";
    String[] domains = new String[] { "domain1", "domain2" };
    PollData pollData1 = new PollData("queue1", domains[0], "worker1", System.currentTimeMillis() - 99 * 1000);
    when(executionDAOFacade.getTaskPollDataByDomain(taskType, domains[0])).thenReturn(pollData1);
    String activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertEquals(domains[0], activeDomain);
    Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
    PollData pollData2 = new PollData("queue2", domains[1], "worker2", System.currentTimeMillis() - 99 * 1000);
    when(executionDAOFacade.getTaskPollDataByDomain(taskType, domains[1])).thenReturn(pollData2);
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertEquals(domains[1], activeDomain);
    Uninterruptibles.sleepUninterruptibly(2, TimeUnit.SECONDS);
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertEquals(domains[1], activeDomain);
    domains = new String[] { "" };
    when(executionDAOFacade.getTaskPollDataByDomain(any(), any())).thenReturn(new PollData());
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertNotNull(activeDomain);
    assertEquals("", activeDomain);
    domains = new String[] {};
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertNull(activeDomain);
    activeDomain = workflowExecutor.getActiveDomain(taskType, null);
    assertNull(activeDomain);
    domains = new String[] { "test-domain" };
    when(executionDAOFacade.getTaskPollDataByDomain(anyString(), anyString())).thenReturn(null);
    activeDomain = workflowExecutor.getActiveDomain(taskType, domains);
    assertNotNull(activeDomain);
    assertEquals("test-domain", activeDomain);
}
Also used : PollData(com.netflix.conductor.common.metadata.tasks.PollData) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 10 with PollData

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

the class TestWorkflowExecutor method testTaskToDomainOverrides.

@Test
public void testTaskToDomainOverrides() {
    Workflow workflow = generateSampleWorkflow();
    List<Task> tasks = generateSampleTasks(4);
    Map<String, String> taskToDomain = new HashMap<>();
    taskToDomain.put("*", "mydomain");
    taskToDomain.put("task2", "someInactiveDomain, NO_DOMAIN");
    taskToDomain.put("task3", "someActiveDomain, NO_DOMAIN");
    taskToDomain.put("task4", "someInactiveDomain, someInactiveDomain2");
    workflow.setTaskToDomain(taskToDomain);
    PollData pollData1 = new PollData("queue1", "mydomain", "worker1", System.currentTimeMillis() - 99 * 100);
    PollData pollData2 = new PollData("queue2", "someActiveDomain", "worker2", System.currentTimeMillis() - 99 * 100);
    when(executionDAOFacade.getTaskPollDataByDomain(anyString(), eq("mydomain"))).thenReturn(pollData1);
    when(executionDAOFacade.getTaskPollDataByDomain(anyString(), eq("someInactiveDomain"))).thenReturn(null);
    when(executionDAOFacade.getTaskPollDataByDomain(anyString(), eq("someActiveDomain"))).thenReturn(pollData2);
    when(executionDAOFacade.getTaskPollDataByDomain(anyString(), eq("someInactiveDomain"))).thenReturn(null);
    workflowExecutor.setTaskDomains(tasks, workflow);
    assertEquals("mydomain", tasks.get(0).getDomain());
    assertNull(tasks.get(1).getDomain());
    assertEquals("someActiveDomain", tasks.get(2).getDomain());
    assertEquals("someInactiveDomain2", tasks.get(3).getDomain());
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowSystemTask(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) HashMap(java.util.HashMap) PollData(com.netflix.conductor.common.metadata.tasks.PollData) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Aggregations

PollData (com.netflix.conductor.common.metadata.tasks.PollData)17 Test (org.junit.Test)10 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 Task (com.netflix.conductor.common.metadata.tasks.Task)4 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)4 Workflow (com.netflix.conductor.common.run.Workflow)4 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)4 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)3 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)3 HashMap (java.util.HashMap)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Uninterruptibles (com.google.common.util.concurrent.Uninterruptibles)1 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)1 COMPLETED (com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED)1 COMPLETED_WITH_ERRORS (com.netflix.conductor.common.metadata.tasks.Task.Status.COMPLETED_WITH_ERRORS)1 FAILED (com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED)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