Search in sources :

Example 11 with BulkIndexer

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

the class ComponentIndexer method doIndexByProjectUuid.

/**
   * @param projectUuid the uuid of the project to analyze, or <code>null</code> if all content should be indexed.<br/>
   * <b>Warning:</b> only use <code>null</code> during startup.
   */
private void doIndexByProjectUuid(@Nullable String projectUuid, Size bulkSize) {
    BulkIndexer bulk = new BulkIndexer(esClient, INDEX_TYPE_COMPONENT.getIndex());
    bulk.setSize(bulkSize);
    bulk.start();
    try (DbSession dbSession = dbClient.openSession(false)) {
        dbClient.componentDao().selectForIndexing(dbSession, projectUuid, context -> {
            ComponentDto dto = (ComponentDto) context.getResultObject();
            bulk.add(newIndexRequest(toDocument(dto)));
        });
    }
    bulk.stop();
}
Also used : DbSession(org.sonar.db.DbSession) ComponentDto(org.sonar.db.component.ComponentDto) BulkIndexer(org.sonar.server.es.BulkIndexer)

Example 12 with BulkIndexer

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

the class ComponentIndexer method index.

void index(ComponentDto... docs) {
    BulkIndexer bulk = new BulkIndexer(esClient, INDEX_TYPE_COMPONENT.getIndex());
    bulk.setSize(Size.REGULAR);
    bulk.start();
    Arrays.stream(docs).map(ComponentIndexer::toDocument).map(ComponentIndexer::newIndexRequest).forEach(bulk::add);
    bulk.stop();
}
Also used : BulkIndexer(org.sonar.server.es.BulkIndexer)

Example 13 with BulkIndexer

use of org.sonar.server.es.BulkIndexer 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)

Aggregations

BulkIndexer (org.sonar.server.es.BulkIndexer)13 DbSession (org.sonar.db.DbSession)4 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)3 Map (java.util.Map)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Maps.newHashMap (com.google.common.collect.Maps.newHashMap)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)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 ComponentDto (org.sonar.db.component.ComponentDto)1 Size (org.sonar.server.es.BulkIndexer.Size)1