Search in sources :

Example 76 with Task

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

the class TestElasticSearchDAOV5 method indexTask.

@Test
public void indexTask() throws Exception {
    String correlationId = "some-correlation-id";
    Task task = new Task();
    task.setTaskId("some-task-id");
    task.setWorkflowInstanceId("some-workflow-instance-id");
    task.setTaskType("some-task-type");
    task.setStatus(Status.FAILED);
    task.setInputData(new HashMap<String, Object>() {

        {
            put("input_key", "input_value");
        }
    });
    task.setCorrelationId(correlationId);
    task.setTaskDefName("some-task-def-name");
    task.setReasonForIncompletion("some-failure-reason");
    indexDAO.indexTask(task);
    await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
        SearchResult<String> result = indexDAO.searchTasks("correlationId='" + correlationId + "'", "*", 0, 10000, null);
        assertTrue("should return 1 or more search results", result.getResults().size() > 0);
        assertEquals("taskId should match the indexed task", "some-task-id", result.getResults().get(0));
    });
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) Test(org.junit.Test)

Example 77 with Task

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

the class TestElasticSearchRestDAOV5 method createTestWorkflow.

@Before
public void createTestWorkflow() throws Exception {
    // define indices
    indexDAO.setup();
    // initialize workflow
    workflow = new Workflow();
    workflow.getInput().put("requestId", "request id 001");
    workflow.getInput().put("hasAwards", true);
    workflow.getInput().put("channelMapping", 5);
    Map<String, Object> name = new HashMap<>();
    name.put("name", "The Who");
    name.put("year", 1970);
    Map<String, Object> name2 = new HashMap<>();
    name2.put("name", "The Doors");
    name2.put("year", 1975);
    List<Object> names = new LinkedList<>();
    names.add(name);
    names.add(name2);
    workflow.getOutput().put("name", name);
    workflow.getOutput().put("names", names);
    workflow.getOutput().put("awards", 200);
    Task task = new Task();
    task.setReferenceTaskName("task2");
    task.getOutputData().put("location", "http://location");
    task.setStatus(Task.Status.COMPLETED);
    Task task2 = new Task();
    task2.setReferenceTaskName("task3");
    task2.getOutputData().put("refId", "abcddef_1234_7890_aaffcc");
    task2.setStatus(Task.Status.SCHEDULED);
    workflow.getTasks().add(task);
    workflow.getTasks().add(task2);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 78 with Task

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

the class TestElasticSearchDAOV5 method createTestWorkflow.

@Before
public void createTestWorkflow() throws Exception {
    // define indices
    indexDAO.setup();
    // initialize workflow
    workflow = new Workflow();
    workflow.getInput().put("requestId", "request id 001");
    workflow.getInput().put("hasAwards", true);
    workflow.getInput().put("channelMapping", 5);
    Map<String, Object> name = new HashMap<>();
    name.put("name", "The Who");
    name.put("year", 1970);
    Map<String, Object> name2 = new HashMap<>();
    name2.put("name", "The Doors");
    name2.put("year", 1975);
    List<Object> names = new LinkedList<>();
    names.add(name);
    names.add(name2);
    workflow.getOutput().put("name", name);
    workflow.getOutput().put("names", names);
    workflow.getOutput().put("awards", 200);
    Task task = new Task();
    task.setReferenceTaskName("task2");
    task.getOutputData().put("location", "http://location");
    task.setStatus(Task.Status.COMPLETED);
    Task task2 = new Task();
    task2.setReferenceTaskName("task3");
    task2.getOutputData().put("refId", "abcddef_1234_7890_aaffcc");
    task2.setStatus(Task.Status.SCHEDULED);
    workflow.getTasks().add(task);
    workflow.getTasks().add(task2);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 79 with Task

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

the class TestElasticSearchDAOV5 method indexTaskWithBatchSizeTwo.

@Test
public void indexTaskWithBatchSizeTwo() throws Exception {
    embeddedElasticSearch.stop();
    startElasticSearchWithBatchSize(2);
    String correlationId = "some-correlation-id";
    Task task = new Task();
    task.setTaskId("some-task-id");
    task.setWorkflowInstanceId("some-workflow-instance-id");
    task.setTaskType("some-task-type");
    task.setStatus(Status.FAILED);
    task.setInputData(new HashMap<String, Object>() {

        {
            put("input_key", "input_value");
        }
    });
    task.setCorrelationId(correlationId);
    task.setTaskDefName("some-task-def-name");
    task.setReasonForIncompletion("some-failure-reason");
    indexDAO.indexTask(task);
    indexDAO.indexTask(task);
    await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
        SearchResult<String> result = indexDAO.searchTasks("correlationId='" + correlationId + "'", "*", 0, 10000, null);
        assertTrue("should return 1 or more search results", result.getResults().size() > 0);
        assertEquals("taskId should match the indexed task", "some-task-id", result.getResults().get(0));
    });
    embeddedElasticSearch.stop();
    startElasticSearchWithBatchSize(1);
}
Also used : Task(com.netflix.conductor.common.metadata.tasks.Task) Test(org.junit.Test)

Example 80 with Task

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

the class WorkflowExecutor method resetCallbacksForWorkflow.

/**
 * @param workflowId the id of the workflow for which task callbacks are to be reset
 * @throws ApplicationException if the workflow is in terminal state
 */
public void resetCallbacksForWorkflow(String workflowId) {
    Workflow workflow = executionDAOFacade.getWorkflowById(workflowId, true);
    if (workflow.getStatus().isTerminal()) {
        throw new ApplicationException(CONFLICT, "Workflow is in terminal state. Status =" + workflow.getStatus());
    }
    // Get SIMPLE tasks in SCHEDULED state that have callbackAfterSeconds > 0 and set the callbackAfterSeconds to 0
    workflow.getTasks().stream().filter(task -> !isSystemTask.test(task) && SCHEDULED.equals(task.getStatus()) && task.getCallbackAfterSeconds() > 0).forEach(task -> {
        if (queueDAO.resetOffsetTime(QueueUtils.getQueueName(task), task.getTaskId())) {
            task.setCallbackAfterSeconds(0);
            executionDAOFacade.updateTask(task);
        }
    });
}
Also used : TaskUtils(com.netflix.conductor.common.utils.TaskUtils) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) ExecutionLockService(com.netflix.conductor.service.ExecutionLockService) Arrays(java.util.Arrays) INVALID_INPUT(com.netflix.conductor.core.execution.ApplicationException.Code.INVALID_INPUT) NOT_FOUND(com.netflix.conductor.core.execution.ApplicationException.Code.NOT_FOUND) QueueUtils(com.netflix.conductor.core.utils.QueueUtils) LoggerFactory(org.slf4j.LoggerFactory) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) CANCELED(com.netflix.conductor.common.metadata.tasks.Task.Status.CANCELED) Task(com.netflix.conductor.common.metadata.tasks.Task) ExecutionDAOFacade(com.netflix.conductor.core.orchestration.ExecutionDAOFacade) StringUtils(org.apache.commons.lang3.StringUtils) WorkflowSystemTask(com.netflix.conductor.core.execution.tasks.WorkflowSystemTask) 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) PollData(com.netflix.conductor.common.metadata.tasks.PollData) SKIPPED(com.netflix.conductor.common.metadata.tasks.Task.Status.SKIPPED) Terminate(com.netflix.conductor.core.execution.tasks.Terminate) Code(com.netflix.conductor.core.execution.ApplicationException.Code) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) Status.valueOf(com.netflix.conductor.common.metadata.tasks.Task.Status.valueOf) Trace(com.netflix.conductor.annotations.Trace) WorkflowStatus(com.netflix.conductor.common.run.Workflow.WorkflowStatus) MetadataMapperService(com.netflix.conductor.core.metadata.MetadataMapperService) Predicate(java.util.function.Predicate) Collectors(java.util.stream.Collectors) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) SCHEDULED(com.netflix.conductor.common.metadata.tasks.Task.Status.SCHEDULED) Objects(java.util.Objects) QueueDAO(com.netflix.conductor.dao.QueueDAO) List(java.util.List) TIMED_OUT(com.netflix.conductor.common.metadata.tasks.Task.Status.TIMED_OUT) Optional(java.util.Optional) Status(com.netflix.conductor.common.metadata.tasks.TaskResult.Status) Configuration(com.netflix.conductor.core.config.Configuration) CONFLICT(com.netflix.conductor.core.execution.ApplicationException.Code.CONFLICT) WorkflowContext(com.netflix.conductor.core.WorkflowContext) IDGenerator(com.netflix.conductor.core.utils.IDGenerator) HashMap(java.util.HashMap) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) SUB_WORKFLOW(com.netflix.conductor.common.metadata.workflow.TaskType.SUB_WORKFLOW) SkipTaskRequest(com.netflix.conductor.common.metadata.workflow.SkipTaskRequest) FAILED_WITH_TERMINAL_ERROR(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED_WITH_TERMINAL_ERROR) Logger(org.slf4j.Logger) RetryUtil(com.netflix.conductor.common.utils.RetryUtil) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) FAILED(com.netflix.conductor.common.metadata.tasks.Task.Status.FAILED) Monitors(com.netflix.conductor.metrics.Monitors) TERMINATE(com.netflix.conductor.common.metadata.workflow.TaskType.TERMINATE) Preconditions(com.google.common.base.Preconditions) TaskType(com.netflix.conductor.common.metadata.workflow.TaskType) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Comparator(java.util.Comparator) Collections(java.util.Collections) SubWorkflow(com.netflix.conductor.core.execution.tasks.SubWorkflow) Workflow(com.netflix.conductor.common.run.Workflow)

Aggregations

Task (com.netflix.conductor.common.metadata.tasks.Task)357 Workflow (com.netflix.conductor.common.run.Workflow)249 Test (org.junit.Test)248 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)227 HashMap (java.util.HashMap)147 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)121 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)110 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)95 UserTask (com.netflix.conductor.tests.utils.UserTask)73 Map (java.util.Map)53 LinkedList (java.util.LinkedList)51 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)45 List (java.util.List)45 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)41 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)39 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)38 Status (com.netflix.conductor.common.metadata.tasks.Task.Status)32 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)29 Collectors (java.util.stream.Collectors)29 TaskType (com.netflix.conductor.common.metadata.workflow.TaskType)28