use of com.netflix.conductor.common.run.SearchResult 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());
}
use of com.netflix.conductor.common.run.SearchResult in project conductor by Netflix.
the class WorkflowServiceImplTest method searchV2Test.
@Test
public void searchV2Test() 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.searchWorkflowsV2(1, 1, Collections.singletonList("strings"), "*", "")).thenReturn(searchResult);
workflowServiceImpl.searchV2(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));
}
use of com.netflix.conductor.common.run.SearchResult 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));
}
use of com.netflix.conductor.common.run.SearchResult in project conductor by Netflix.
the class ElasticSearchRestDAOV5 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.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);
}
use of com.netflix.conductor.common.run.SearchResult in project conductor by Netflix.
the class ElasticSearchDAOV5 method search.
private SearchResult<String> search(String indexName, String structuredQuery, int start, int size, List<String> sortOptions, String freeTextQuery, String docType) {
try {
QueryBuilder queryBuilder = QueryBuilders.matchAllQuery();
if (StringUtils.isNotEmpty(structuredQuery)) {
Expression expression = Expression.fromString(structuredQuery);
queryBuilder = expression.getFilterBuilder();
}
BoolQueryBuilder filterQuery = QueryBuilders.boolQuery().must(queryBuilder);
QueryStringQueryBuilder stringQuery = QueryBuilders.queryStringQuery(freeTextQuery);
BoolQueryBuilder fq = QueryBuilders.boolQuery().must(stringQuery).must(filterQuery);
final SearchRequestBuilder srb = elasticSearchClient.prepareSearch(indexName).setQuery(fq).setTypes(docType).storedFields("_id").setFrom(start).setSize(size);
if (sortOptions != null) {
sortOptions.forEach(sortOption -> addSortOptionToSearchRequest(srb, sortOption));
}
SearchResponse response = srb.get();
LinkedList<String> result = StreamSupport.stream(response.getHits().spliterator(), false).map(SearchHit::getId).collect(Collectors.toCollection(LinkedList::new));
long count = response.getHits().getTotalHits();
return new SearchResult<>(count, result);
} catch (ParserException e) {
String errorMsg = String.format("Error performing search on index:%s with docType:%s", indexName, docType);
logger.error(errorMsg);
throw new ApplicationException(Code.BACKEND_ERROR, errorMsg, e);
}
}
Aggregations