Search in sources :

Example 1 with WorkflowSummary

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

the class WorkflowClientTest method testSearch.

@Test
public void testSearch() {
    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?query=my_complex_query"))))).thenReturn(clientResponse);
    SearchResult<WorkflowSummary> searchResult = workflowClient.search("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 2 with WorkflowSummary

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

the class WorkflowServiceImplTest method searchTest.

@Test
public void searchTest() throws InterruptedException {
    CountDownLatch streamAlive = new CountDownLatch(1);
    AtomicReference<WorkflowServicePb.WorkflowSummarySearchResult> result = new AtomicReference<>();
    SearchPb.Request req = SearchPb.Request.newBuilder().setStart(1).setSize(1).setSort("strings").setQuery("").setFreeText("").build();
    StreamObserver<WorkflowServicePb.WorkflowSummarySearchResult> streamObserver = new StreamObserver<WorkflowServicePb.WorkflowSummarySearchResult>() {

        @Override
        public void onNext(WorkflowServicePb.WorkflowSummarySearchResult value) {
            result.set(value);
        }

        @Override
        public void onError(Throwable t) {
            streamAlive.countDown();
        }

        @Override
        public void onCompleted() {
            streamAlive.countDown();
        }
    };
    WorkflowSummary workflow = new WorkflowSummary();
    SearchResult<WorkflowSummary> searchResult = new SearchResult<>();
    searchResult.setTotalHits(1);
    searchResult.setResults(Collections.singletonList(workflow));
    when(workflowService.searchWorkflows(anyInt(), anyInt(), anyList(), anyString(), anyString())).thenReturn(searchResult);
    workflowServiceImpl.search(req, streamObserver);
    streamAlive.await(10, TimeUnit.MILLISECONDS);
    WorkflowServicePb.WorkflowSummarySearchResult workflowSearchResult = result.get();
    assertEquals(1, workflowSearchResult.getTotalHits());
    assertEquals(WorkflowSummaryPb.WorkflowSummary.newBuilder().build(), workflowSearchResult.getResultsList().get(0));
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) SearchPb(com.netflix.conductor.grpc.SearchPb) AtomicReference(java.util.concurrent.atomic.AtomicReference) SearchResult(com.netflix.conductor.common.run.SearchResult) CountDownLatch(java.util.concurrent.CountDownLatch) WorkflowServicePb(com.netflix.conductor.grpc.WorkflowServicePb) Test(org.junit.Test)

Example 3 with WorkflowSummary

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

the class TestElasticSearchRestDAOV7 method shouldAsyncUpdateWorkflow.

@Test
public void shouldAsyncUpdateWorkflow() throws Exception {
    Workflow workflow = TestUtils.loadWorkflowSnapshot("workflow");
    WorkflowSummary summary = new WorkflowSummary(workflow);
    indexDAO.indexWorkflow(workflow);
    indexDAO.asyncUpdateWorkflow(workflow.getWorkflowId(), new String[] { "status" }, new Object[] { Workflow.WorkflowStatus.FAILED }).get();
    summary.setStatus(Workflow.WorkflowStatus.FAILED);
    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 4 with WorkflowSummary

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

the class TestElasticSearchRestDAOV7 method shouldIndexWorkflow.

@Test
public void shouldIndexWorkflow() {
    Workflow workflow = TestUtils.loadWorkflowSnapshot("workflow");
    WorkflowSummary summary = new WorkflowSummary(workflow);
    indexDAO.indexWorkflow(workflow);
    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 5 with WorkflowSummary

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

the class ElasticSearchRestDAOV5 method indexWorkflow.

@Override
public void indexWorkflow(Workflow workflow) {
    try {
        long startTime = Instant.now().toEpochMilli();
        String workflowId = workflow.getWorkflowId();
        WorkflowSummary summary = new WorkflowSummary(workflow);
        byte[] docBytes = objectMapper.writeValueAsBytes(summary);
        IndexRequest request = new IndexRequest(indexName, WORKFLOW_DOC_TYPE, workflowId);
        request.source(docBytes, XContentType.JSON);
        new RetryUtil<IndexResponse>().retryOnException(() -> {
            try {
                return elasticSearchClient.index(request);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }, null, null, RETRY_COUNT, "Indexing workflow document: " + workflow.getWorkflowId(), "indexWorkflow");
        long endTime = Instant.now().toEpochMilli();
        logger.debug("Time taken {} for indexing workflow: {}", endTime - startTime, workflowId);
        Monitors.recordESIndexTime("index_workflow", WORKFLOW_DOC_TYPE, endTime - startTime);
        Monitors.recordWorkerQueueSize("indexQueue", ((ThreadPoolExecutor) executorService).getQueue().size());
    } catch (Exception e) {
        Monitors.error(className, "indexWorkflow");
        logger.error("Failed to index workflow: {}", workflow.getWorkflowId(), e);
    }
}
Also used : WorkflowSummary(com.netflix.conductor.common.run.WorkflowSummary) IndexResponse(org.elasticsearch.action.index.IndexResponse) IOException(java.io.IOException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IndexRequest(org.elasticsearch.action.index.IndexRequest) ResponseException(org.elasticsearch.client.ResponseException) ApplicationException(com.netflix.conductor.core.execution.ApplicationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException)

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