Search in sources :

Example 11 with WorkflowSummary

use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.

the class WorkflowServiceTest method testSearchWorkflows.

@Test
public void testSearchWorkflows() {
    Workflow workflow = new Workflow();
    workflow.setCorrelationId("c123");
    WorkflowSummary workflowSummary = new WorkflowSummary(workflow);
    List<WorkflowSummary> listOfWorkflowSummary = new ArrayList<WorkflowSummary>() {

        {
            add(workflowSummary);
        }
    };
    SearchResult<WorkflowSummary> searchResult = new SearchResult<WorkflowSummary>(100, listOfWorkflowSummary);
    when(mockExecutionService.search("*", "*", 0, 100, Collections.singletonList("asc"))).thenReturn(searchResult);
    assertEquals(searchResult, workflowService.searchWorkflows(0, 100, "asc", "*", "*"));
    when(mockExecutionService.search("*", "*", 0, 100, Collections.singletonList("asc"))).thenReturn(searchResult);
    assertEquals(searchResult, workflowService.searchWorkflows(0, 100, Collections.singletonList("asc"), "*", "*"));
}
Also used : WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Workflow(com.netflix.conductor.common.run.Workflow) SearchResult(com.netflix.conductor.common.run.SearchResult) Test(org.junit.Test)

Example 12 with WorkflowSummary

use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.

the class WorkflowStatusPublisherIntegrationTest method testListenerOnCompletedWorkflow.

@Test
public void testListenerOnCompletedWorkflow() throws IOException, InterruptedException {
    clearWorkflows();
    WorkflowDef def = new WorkflowDef();
    def.setName(LINEAR_WORKFLOW_T1_T2);
    def.setDescription(def.getName());
    def.setVersion(WORKFLOW_VERSION);
    def.setSchemaVersion(2);
    def.setWorkflowStatusListenerEnabled(true);
    LinkedList<WorkflowTask> wftasks = new LinkedList<>();
    WorkflowTask wft1 = new WorkflowTask();
    wft1.setName("junit_task_1");
    wft1.setTaskReferenceName("t1");
    wftasks.add(wft1);
    def.setTasks(wftasks);
    metadataService.updateWorkflowDef(Collections.singletonList(def));
    String id = startOrLoadWorkflowExecution(def.getName(), 1, "testWorkflowCompletedListener", new HashMap<>(), null, null);
    List<Task> tasks = workflowExecutionService.getTasks("junit_task_1", null, 1);
    tasks.get(0).setStatus(COMPLETED);
    workflowExecutionService.updateTask(tasks.get(0));
    checkIfWorkflowIsCompleted(id);
    List<Message> callbackMessages = queueDAO.pollMessages(CALLBACK_QUEUE, 1, 200);
    queueDAO.ack(CALLBACK_QUEUE, callbackMessages.get(0).getId());
    WorkflowSummary payload = mapper.readValue(callbackMessages.get(0).getPayload(), WorkflowSummary.class);
    assertEquals(id, callbackMessages.get(0).getId());
    assertEquals(LINEAR_WORKFLOW_T1_T2, payload.getWorkflowType());
    assertEquals("testWorkflowCompletedListener", payload.getCorrelationId());
    assertEquals(Workflow.WorkflowStatus.COMPLETED, payload.getStatus());
}
Also used : WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Message(com.netflix.conductor.core.events.queue.Message) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 13 with WorkflowSummary

use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.

the class AbstractHttpEndToEndTest method testAll.

@Test
public void testAll() throws Exception {
    createAndRegisterTaskDefinitions("t", 5);
    WorkflowDef def = new WorkflowDef();
    def.setName("test");
    def.setOwnerEmail(DEFAULT_EMAIL_ADDRESS);
    WorkflowTask t0 = new WorkflowTask();
    t0.setName("t0");
    t0.setWorkflowTaskType(TaskType.SIMPLE);
    t0.setTaskReferenceName("t0");
    WorkflowTask t1 = new WorkflowTask();
    t1.setName("t1");
    t1.setWorkflowTaskType(TaskType.SIMPLE);
    t1.setTaskReferenceName("t1");
    def.getTasks().add(t0);
    def.getTasks().add(t1);
    metadataClient.registerWorkflowDef(def);
    WorkflowDef workflowDefinitionFromSystem = metadataClient.getWorkflowDef(def.getName(), null);
    assertNotNull(workflowDefinitionFromSystem);
    assertEquals(def, workflowDefinitionFromSystem);
    String correlationId = "test_corr_id";
    StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest().withName(def.getName()).withCorrelationId(correlationId).withPriority(50).withInput(new HashMap<>());
    String workflowId = workflowClient.startWorkflow(startWorkflowRequest);
    assertNotNull(workflowId);
    Workflow workflow = workflowClient.getWorkflow(workflowId, false);
    assertEquals(0, workflow.getTasks().size());
    assertEquals(workflowId, workflow.getWorkflowId());
    Awaitility.await().atMost(5, TimeUnit.SECONDS).untilAsserted(() -> {
        List<Workflow> workflowList = workflowClient.getWorkflows(def.getName(), correlationId, false, false);
        assertEquals(1, workflowList.size());
        assertEquals(workflowId, workflowList.get(0).getWorkflowId());
    });
    workflow = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(1, workflow.getTasks().size());
    assertEquals(t0.getTaskReferenceName(), workflow.getTasks().get(0).getReferenceTaskName());
    assertEquals(workflowId, workflow.getWorkflowId());
    int queueSize = taskClient.getQueueSizeForTask(workflow.getTasks().get(0).getTaskType());
    assertEquals(1, queueSize);
    List<String> runningIds = workflowClient.getRunningWorkflow(def.getName(), def.getVersion());
    assertNotNull(runningIds);
    assertEquals(1, runningIds.size());
    assertEquals(workflowId, runningIds.get(0));
    List<Task> polled = taskClient.batchPollTasksByTaskType("non existing task", "test", 1, 100);
    assertNotNull(polled);
    assertEquals(0, polled.size());
    polled = taskClient.batchPollTasksByTaskType(t0.getName(), "test", 1, 100);
    assertNotNull(polled);
    assertEquals(1, polled.size());
    assertEquals(t0.getName(), polled.get(0).getTaskDefName());
    Task task = polled.get(0);
    Boolean acked = taskClient.ack(task.getTaskId(), "test");
    assertNotNull(acked);
    assertTrue(acked);
    task.getOutputData().put("key1", "value1");
    task.setStatus(Status.COMPLETED);
    taskClient.updateTask(new TaskResult(task));
    polled = taskClient.batchPollTasksByTaskType(t0.getName(), "test", 1, 100);
    assertNotNull(polled);
    assertTrue(polled.toString(), polled.isEmpty());
    workflow = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(2, workflow.getTasks().size());
    assertEquals(t0.getTaskReferenceName(), workflow.getTasks().get(0).getReferenceTaskName());
    assertEquals(t1.getTaskReferenceName(), workflow.getTasks().get(1).getReferenceTaskName());
    assertEquals(Task.Status.COMPLETED, workflow.getTasks().get(0).getStatus());
    assertEquals(Task.Status.SCHEDULED, workflow.getTasks().get(1).getStatus());
    Task taskById = taskClient.getTaskDetails(task.getTaskId());
    assertNotNull(taskById);
    assertEquals(task.getTaskId(), taskById.getTaskId());
    queueSize = taskClient.getQueueSizeForTask(workflow.getTasks().get(1).getTaskType());
    assertEquals(1, queueSize);
    List<Task> getTasks = taskClient.getPendingTasksByType(t0.getName(), null, 1);
    assertNotNull(getTasks);
    // getTasks only gives pending tasks
    assertEquals(0, getTasks.size());
    getTasks = taskClient.getPendingTasksByType(t1.getName(), null, 1);
    assertNotNull(getTasks);
    assertEquals(1, getTasks.size());
    Task pending = taskClient.getPendingTaskForWorkflow(workflowId, t1.getTaskReferenceName());
    assertNotNull(pending);
    assertEquals(t1.getTaskReferenceName(), pending.getReferenceTaskName());
    assertEquals(workflowId, pending.getWorkflowInstanceId());
    Thread.sleep(1000);
    SearchResult<WorkflowSummary> searchResult = workflowClient.search("workflowType='" + def.getName() + "'");
    assertNotNull(searchResult);
    assertEquals(1, searchResult.getTotalHits());
    assertEquals(workflow.getWorkflowId(), searchResult.getResults().get(0).getWorkflowId());
    SearchResult<Workflow> searchResultV2 = workflowClient.searchV2("workflowType='" + def.getName() + "'");
    assertNotNull(searchResultV2);
    assertEquals(1, searchResultV2.getTotalHits());
    assertEquals(workflow.getWorkflowId(), searchResultV2.getResults().get(0).getWorkflowId());
    SearchResult<WorkflowSummary> searchResultAdvanced = workflowClient.search(0, 1, null, null, "workflowType='" + def.getName() + "'");
    assertNotNull(searchResultAdvanced);
    assertEquals(1, searchResultAdvanced.getTotalHits());
    assertEquals(workflow.getWorkflowId(), searchResultAdvanced.getResults().get(0).getWorkflowId());
    SearchResult<Workflow> searchResultV2Advanced = workflowClient.searchV2(0, 1, null, null, "workflowType='" + def.getName() + "'");
    assertNotNull(searchResultV2Advanced);
    assertEquals(1, searchResultV2Advanced.getTotalHits());
    assertEquals(workflow.getWorkflowId(), searchResultV2Advanced.getResults().get(0).getWorkflowId());
    workflowClient.terminateWorkflow(workflowId, "terminate reason");
    workflow = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.TERMINATED, workflow.getStatus());
    workflowClient.restart(workflowId, false);
    workflow = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(workflow);
    assertEquals(WorkflowStatus.RUNNING, workflow.getStatus());
    assertEquals(1, workflow.getTasks().size());
    workflowClient.skipTaskFromWorkflow(workflowId, "t1");
}
Also used : WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Task(com.netflix.conductor.common.metadata.tasks.Task) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Workflow(com.netflix.conductor.common.run.Workflow) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Example 14 with WorkflowSummary

use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.

the class ExecutionService method searchWorkflowByTasks.

public SearchResult<WorkflowSummary> searchWorkflowByTasks(String query, String freeText, int start, int size, List<String> sortOptions) {
    SearchResult<TaskSummary> taskSummarySearchResult = searchTasks(query, freeText, start, size, sortOptions);
    List<WorkflowSummary> workflowSummaries = taskSummarySearchResult.getResults().stream().parallel().map(taskSummary -> {
        try {
            String workflowId = taskSummary.getWorkflowId();
            return new WorkflowSummary(executionDAOFacade.getWorkflowById(workflowId, false));
        } catch (Exception e) {
            logger.error("Error fetching workflow by id: {}", taskSummary.getWorkflowId(), e);
            return null;
        }
    }).filter(Objects::nonNull).distinct().collect(Collectors.toList());
    int missing = taskSummarySearchResult.getResults().size() - workflowSummaries.size();
    long totalHits = taskSummarySearchResult.getTotalHits() - missing;
    return new SearchResult<>(totalHits, workflowSummaries);
}
Also used : QueueUtils(com.netflix.conductor.core.utils.QueueUtils) Status(com.netflix.conductor.common.metadata.tasks.Task.Status) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Task(com.netflix.conductor.common.metadata.tasks.Task) Singleton(javax.inject.Singleton) ExecutionDAOFacade(com.netflix.conductor.core.orchestration.ExecutionDAOFacade) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) ServiceUtils(com.netflix.conductor.service.utils.ServiceUtils) ArrayList(java.util.ArrayList) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Inject(javax.inject.Inject) Workflow(com.netflix.conductor.common.run.Workflow) Map(java.util.Map) PollData(com.netflix.conductor.common.metadata.tasks.PollData) ExternalPayloadStorage(com.netflix.conductor.common.utils.ExternalPayloadStorage) Max(javax.validation.constraints.Max) Operation(com.netflix.conductor.common.utils.ExternalPayloadStorage.Operation) WorkflowExecutor(com.netflix.conductor.core.execution.WorkflowExecutor) EventExecution(com.netflix.conductor.common.metadata.events.EventExecution) LinkedList(java.util.LinkedList) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) Message(com.netflix.conductor.core.events.queue.Message) SearchResult(com.netflix.conductor.common.run.SearchResult) Logger(org.slf4j.Logger) Trace(com.netflix.conductor.annotations.Trace) TaskExecLog(com.netflix.conductor.common.metadata.tasks.TaskExecLog) TaskSummary(com.netflix.conductor.common.run.TaskSummary) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) Collectors(java.util.stream.Collectors) Monitors(com.netflix.conductor.metrics.Monitors) ExternalStorageLocation(com.netflix.conductor.common.run.ExternalStorageLocation) Objects(java.util.Objects) QueueDAO(com.netflix.conductor.dao.QueueDAO) List(java.util.List) SystemTaskType(com.netflix.conductor.core.execution.SystemTaskType) Optional(java.util.Optional) Configuration(com.netflix.conductor.core.config.Configuration) Comparator(java.util.Comparator) PayloadType(com.netflix.conductor.common.utils.ExternalPayloadStorage.PayloadType) Collections(java.util.Collections) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) TaskSummary(com.netflix.conductor.common.run.TaskSummary) Objects(java.util.Objects) SearchResult(com.netflix.conductor.common.run.SearchResult) ApplicationException(com.netflix.conductor.core.execution.ApplicationException)

Example 15 with WorkflowSummary

use of com.netflix.conductor.common.run.WorkflowSummary in project conductor by Netflix.

the class WorkflowServiceTest method testSearchWorkflowsByTasks.

@Test
public void testSearchWorkflowsByTasks() {
    Workflow workflow = new Workflow();
    workflow.setCorrelationId("c123");
    WorkflowSummary workflowSummary = new WorkflowSummary(workflow);
    List<WorkflowSummary> listOfWorkflowSummary = new ArrayList<WorkflowSummary>() {

        {
            add(workflowSummary);
        }
    };
    SearchResult<WorkflowSummary> searchResult = new SearchResult<>(100, listOfWorkflowSummary);
    when(mockExecutionService.searchWorkflowByTasks("*", "*", 0, 100, Collections.singletonList("asc"))).thenReturn(searchResult);
    assertEquals(searchResult, workflowService.searchWorkflowsByTasks(0, 100, "asc", "*", "*"));
    when(mockExecutionService.searchWorkflowByTasks("*", "*", 0, 100, Collections.singletonList("asc"))).thenReturn(searchResult);
    assertEquals(searchResult, workflowService.searchWorkflowsByTasks(0, 100, Collections.singletonList("asc"), "*", "*"));
}
Also used : WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Workflow(com.netflix.conductor.common.run.Workflow) SearchResult(com.netflix.conductor.common.run.SearchResult) Test(org.junit.Test)

Aggregations

WorkflowSummary (com.netflix.conductor.common.run.WorkflowSummary)30 Test (org.junit.Test)22 Workflow (com.netflix.conductor.common.run.Workflow)19 SearchResult (com.netflix.conductor.common.run.SearchResult)7 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)6 IOException (java.io.IOException)5 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 Task (com.netflix.conductor.common.metadata.tasks.Task)4 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)4 Message (com.netflix.conductor.core.events.queue.Message)4 ParserException (com.netflix.conductor.elasticsearch.query.parser.ParserException)4 TaskResult (com.netflix.conductor.common.metadata.tasks.TaskResult)3 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)3 Collections (java.util.Collections)3 LinkedList (java.util.LinkedList)3 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)2 StartWorkflowRequest (com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest)2 SearchPb (com.netflix.conductor.grpc.SearchPb)2 WorkflowServicePb (com.netflix.conductor.grpc.WorkflowServicePb)2