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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations