use of com.lambdista.util.Try in project hopsworks by logicalclocks.
the class LibraryController method pipList.
/**
* @param <R> parsed elastic item
* @param <S1> intermediate result wrapped in Try
* @param <S2> final result
* @return
* @throws ProvenanceException
*/
private <R, S1, S2> S2 pipList(String query, Integer offset, Integer limit, LibraryController.HandlerFactory<R, S1, S2> handlerFactory, String index) throws ServiceException {
Pair<Long, Try<S1>> searchResult;
try {
CheckedSupplier<SearchRequest, ProvenanceException> srF = ElasticHelper.baseSearchRequest(index, settings.getElasticDefaultScrollPageSize()).andThen(ElasticHelper.withPagination(offset, limit, settings.getElasticDefaultScrollPageSize()));
SearchRequest request = srF.get();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.query(ElasticHelper.fullTextSearch("library", query));
request.source(sourceBuilder);
searchResult = provElasticController.search(request, handlerFactory.getHandler());
} catch (ElasticException | ProvenanceException pe) {
throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_LIST_LIB_ERROR, Level.FINE, "Unable to list python libraries", pe.getMessage(), pe);
}
return handlerFactory.checkedResult(searchResult);
}
use of com.lambdista.util.Try in project hopsworks by logicalclocks.
the class ProvAppController method provAppState.
public Map<String, Map<Provenance.AppState, ProvAppStateElastic>> provAppState(Map<ProvParser.Field, ProvParser.FilterVal> filterBy, List<Pair<ProvParser.Field, SortOrder>> sortBy, Integer offset, Integer limit) throws ProvenanceException {
CheckedSupplier<SearchRequest, ProvenanceException> srF = ElasticHelper.scrollingSearchRequest(Settings.ELASTIC_INDEX_APP_PROVENANCE, settings.getElasticDefaultScrollPageSize()).andThen(provAppStateQB(filterBy)).andThen(ElasticHelper.sortBy(sortBy)).andThen(ElasticHelper.withPagination(offset, limit, settings.getElasticMaxScrollPageSize()));
SearchRequest request = srF.get();
Pair<Long, Try<ElasticAppStatesObj>> searchResult;
try {
searchResult = client.searchScrolling(request, ElasticAppStatesObj.getHandler());
} catch (ElasticException e) {
String msg = "provenance - elastic query problem";
throw ProvHelper.fromElastic(e, msg, msg + " - app state");
}
return ElasticAppStatesObj.checkedResult(searchResult);
}
use of com.lambdista.util.Try in project hopsworks by logicalclocks.
the class ProvStateController method provFileState.
/**
* @param <R> parsed elastic item
* @param <S1> intermediate result wrapped in Try
* @param <S2> final result
* @return
* @throws ProvenanceException
*/
private <R, S1, S2> S2 provFileState(Long projectIId, Map<ProvParser.Field, ProvParser.FilterVal> fileStateFilters, List<Pair<ProvParser.Field, SortOrder>> fileStateSortBy, Map<String, String> xAttrsFilters, Map<String, String> likeXAttrsFilters, Set<String> hasXAttrsFilters, List<ProvStateParamBuilder.SortE> xattrSortBy, Integer offset, Integer limit, HandlerFactory<R, S1, S2> handlerFactory) throws ProvenanceException {
CheckedSupplier<SearchRequest, ProvenanceException> srF = ElasticHelper.baseSearchRequest(settings.getProvFileIndex(projectIId), settings.getElasticDefaultScrollPageSize()).andThen(filterByStateParams(fileStateFilters, xAttrsFilters, likeXAttrsFilters, hasXAttrsFilters)).andThen(ElasticHelper.withFileStateOrder(fileStateSortBy, xattrSortBy)).andThen(ElasticHelper.withPagination(offset, limit, settings.getElasticMaxScrollPageSize()));
SearchRequest request = srF.get();
Pair<Long, Try<S1>> searchResult;
try {
searchResult = client.search(request, handlerFactory.getHandler());
} catch (ElasticException e) {
String msg = "provenance - elastic query problem";
throw ProvHelper.fromElastic(e, msg, msg + " - file state");
}
return handlerFactory.checkedResult(searchResult);
}
use of com.lambdista.util.Try in project hopsworks by logicalclocks.
the class TestElasticClientController method testScrollingHasLeftoverWithScrollId.
@Test
public void testScrollingHasLeftoverWithScrollId() throws ElasticException {
// arrange
int totalHits = 2;
SearchRequest request = new SearchRequest();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.size(totalHits);
request.source(sourceBuilder);
SearchResponse response = createResponse(new SearchHit[] { createHit }, totalHits, "");
// region Mock
Mockito.doReturn(null).when(client).baseSearch(Mockito.any());
Mockito.doReturn(createResponse(new SearchHit[] { readHit }, totalHits, "")).when(client).searchScrollingInt(Mockito.any());
Mockito.doReturn(null).when(client).clearScrollingContext(Mockito.any());
// endregion
// act
Pair<Long, Try<Object>> result = client.scrolling(response, handler, request);
// assert
Assert.assertEquals(2, result.getValue0().intValue());
Mockito.verify(client, Mockito.times(0)).baseSearch(Mockito.any());
Mockito.verify(client, Mockito.times(1)).searchScrollingInt(Mockito.any());
Mockito.verify(client, Mockito.times(1)).clearScrollingContext(Mockito.any());
}
use of com.lambdista.util.Try in project hopsworks by logicalclocks.
the class TestElasticClientController method testScrollingWithScrollId.
@Test
public void testScrollingWithScrollId() throws ElasticException {
// arrange
int totalHits = 1;
SearchRequest request = new SearchRequest();
SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
sourceBuilder.size(totalHits);
request.source(sourceBuilder);
SearchResponse response = createResponse(new SearchHit[] { createHit }, totalHits, "");
// region Mock
Mockito.doReturn(null).when(client).baseSearch(Mockito.any());
Mockito.doReturn(null).when(client).searchScrollingInt(Mockito.any());
Mockito.doReturn(null).when(client).clearScrollingContext(Mockito.any());
// endregion
// act
Pair<Long, Try<Object>> result = client.scrolling(response, handler, request);
// assert
Assert.assertEquals(1, result.getValue0().intValue());
Mockito.verify(client, Mockito.times(0)).baseSearch(Mockito.any());
Mockito.verify(client, Mockito.times(0)).searchScrollingInt(Mockito.any());
Mockito.verify(client, Mockito.times(1)).clearScrollingContext(Mockito.any());
}
Aggregations