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());
}
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);
}
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);
}
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));
}
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));
}
Aggregations