Search in sources :

Example 16 with IndexingResult

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

the class IssueIndexerTest method index_is_not_updated_when_creating_project.

@Test
public void index_is_not_updated_when_creating_project() {
    // it's impossible to already have an issue on a project
    // that is being created, but it's just to verify that
    // indexing is disabled
    IssueDto issue = db.issues().insert();
    IndexingResult result = indexProject(issue.getProjectUuid(), ProjectIndexer.Cause.PROJECT_CREATION);
    assertThat(result.getTotal()).isZero();
    assertThatIndexHasSize(0);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 17 with IndexingResult

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

the class IssueIndexerTest method indexing_recovers_multiple_errors_on_the_same_project.

@Test
public void indexing_recovers_multiple_errors_on_the_same_project() {
    RuleDefinitionDto rule = db.rules().insert();
    ComponentDto project = db.components().insertPrivateProject();
    ComponentDto file = db.components().insertComponent(newFileDto(project));
    IssueDto issue1 = db.issues().insert(rule, project, file);
    IssueDto issue2 = db.issues().insert(rule, project, file);
    es.lockWrites(TYPE_ISSUE);
    IndexingResult result = indexProject(project.uuid(), ProjectIndexer.Cause.PROJECT_DELETION);
    assertThat(result.getTotal()).isEqualTo(2L);
    assertThat(result.getFailures()).isEqualTo(2L);
    // index is still read-only, fail to recover
    result = recover();
    assertThat(result.getTotal()).isEqualTo(2L);
    assertThat(result.getFailures()).isEqualTo(2L);
    assertThatIndexHasSize(0);
    es.unlockWrites(TYPE_ISSUE);
    result = recover();
    assertThat(result.getTotal()).isEqualTo(2L);
    assertThat(result.getFailures()).isZero();
    assertThatIndexHasSize(2);
    assertThatEsQueueTableHasSize(0);
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) ComponentDto(org.sonar.db.component.ComponentDto) RuleDefinitionDto(org.sonar.db.rule.RuleDefinitionDto) IssueDto(org.sonar.db.issue.IssueDto) Test(org.junit.Test)

Example 18 with IndexingResult

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

the class ActiveRuleIndexer method doIndexRuleProfiles.

private IndexingResult doIndexRuleProfiles(DbSession dbSession, Map<String, EsQueueDto> ruleProfileItems) {
    IndexingResult result = new IndexingResult();
    for (Map.Entry<String, EsQueueDto> entry : ruleProfileItems.entrySet()) {
        String ruleProfileUUid = entry.getKey();
        EsQueueDto item = entry.getValue();
        IndexingResult profileResult;
        RulesProfileDto profile = dbClient.qualityProfileDao().selectRuleProfile(dbSession, ruleProfileUUid);
        if (profile == null) {
            // profile does not exist anymore in db --> related documents must be deleted from index rules/activeRule
            SearchRequest search = EsClient.prepareSearch(TYPE_ACTIVE_RULE.getMainType()).source(new SearchSourceBuilder().query(QueryBuilders.boolQuery().must(termQuery(FIELD_ACTIVE_RULE_PROFILE_UUID, ruleProfileUUid))));
            profileResult = BulkIndexer.delete(esClient, TYPE_ACTIVE_RULE, search);
        } else {
            BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, IndexingListener.FAIL_ON_ERROR);
            bulkIndexer.start();
            dbClient.activeRuleDao().scrollByRuleProfileForIndexing(dbSession, ruleProfileUUid, i -> bulkIndexer.add(newIndexRequest(i)));
            profileResult = bulkIndexer.stop();
        }
        if (profileResult.isSuccess()) {
            deleteQueueDto(dbSession, item);
        }
        result.add(profileResult);
    }
    return result;
}
Also used : SearchRequest(org.elasticsearch.action.search.SearchRequest) IndexingResult(org.sonar.server.es.IndexingResult) EsQueueDto(org.sonar.db.es.EsQueueDto) RulesProfileDto(org.sonar.db.qualityprofile.RulesProfileDto) HashMap(java.util.HashMap) Map(java.util.Map) BulkIndexer(org.sonar.server.es.BulkIndexer) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder)

Example 19 with IndexingResult

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

the class ActiveRuleIndexer method index.

/**
 * @return the number of items that have been successfully indexed
 */
@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
    IndexingResult result = new IndexingResult();
    if (items.isEmpty()) {
        return result;
    }
    Map<String, EsQueueDto> activeRuleItems = new HashMap<>();
    Map<String, EsQueueDto> ruleProfileItems = new HashMap<>();
    items.forEach(i -> {
        if (ID_TYPE_RULE_PROFILE_UUID.equals(i.getDocIdType())) {
            ruleProfileItems.put(i.getDocId(), i);
        } else if (ID_TYPE_ACTIVE_RULE_UUID.equals(i.getDocIdType())) {
            activeRuleItems.put(i.getDocId(), i);
        } else {
            LOGGER.error("Unsupported es_queue.doc_id_type. Removing row from queue: " + i);
            deleteQueueDto(dbSession, i);
        }
    });
    if (!activeRuleItems.isEmpty()) {
        result.add(doIndexActiveRules(dbSession, activeRuleItems));
    }
    if (!ruleProfileItems.isEmpty()) {
        result.add(doIndexRuleProfiles(dbSession, ruleProfileItems));
    }
    return result;
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) HashMap(java.util.HashMap) EsQueueDto(org.sonar.db.es.EsQueueDto)

Example 20 with IndexingResult

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

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