Search in sources :

Example 21 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class ActiveRuleIndexer method doIndexActiveRules.

private IndexingResult doIndexActiveRules(DbSession dbSession, Map<String, EsQueueDto> activeRuleItems) {
    OneToOneResilientIndexingListener listener = new OneToOneResilientIndexingListener(dbClient, dbSession, activeRuleItems.values());
    BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
    bulkIndexer.start();
    Map<String, EsQueueDto> remaining = new HashMap<>(activeRuleItems);
    dbClient.activeRuleDao().scrollByUuidsForIndexing(dbSession, toActiveRuleUuids(activeRuleItems), i -> {
        remaining.remove(docIdOf(i.getUuid()));
        bulkIndexer.add(newIndexRequest(i));
    });
    // the remaining ids reference rows that don't exist in db. They must
    // be deleted from index.
    remaining.values().forEach(item -> bulkIndexer.addDeletion(TYPE_ACTIVE_RULE, item.getDocId(), item.getDocRouting()));
    return bulkIndexer.stop();
}
Also used : HashMap(java.util.HashMap) EsQueueDto(org.sonar.db.es.EsQueueDto) BulkIndexer(org.sonar.server.es.BulkIndexer) OneToOneResilientIndexingListener(org.sonar.server.es.OneToOneResilientIndexingListener)

Example 22 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class RuleIndexer method index.

@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
    IndexingResult result = new IndexingResult();
    if (!items.isEmpty()) {
        ListMultimap<String, EsQueueDto> itemsByType = groupItemsByIndexTypeFormat(items);
        doIndexRules(dbSession, itemsByType.get(TYPE_RULE.format())).ifPresent(result::add);
    }
    return result;
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) EsQueueDto(org.sonar.db.es.EsQueueDto)

Example 23 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class ComponentIndexerTest method indexProject.

private IndexingResult indexProject(ComponentDto project, ProjectIndexer.Cause cause) {
    DbSession dbSession = db.getSession();
    Collection<EsQueueDto> items = underTest.prepareForRecovery(dbSession, singletonList(project.uuid()), cause);
    dbSession.commit();
    return underTest.index(dbSession, items);
}
Also used : DbSession(org.sonar.db.DbSession) EsQueueDto(org.sonar.db.es.EsQueueDto)

Example 24 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class OneToOneResilientIndexingListenerTest method insertInQueue.

private EsQueueDto insertInQueue(IndexType indexType, String id) {
    EsQueueDto item = EsQueueDto.create(indexType.format(), id);
    db.getDbClient().esQueueDao().insert(db.getSession(), singletonList(item));
    return item;
}
Also used : EsQueueDto(org.sonar.db.es.EsQueueDto)

Example 25 with EsQueueDto

use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.

the class RecoveryIndexerTest method insertItem.

private EsQueueDto insertItem(IndexType indexType, String docUuid) {
    EsQueueDto item = EsQueueDto.create(indexType.format(), docUuid);
    db.getDbClient().esQueueDao().insert(db.getSession(), item);
    db.commit();
    return item;
}
Also used : EsQueueDto(org.sonar.db.es.EsQueueDto)

Aggregations

EsQueueDto (org.sonar.db.es.EsQueueDto)26 Test (org.junit.Test)13 DbSession (org.sonar.db.DbSession)7 IndexingResult (org.sonar.server.es.IndexingResult)6 HashMap (java.util.HashMap)3 BulkIndexer (org.sonar.server.es.BulkIndexer)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections.emptyList (java.util.Collections.emptyList)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 ComponentDto (org.sonar.db.component.ComponentDto)2 OneToOneResilientIndexingListener (org.sonar.server.es.OneToOneResilientIndexingListener)2 ProjectIndexer (org.sonar.server.es.ProjectIndexer)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 Arrays.asList (java.util.Arrays.asList)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singletonList (java.util.Collections.singletonList)1