Search in sources :

Example 11 with SearchResult

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

the class ExecutionDAOFacadeTest method testGetWorkflowsByCorrelationId.

@Test
public void testGetWorkflowsByCorrelationId() {
    when(executionDAO.canSearchAcrossWorkflows()).thenReturn(true);
    when(executionDAO.getWorkflowsByCorrelationId(any(), any(), anyBoolean())).thenReturn(Collections.singletonList(new Workflow()));
    List<Workflow> workflows = executionDAOFacade.getWorkflowsByCorrelationId("workflowName", "correlationId", true);
    assertNotNull(workflows);
    assertEquals(1, workflows.size());
    verify(indexDAO, never()).searchWorkflows(anyString(), anyString(), anyInt(), anyInt(), any());
    when(executionDAO.canSearchAcrossWorkflows()).thenReturn(false);
    List<String> workflowIds = new ArrayList<>();
    workflowIds.add("workflowId");
    SearchResult<String> searchResult = new SearchResult<>();
    searchResult.setResults(workflowIds);
    when(indexDAO.searchWorkflows(anyString(), anyString(), anyInt(), anyInt(), any())).thenReturn(searchResult);
    when(executionDAO.getWorkflow("workflowId", true)).thenReturn(new Workflow());
    workflows = executionDAOFacade.getWorkflowsByCorrelationId("workflowName", "correlationId", true);
    assertNotNull(workflows);
    assertEquals(1, workflows.size());
}
Also used : ArrayList(java.util.ArrayList) Workflow(com.netflix.conductor.common.run.Workflow) SearchResult(com.netflix.conductor.common.run.SearchResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 12 with SearchResult

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

the class ElasticSearchRestDAOV6 method searchObjectIds.

/**
 * Tries to find object ids for a given query in an index.
 *
 * @param indexName    The name of the index.
 * @param queryBuilder The query to use for searching.
 * @param start        The start to use.
 * @param size         The total return size.
 * @param sortOptions  A list of string options to sort in the form VALUE:ORDER; where ORDER is optional and can be
 *                     either ASC OR DESC.
 * @param docType      The document type to searchObjectIdsViaExpression for.
 * @return The SearchResults which includes the count and IDs that were found.
 * @throws IOException If we cannot communicate with ES.
 */
private SearchResult<String> searchObjectIds(String indexName, QueryBuilder queryBuilder, int start, int size, List<String> sortOptions, String docType) throws IOException {
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(queryBuilder);
    searchSourceBuilder.from(start);
    searchSourceBuilder.size(size);
    if (sortOptions != null && !sortOptions.isEmpty()) {
        for (String sortOption : sortOptions) {
            SortOrder order = SortOrder.ASC;
            String field = sortOption;
            int index = sortOption.indexOf(":");
            if (index > 0) {
                field = sortOption.substring(0, index);
                order = SortOrder.valueOf(sortOption.substring(index + 1));
            }
            searchSourceBuilder.sort(new FieldSortBuilder(field).order(order));
        }
    }
    // Generate the actual request to send to ES.
    docType = StringUtils.isBlank(docTypeOverride) ? docType : docTypeOverride;
    SearchRequest searchRequest = new SearchRequest(indexName);
    searchRequest.types(docType);
    searchRequest.source(searchSourceBuilder);
    SearchResponse response = elasticSearchClient.search(searchRequest);
    List<String> result = new LinkedList<>();
    response.getHits().forEach(hit -> result.add(hit.getId()));
    long count = response.getHits().getTotalHits();
    return new SearchResult<>(count, result);
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) SortOrder(org.elasticsearch.search.sort.SortOrder) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) SearchResult(com.netflix.conductor.common.run.SearchResult) LinkedList(java.util.LinkedList) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 13 with SearchResult

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

the class ElasticSearchRestDAOV7 method searchObjectIds.

/**
 * Tries to find object ids for a given query in an index.
 *
 * @param indexName    The name of the index.
 * @param queryBuilder The query to use for searching.
 * @param start        The start to use.
 * @param size         The total return size.
 * @param sortOptions  A list of string options to sort in the form VALUE:ORDER; where ORDER is optional and can be
 *                     either ASC OR DESC.
 * @param docType      The document type to searchObjectIdsViaExpression for.
 * @return The SearchResults which includes the count and IDs that were found.
 * @throws IOException If we cannot communicate with ES.
 */
private SearchResult<String> searchObjectIds(String indexName, QueryBuilder queryBuilder, int start, int size, List<String> sortOptions, String docType) throws IOException {
    SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
    searchSourceBuilder.query(queryBuilder);
    searchSourceBuilder.from(start);
    searchSourceBuilder.size(size);
    if (sortOptions != null && !sortOptions.isEmpty()) {
        for (String sortOption : sortOptions) {
            SortOrder order = SortOrder.ASC;
            String field = sortOption;
            int index = sortOption.indexOf(":");
            if (index > 0) {
                field = sortOption.substring(0, index);
                order = SortOrder.valueOf(sortOption.substring(index + 1));
            }
            searchSourceBuilder.sort(new FieldSortBuilder(field).order(order));
        }
    }
    // Generate the actual request to send to ES.
    SearchRequest searchRequest = new SearchRequest(indexName);
    searchRequest.source(searchSourceBuilder);
    SearchResponse response = elasticSearchClient.search(searchRequest, RequestOptions.DEFAULT);
    List<String> result = new LinkedList<>();
    response.getHits().forEach(hit -> result.add(hit.getId()));
    long count = response.getHits().getTotalHits().value;
    return new SearchResult<>(count, result);
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) SortOrder(org.elasticsearch.search.sort.SortOrder) FieldSortBuilder(org.elasticsearch.search.sort.FieldSortBuilder) SearchResult(com.netflix.conductor.common.run.SearchResult) LinkedList(java.util.LinkedList) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 14 with SearchResult

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

the class WorkflowServiceImplTest method searchByTasksTest.

@Test
public void searchByTasksTest() 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.searchWorkflowsByTasks(anyInt(), anyInt(), anyList(), anyString(), anyString())).thenReturn(searchResult);
    workflowServiceImpl.searchByTasks(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 15 with SearchResult

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

the class WorkflowServiceImplTest method searchByTasksV2Test.

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

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

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

        @Override
        public void onCompleted() {
            streamAlive.countDown();
        }
    };
    Workflow workflow = new Workflow();
    SearchResult<Workflow> searchResult = new SearchResult<>();
    searchResult.setTotalHits(1);
    searchResult.setResults(Collections.singletonList(workflow));
    when(workflowService.searchWorkflowsByTasksV2(1, 1, Collections.singletonList("strings"), "*", "")).thenReturn(searchResult);
    workflowServiceImpl.searchByTasksV2(req, streamObserver);
    streamAlive.await(10, TimeUnit.MILLISECONDS);
    WorkflowServicePb.WorkflowSearchResult workflowSearchResult = result.get();
    assertEquals(1, workflowSearchResult.getTotalHits());
    assertEquals(WorkflowPb.Workflow.newBuilder().build(), workflowSearchResult.getResultsList().get(0));
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) SearchPb(com.netflix.conductor.grpc.SearchPb) Workflow(com.netflix.conductor.common.run.Workflow) 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)

Aggregations

SearchResult (com.netflix.conductor.common.run.SearchResult)19 Test (org.junit.Test)14 Workflow (com.netflix.conductor.common.run.Workflow)12 WorkflowSummary (com.netflix.conductor.common.run.WorkflowSummary)9 Collections (java.util.Collections)5 SearchPb (com.netflix.conductor.grpc.SearchPb)4 WorkflowServicePb (com.netflix.conductor.grpc.WorkflowServicePb)4 ClientHandler (com.sun.jersey.api.client.ClientHandler)4 ClientResponse (com.sun.jersey.api.client.ClientResponse)4 GenericType (com.sun.jersey.api.client.GenericType)4 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)4 StreamObserver (io.grpc.stub.StreamObserver)4 URI (java.net.URI)4 LinkedList (java.util.LinkedList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 TestCase.assertEquals (junit.framework.TestCase.assertEquals)4 SearchResponse (org.elasticsearch.action.search.SearchResponse)4 Before (org.junit.Before)4 RunWith (org.junit.runner.RunWith)4