Search in sources :

Example 6 with EsQueueDto

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

the class ProjectMeasuresIndexerTest 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 7 with EsQueueDto

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

the class ActiveRuleIndexerTest method commitAndIndex_keeps_elements_to_recover_in_ES_QUEUE_on_errors.

@Test
public void commitAndIndex_keeps_elements_to_recover_in_ES_QUEUE_on_errors() {
    ActiveRuleDto ar = db.qualityProfiles().activateRule(profile1, rule1);
    es.lockWrites(TYPE_ACTIVE_RULE);
    commitAndIndex(rule1, ar);
    EsQueueDto expectedItem = EsQueueDto.create(TYPE_ACTIVE_RULE.format(), "ar_" + ar.getUuid(), "activeRuleUuid", ar.getRuleUuid());
    assertThatEsQueueContainsExactly(expectedItem);
    es.unlockWrites(TYPE_ACTIVE_RULE);
}
Also used : EsQueueDto(org.sonar.db.es.EsQueueDto) ActiveRuleDto(org.sonar.db.qualityprofile.ActiveRuleDto) Test(org.junit.Test)

Example 8 with EsQueueDto

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

the class ActiveRuleIndexerTest method index_fails_and_deletes_doc_if_docIdType_is_unsupported.

@Test
public void index_fails_and_deletes_doc_if_docIdType_is_unsupported() {
    EsQueueDto item = EsQueueDto.create(TYPE_ACTIVE_RULE.format(), "the_id", "unsupported", "the_routing");
    db.getDbClient().esQueueDao().insert(db.getSession(), item);
    underTest.index(db.getSession(), singletonList(item));
    assertThatEsQueueTableIsEmpty();
    assertThat(es.countDocuments(TYPE_ACTIVE_RULE)).isZero();
}
Also used : EsQueueDto(org.sonar.db.es.EsQueueDto) Test(org.junit.Test)

Example 9 with EsQueueDto

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

the class PermissionIndexer method index.

@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
    IndexingResult result = new IndexingResult();
    List<BulkIndexer> bulkIndexers = items.stream().map(EsQueueDto::getDocType).distinct().map(indexTypeByFormat::get).filter(Objects::nonNull).map(indexType -> new BulkIndexer(esClient, indexType, Size.REGULAR, new OneToOneResilientIndexingListener(dbClient, dbSession, items))).collect(Collectors.toList());
    if (bulkIndexers.isEmpty()) {
        return result;
    }
    bulkIndexers.forEach(BulkIndexer::start);
    PermissionIndexerDao permissionIndexerDao = new PermissionIndexerDao();
    Set<String> remainingProjectUuids = items.stream().map(EsQueueDto::getDocId).map(AuthorizationDoc::projectUuidOf).collect(MoreCollectors.toHashSet());
    permissionIndexerDao.selectByUuids(dbClient, dbSession, remainingProjectUuids).forEach(p -> {
        remainingProjectUuids.remove(p.getProjectUuid());
        bulkIndexers.forEach(bi -> bi.add(AuthorizationDoc.fromDto(bi.getIndexType(), p).toIndexRequest()));
    });
    // the remaining references on projects that don't exist in db. They must
    // be deleted from index.
    remainingProjectUuids.forEach(projectUuid -> bulkIndexers.forEach(bi -> {
        String authorizationDocId = AuthorizationDoc.idOf(projectUuid);
        bi.addDeletion(bi.getIndexType(), authorizationDocId, authorizationDocId);
    }));
    bulkIndexers.forEach(b -> result.add(b.stop()));
    return result;
}
Also used : Arrays(java.util.Arrays) ImmutableSet(com.google.common.collect.ImmutableSet) EsQueueDto(org.sonar.db.es.EsQueueDto) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) Set(java.util.Set) Autowired(org.springframework.beans.factory.annotation.Autowired) BulkIndexer(org.sonar.server.es.BulkIndexer) Collectors(java.util.stream.Collectors) DbSession(org.sonar.db.DbSession) EsClient(org.sonar.server.es.EsClient) Objects(java.util.Objects) OneToOneResilientIndexingListener(org.sonar.server.es.OneToOneResilientIndexingListener) DbClient(org.sonar.db.DbClient) List(java.util.List) Stream(java.util.stream.Stream) MoreCollectors.toArrayList(org.sonar.core.util.stream.MoreCollectors.toArrayList) IndexingResult(org.sonar.server.es.IndexingResult) Map(java.util.Map) Size(org.sonar.server.es.BulkIndexer.Size) ProjectIndexer(org.sonar.server.es.ProjectIndexer) VisibleForTesting(com.google.common.annotations.VisibleForTesting) MoreCollectors(org.sonar.core.util.stream.MoreCollectors) IndexType(org.sonar.server.es.IndexType) IndexingResult(org.sonar.server.es.IndexingResult) EsQueueDto(org.sonar.db.es.EsQueueDto) Objects(java.util.Objects) BulkIndexer(org.sonar.server.es.BulkIndexer) OneToOneResilientIndexingListener(org.sonar.server.es.OneToOneResilientIndexingListener)

Example 10 with EsQueueDto

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

the class RecoveryIndexerTest method recover_multiple_times_the_same_document.

@Test
public void recover_multiple_times_the_same_document() {
    EsQueueDto item1 = insertItem(FOO_TYPE, "f1");
    EsQueueDto item2 = insertItem(FOO_TYPE, item1.getDocId());
    EsQueueDto item3 = insertItem(FOO_TYPE, item1.getDocId());
    advanceInTime();
    SuccessfulFakeIndexer indexer = new SuccessfulFakeIndexer(FOO_TYPE);
    underTest = newRecoveryIndexer(indexer);
    underTest.recover();
    assertThatQueueHasSize(0);
    assertThat(indexer.called).hasSize(1);
    assertThat(indexer.called.get(0)).extracting(EsQueueDto::getUuid).containsExactlyInAnyOrder(item1.getUuid(), item2.getUuid(), item3.getUuid());
    assertThatLogsContain(TRACE, "Elasticsearch recovery - processing 3 [foos/foo]");
    assertThatLogsContain(INFO, "Elasticsearch recovery - 3 documents processed [0 failures]");
}
Also used : EsQueueDto(org.sonar.db.es.EsQueueDto) Test(org.junit.Test)

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