Search in sources :

Example 1 with IndexingResult

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

the class ProjectMeasuresIndexer method index.

@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
    if (items.isEmpty()) {
        return new IndexingResult();
    }
    OneToOneResilientIndexingListener listener = new OneToOneResilientIndexingListener(dbClient, dbSession, items);
    BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
    bulkIndexer.start();
    List<String> projectUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toArrayList(items.size()));
    Iterator<String> it = projectUuids.iterator();
    while (it.hasNext()) {
        String projectUuid = it.next();
        try (ProjectMeasuresIndexerIterator rowIt = ProjectMeasuresIndexerIterator.create(dbSession, projectUuid)) {
            while (rowIt.hasNext()) {
                bulkIndexer.add(toProjectMeasuresDoc(rowIt.next()).toIndexRequest());
                it.remove();
            }
        }
    }
    // the remaining uuids reference projects that don't exist in db. They must be deleted from index.
    projectUuids.forEach(projectUuid -> bulkIndexer.addDeletion(TYPE_PROJECT_MEASURES, projectUuid, AuthorizationDoc.idOf(projectUuid)));
    return bulkIndexer.stop();
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) ProjectMeasuresIndexerIterator(org.sonar.db.measure.ProjectMeasuresIndexerIterator) BulkIndexer(org.sonar.server.es.BulkIndexer) OneToOneResilientIndexingListener(org.sonar.server.es.OneToOneResilientIndexingListener)

Example 2 with IndexingResult

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

the class ComponentIndexerTest method errors_during_indexing_are_recovered.

@Test
public void errors_during_indexing_are_recovered() {
    ComponentDto project1 = db.components().insertPrivateProject();
    es.lockWrites(TYPE_COMPONENT);
    IndexingResult result = indexProject(project1, PROJECT_CREATION);
    assertThat(result.getTotal()).isOne();
    assertThat(result.getFailures()).isOne();
    // index is still read-only, fail to recover
    result = recover();
    assertThat(result.getTotal()).isOne();
    assertThat(result.getFailures()).isOne();
    assertThat(es.countDocuments(TYPE_COMPONENT)).isZero();
    es.unlockWrites(TYPE_COMPONENT);
    result = recover();
    assertThat(result.getTotal()).isOne();
    assertThat(result.getFailures()).isZero();
    assertThatIndexContainsOnly(project1);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 3 with IndexingResult

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

the class ComponentIndexerTest method update_index_on_project_creation.

@Test
public void update_index_on_project_creation() {
    ComponentDto project = db.components().insertPrivateProject();
    IndexingResult result = indexProject(project, PROJECT_CREATION);
    assertThatIndexContainsOnly(project);
    assertThat(result.getTotal()).isOne();
    assertThat(result.getSuccess()).isOne();
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test)

Example 4 with IndexingResult

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

the class IssueIndexerTest method index_is_updated_when_deleting_project.

@Test
public void index_is_updated_when_deleting_project() {
    addIssueToIndex("P1", "I1");
    assertThatIndexHasSize(1);
    IndexingResult result = indexProject("P1", ProjectIndexer.Cause.PROJECT_DELETION);
    assertThat(result.getTotal()).isOne();
    assertThat(result.getSuccess()).isOne();
    assertThatIndexHasSize(0);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) Test(org.junit.Test)

Example 5 with IndexingResult

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

the class IssueIndexerTest method index_is_not_updated_when_updating_tags.

@Test
public void index_is_not_updated_when_updating_tags() {
    // issue is inserted to verify that indexing of project is not triggered
    IssueDto issue = db.issues().insert();
    IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_TAGS_UPDATE);
    assertThat(result.getTotal()).isZero();
    assertThatIndexHasSize(0);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Aggregations

IndexingResult (org.sonar.server.es.IndexingResult)26 Test (org.junit.Test)15 ComponentDto (org.sonar.db.component.ComponentDto)11 BulkIndexer (org.sonar.server.es.BulkIndexer)8 OneToOneResilientIndexingListener (org.sonar.server.es.OneToOneResilientIndexingListener)6 EsQueueDto (org.sonar.db.es.EsQueueDto)5 IssueDto (org.sonar.db.issue.IssueDto)5 OneToManyResilientIndexingListener (org.sonar.server.es.OneToManyResilientIndexingListener)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)2 IndexingListener (org.sonar.server.es.IndexingListener)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Objects (java.util.Objects)1