Search in sources :

Example 1 with IndexType

use of org.sonar.server.es.IndexType in project sonarqube by SonarSource.

the class ProxyIndexRequestBuilderTest method fail_if_bad_query.

@Test
public void fail_if_bad_query() {
    IndexRequestBuilder requestBuilder = esTester.client().prepareIndex(new IndexType("unknownIndex", "unknownType"));
    try {
        requestBuilder.get();
        fail();
    } catch (Exception e) {
        assertThat(e).isInstanceOf(IllegalStateException.class);
        assertThat(e.getMessage()).contains("Fail to execute ES index request for key 'null' on index 'unknownIndex' on type 'unknownType'");
    }
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) IndexType(org.sonar.server.es.IndexType) Test(org.junit.Test)

Example 2 with IndexType

use of org.sonar.server.es.IndexType in project sonarqube by SonarSource.

the class PermissionIndexer method index.

private void index(Collection<PermissionIndexerDao.Dto> authorizations, AuthorizationScope scope, Size bulkSize) {
    IndexType indexType = scope.getIndexType();
    BulkIndexer bulkIndexer = new BulkIndexer(esClient, indexType.getIndex());
    bulkIndexer.setSize(bulkSize);
    bulkIndexer.start();
    authorizations.stream().filter(scope.getProjectPredicate()).map(dto -> newIndexRequest(dto, indexType)).forEach(bulkIndexer::add);
    bulkIndexer.stop();
}
Also used : Arrays(java.util.Arrays) Collection(java.util.Collection) Set(java.util.Set) Collectors(org.sonar.core.util.stream.Collectors) HashMap(java.util.HashMap) Collectors.toSet(org.sonar.core.util.stream.Collectors.toSet) BulkIndexer(org.sonar.server.es.BulkIndexer) DbSession(org.sonar.db.DbSession) EsClient(org.sonar.server.es.EsClient) DbClient(org.sonar.db.DbClient) List(java.util.List) IndexRequest(org.elasticsearch.action.index.IndexRequest) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Stream(java.util.stream.Stream) DateUtils(org.sonar.api.utils.DateUtils) Dto(org.sonar.server.permission.index.PermissionIndexerDao.Dto) Map(java.util.Map) Size(org.sonar.server.es.BulkIndexer.Size) ProjectIndexer(org.sonar.server.es.ProjectIndexer) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StartupIndexer(org.sonar.server.es.StartupIndexer) IndexType(org.sonar.server.es.IndexType) IndexType(org.sonar.server.es.IndexType) BulkIndexer(org.sonar.server.es.BulkIndexer)

Example 3 with IndexType

use of org.sonar.server.es.IndexType in project sonarqube by SonarSource.

the class ProxyIndexRequestBuilderTest method fail_if_bad_query_with_basic_profiling.

@Test
public void fail_if_bad_query_with_basic_profiling() {
    IndexRequestBuilder requestBuilder = esTester.client().prepareIndex(new IndexType("unknownIndex", "unknownType"));
    try {
        requestBuilder.get();
        fail();
    } catch (Exception e) {
        assertThat(e).isInstanceOf(IllegalStateException.class);
        assertThat(e.getMessage()).contains("Fail to execute ES index request for key 'null' on index 'unknownIndex' on type 'unknownType'");
    }
}
Also used : IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) IndexType(org.sonar.server.es.IndexType) Test(org.junit.Test)

Aggregations

IndexType (org.sonar.server.es.IndexType)3 IndexRequestBuilder (org.elasticsearch.action.index.IndexRequestBuilder)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Stream (java.util.stream.Stream)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1 DateUtils (org.sonar.api.utils.DateUtils)1 Collectors (org.sonar.core.util.stream.Collectors)1 Collectors.toSet (org.sonar.core.util.stream.Collectors.toSet)1 DbClient (org.sonar.db.DbClient)1 DbSession (org.sonar.db.DbSession)1 BulkIndexer (org.sonar.server.es.BulkIndexer)1 Size (org.sonar.server.es.BulkIndexer.Size)1