Search in sources :

Example 26 with WorkflowSummary

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

the class TestElasticSearchRestDAOV7 method shouldIndexWorkflowAsync.

@Test
public void shouldIndexWorkflowAsync() throws Exception {
    Workflow workflow = TestUtils.loadWorkflowSnapshot("workflow");
    WorkflowSummary summary = new WorkflowSummary(workflow);
    indexDAO.asyncIndexWorkflow(workflow).get();
    assertWorkflowSummary(workflow.getWorkflowId(), summary);
}
Also used : WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Workflow(com.netflix.conductor.common.run.Workflow) Test(org.junit.Test)

Example 27 with WorkflowSummary

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

the class AbstractGrpcEndToEndTest method testAll.

@Test
public void testAll() throws Exception {
    assertNotNull(taskClient);
    List<TaskDef> defs = new LinkedList<>();
    for (int i = 0; i < 5; i++) {
        TaskDef def = new TaskDef("t" + i, "task " + i, DEFAULT_EMAIL_ADDRESS, 3, 60, 60);
        def.setTimeoutPolicy(TimeoutPolicy.RETRY);
        defs.add(def);
    }
    metadataClient.registerTaskDefs(defs);
    for (int i = 0; i < 5; i++) {
        final String taskName = "t" + i;
        TaskDef def = metadataClient.getTaskDef(taskName);
        assertNotNull(def);
        assertEquals(taskName, def.getName());
    }
    WorkflowDef def = createWorkflowDefinition("test");
    WorkflowTask t0 = createWorkflowTask("t0");
    WorkflowTask t1 = createWorkflowTask("t1");
    def.getTasks().add(t0);
    def.getTasks().add(t1);
    metadataClient.registerWorkflowDef(def);
    WorkflowDef found = metadataClient.getWorkflowDef(def.getName(), null);
    assertNotNull(found);
    assertEquals(def, found);
    String correlationId = "test_corr_id";
    StartWorkflowRequest startWf = new StartWorkflowRequest();
    startWf.setName(def.getName());
    startWf.setCorrelationId(correlationId);
    String workflowId = workflowClient.startWorkflow(startWf);
    assertNotNull(workflowId);
    System.out.println("Started workflow id=" + workflowId);
    Workflow wf = workflowClient.getWorkflow(workflowId, false);
    assertEquals(0, wf.getTasks().size());
    assertEquals(workflowId, wf.getWorkflowId());
    wf = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(wf);
    assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
    assertEquals(1, wf.getTasks().size());
    assertEquals(t0.getTaskReferenceName(), wf.getTasks().get(0).getReferenceTaskName());
    assertEquals(workflowId, wf.getWorkflowId());
    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());
    wf = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(wf);
    assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
    assertEquals(2, wf.getTasks().size());
    assertEquals(t0.getTaskReferenceName(), wf.getTasks().get(0).getReferenceTaskName());
    assertEquals(t1.getTaskReferenceName(), wf.getTasks().get(1).getReferenceTaskName());
    assertEquals(Status.COMPLETED, wf.getTasks().get(0).getStatus());
    assertEquals(Status.SCHEDULED, wf.getTasks().get(1).getStatus());
    Task taskById = taskClient.getTaskDetails(task.getTaskId());
    assertNotNull(taskById);
    assertEquals(task.getTaskId(), taskById.getTaskId());
    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(wf.getWorkflowId(), searchResult.getResults().get(0).getWorkflowId());
    SearchResult<Workflow> searchResultV2 = workflowClient.searchV2("workflowType='" + def.getName() + "'");
    assertNotNull(searchResultV2);
    assertEquals(1, searchResultV2.getTotalHits());
    assertEquals(wf.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(wf.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(wf.getWorkflowId(), searchResultV2Advanced.getResults().get(0).getWorkflowId());
    workflowClient.terminateWorkflow(workflowId, "terminate reason");
    wf = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(wf);
    assertEquals(WorkflowStatus.TERMINATED, wf.getStatus());
    workflowClient.restart(workflowId, false);
    wf = workflowClient.getWorkflow(workflowId, true);
    assertNotNull(wf);
    assertEquals(WorkflowStatus.RUNNING, wf.getStatus());
    assertEquals(1, wf.getTasks().size());
}
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) LinkedList(java.util.LinkedList) StartWorkflowRequest(com.netflix.conductor.common.metadata.workflow.StartWorkflowRequest) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) TaskResult(com.netflix.conductor.common.metadata.tasks.TaskResult) Test(org.junit.Test)

Example 28 with WorkflowSummary

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

the class WorkflowStatusPublisherIntegrationTest method testListenerOnTerminatedWorkflow.

@Test
public void testListenerOnTerminatedWorkflow() throws IOException {
    String id = startOrLoadWorkflowExecution(LINEAR_WORKFLOW_T1_T2, 1, "testWorkflowTerminatedListener", new HashMap<>(), null, null);
    workflowExecutor.terminateWorkflow(id, INCOMPLETION_REASON);
    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("testWorkflowTerminatedListener", payload.getCorrelationId());
    assertEquals(Workflow.WorkflowStatus.TERMINATED, payload.getStatus());
    assertEquals(INCOMPLETION_REASON, payload.getReasonForIncompletion());
}
Also used : WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Message(com.netflix.conductor.core.events.queue.Message) Test(org.junit.Test)

Example 29 with WorkflowSummary

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

the class WorkflowClientTest method testSearchWithParams.

@Test
public void testSearchWithParams() {
    ClientResponse clientResponse = mock(ClientResponse.class);
    SearchResult<WorkflowSummary> workflowSearchResult = new SearchResult<>();
    workflowSearchResult.setTotalHits(1);
    WorkflowSummary workflowSummary = new WorkflowSummary(new Workflow());
    workflowSearchResult.setResults(Collections.singletonList(workflowSummary));
    when(clientResponse.getEntity(argThat((GenericType<SearchResult<WorkflowSummary>> type) -> ((ParameterizedTypeImpl) type.getType()).getRawType().equals(SearchResult.class) && ((ParameterizedTypeImpl) type.getType()).getActualTypeArguments()[0].equals(WorkflowSummary.class)))).thenReturn(workflowSearchResult);
    when(clientHandler.handle(argThat(argument -> argument.getURI().equals(URI.create("http://myuri:8080/workflow/search?start=0&size=10&sort=sort&freeText=text&query=my_complex_query"))))).thenReturn(clientResponse);
    SearchResult<WorkflowSummary> searchResult = workflowClient.search(0, 10, "sort", "text", "my_complex_query");
    assertEquals(1, searchResult.getTotalHits());
    assertEquals(Collections.singletonList(workflowSummary), searchResult.getResults());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ClientHandler(com.sun.jersey.api.client.ClientHandler) SearchResult(com.netflix.conductor.common.run.SearchResult) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) Mock(org.mockito.Mock) ClientResponse(com.sun.jersey.api.client.ClientResponse) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Workflow(com.netflix.conductor.common.run.Workflow) GenericType(com.sun.jersey.api.client.GenericType) ParameterizedTypeImpl(sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl) URI(java.net.URI) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) Before(org.junit.Before) TestCase.assertEquals(junit.framework.TestCase.assertEquals) Mockito.mock(org.mockito.Mockito.mock) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Workflow(com.netflix.conductor.common.run.Workflow) SearchResult(com.netflix.conductor.common.run.SearchResult) ParameterizedTypeImpl(sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl) Test(org.junit.Test)

Example 30 with WorkflowSummary

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

the class DynoQueueStatusPublisher method workflowToMessage.

private Message workflowToMessage(Workflow workflow) {
    String jsonWfSummary;
    WorkflowSummary summary = new WorkflowSummary(workflow);
    try {
        jsonWfSummary = objectMapper.writeValueAsString(summary);
    } catch (JsonProcessingException e) {
        LOGGER.error("Failed to convert WorkflowSummary: {} to String. Exception: {}", summary, e);
        throw new RuntimeException(e);
    }
    return new Message(workflow.getWorkflowId(), jsonWfSummary, null);
}
Also used : WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) Message(com.netflix.conductor.core.events.queue.Message) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

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