Search in sources :

Example 6 with UnknownIndexException

use of org.molgenis.data.index.exception.UnknownIndexException in project molgenis by molgenis.

the class IndexedRepositoryDecoratorTest method aggregateUnknownIndexExceptionUnrecoverable.

@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "Error executing query, index for entity type 'My entity type' with id 'entity' does not exist")
public void aggregateUnknownIndexExceptionUnrecoverable() {
    AggregateQuery aggregateQuery = mock(AggregateQuery.class);
    when(searchService.aggregate(repositoryEntityType, aggregateQuery)).thenThrow(new UnknownIndexException("msg"));
    indexedRepositoryDecorator.aggregate(aggregateQuery);
}
Also used : UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) Test(org.testng.annotations.Test)

Example 7 with UnknownIndexException

use of org.molgenis.data.index.exception.UnknownIndexException in project molgenis by molgenis.

the class IndexedRepositoryDecoratorTest method aggregateUnknownIndexExceptionRecoverable.

@Test
public void aggregateUnknownIndexExceptionRecoverable() {
    AggregateQuery aggregateQuery = mock(AggregateQuery.class);
    AggregateResult aggregateResult = mock(AggregateResult.class);
    when(searchService.aggregate(repositoryEntityType, aggregateQuery)).thenThrow(new UnknownIndexException("msg")).thenReturn(aggregateResult);
    assertEquals(indexedRepositoryDecorator.aggregate(aggregateQuery), aggregateResult);
    verify(delegateRepository, never()).count(unsupportedQuery);
}
Also used : AggregateResult(org.molgenis.data.aggregation.AggregateResult) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) AggregateQuery(org.molgenis.data.aggregation.AggregateQuery) Test(org.testng.annotations.Test)

Example 8 with UnknownIndexException

use of org.molgenis.data.index.exception.UnknownIndexException in project molgenis by molgenis.

the class IndexedRepositoryDecoratorTest method findAllUnknownIndexExceptionUnrecoverable.

@Test(expectedExceptions = MolgenisDataException.class, expectedExceptionsMessageRegExp = "Error executing query, index for entity type 'My entity type' with id 'entity' does not exist")
public void findAllUnknownIndexExceptionUnrecoverable() {
    when(searchService.search(repositoryEntityType, unsupportedQuery)).thenThrow(new UnknownIndexException("msg"));
    indexedRepositoryDecorator.findAll(unsupportedQuery);
}
Also used : UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) Test(org.testng.annotations.Test)

Example 9 with UnknownIndexException

use of org.molgenis.data.index.exception.UnknownIndexException in project molgenis by molgenis.

the class ClientFacade method deleteIndexes.

private void deleteIndexes(List<Index> indexes) {
    if (LOG.isTraceEnabled()) {
        LOG.trace("Deleting index(es) '{}' ...", toString(indexes));
    }
    String[] indexNames = toIndexNames(indexes);
    DeleteIndexRequestBuilder deleteIndexRequest = client.admin().indices().prepareDelete(indexNames);
    DeleteIndexResponse deleteIndexResponse;
    try {
        deleteIndexResponse = deleteIndexRequest.get();
    } catch (ResourceNotFoundException e) {
        LOG.debug("", e);
        throw new UnknownIndexException(toString(indexes));
    } catch (ElasticsearchException e) {
        LOG.error("", e);
        throw new IndexException(format("Error deleting index(es) '%s'.", toString(indexes)));
    }
    if (!deleteIndexResponse.isAcknowledged()) {
        throw new IndexException(format("Error deleting index(es) '%s'.", toString(indexes)));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Deleted index(es) '{}'.", toString(indexes));
    }
}
Also used : DeleteIndexResponse(org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse) IndexException(org.molgenis.data.index.exception.IndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) DeleteIndexRequestBuilder(org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder) ElasticsearchException(org.elasticsearch.ElasticsearchException) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException)

Example 10 with UnknownIndexException

use of org.molgenis.data.index.exception.UnknownIndexException in project molgenis by molgenis.

the class ClientFacade method search.

private SearchHits search(QueryBuilder query, int from, int size, Sort sort, List<Index> indexes) {
    if (size > 10000) {
        throw new MolgenisQueryException(String.format("Batch size of %s exceeds the maximum batch size of %s for search queries", size, MAX_BATCH_SIZE));
    }
    if (LOG.isTraceEnabled()) {
        if (sort != null) {
            LOG.trace("Searching docs [{}-{}] in index(es) '{}' with query '{}' sorted by '{}' ...", from, from + size, toString(indexes), query, sort);
        } else {
            LOG.trace("Searching docs [{}-{}] in index(es) '{}' with query '{}' ...", from, from + size, toString(indexes), query);
        }
    }
    SearchRequestBuilder searchRequest = createSearchRequest(query, from, size, sort, null, indexes);
    SearchResponse searchResponse;
    try {
        searchResponse = searchRequest.get();
    } catch (ResourceNotFoundException e) {
        LOG.error("", e);
        throw new UnknownIndexException(toIndexNames(indexes));
    } catch (ElasticsearchException e) {
        LOG.error("", e);
        throw new IndexException(format("Error searching docs in index(es) '%s' with query '%s'.", toString(indexes), query));
    }
    if (searchResponse.getFailedShards() > 0) {
        LOG.error(stream(searchResponse.getShardFailures()).map(ShardSearchFailure::toString).collect(joining("\n")));
        throw new IndexException(format("Error searching docs in index(es) '%s' with query '%s'.", toString(indexes), query));
    }
    if (searchResponse.isTimedOut()) {
        throw new IndexException(format("Timeout searching counting docs in index(es) '%s'  with query '%s'.", toString(indexes), query));
    }
    if (LOG.isDebugEnabled()) {
        if (sort != null) {
            LOG.debug("Searched {} docs in index(es) '{}' with query '{}' sorted by '{}' in {}ms.", searchResponse.getHits().getTotalHits(), toString(indexes), query, sort, searchResponse.getTookInMillis());
        } else {
            LOG.debug("Searched {} docs in index(es) '{}' with query '{}' in {}ms.", searchResponse.getHits().getTotalHits(), toString(indexes), query, searchResponse.getTookInMillis());
        }
    }
    return createSearchResponse(searchResponse);
}
Also used : MolgenisQueryException(org.molgenis.data.MolgenisQueryException) SearchRequestBuilder(org.elasticsearch.action.search.SearchRequestBuilder) IndexException(org.molgenis.data.index.exception.IndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) UnknownIndexException(org.molgenis.data.index.exception.UnknownIndexException) ElasticsearchException(org.elasticsearch.ElasticsearchException) ShardSearchFailure(org.elasticsearch.action.search.ShardSearchFailure) ResourceNotFoundException(org.elasticsearch.ResourceNotFoundException) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Aggregations

UnknownIndexException (org.molgenis.data.index.exception.UnknownIndexException)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)7 ResourceNotFoundException (org.elasticsearch.ResourceNotFoundException)7 IndexException (org.molgenis.data.index.exception.IndexException)7 Test (org.testng.annotations.Test)5 ShardSearchFailure (org.elasticsearch.action.search.ShardSearchFailure)4 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)3 SearchResponse (org.elasticsearch.action.search.SearchResponse)3 DeleteIndexRequestBuilder (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequestBuilder)2 DeleteIndexResponse (org.elasticsearch.action.admin.indices.delete.DeleteIndexResponse)2 AggregateQuery (org.molgenis.data.aggregation.AggregateQuery)2 ShardOperationFailedException (org.elasticsearch.action.ShardOperationFailedException)1 CreateIndexRequestBuilder (org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder)1 CreateIndexResponse (org.elasticsearch.action.admin.indices.create.CreateIndexResponse)1 RefreshRequestBuilder (org.elasticsearch.action.admin.indices.refresh.RefreshRequestBuilder)1 RefreshResponse (org.elasticsearch.action.admin.indices.refresh.RefreshResponse)1 DeleteRequestBuilder (org.elasticsearch.action.delete.DeleteRequestBuilder)1 DeleteResponse (org.elasticsearch.action.delete.DeleteResponse)1 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1