use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.
the class OneToManyResilientIndexingListenerTest 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;
}
use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.
the class OneToManyResilientIndexingListenerTest method ES_QUEUE_rows_are_deleted_when_all_docs_are_successfully_indexed.
@Test
public void ES_QUEUE_rows_are_deleted_when_all_docs_are_successfully_indexed() {
EsQueueDto item1 = insertInQueue(TYPE_ISSUE, "P1");
EsQueueDto item2 = insertInQueue(TYPE_ISSUE, "P2");
EsQueueDto outOfScopeItem = insertInQueue(ComponentIndexDefinition.TYPE_COMPONENT, "P1");
db.commit();
// does not contain outOfScopeItem
IndexingListener underTest = newListener(asList(item1, item2));
DocId issue1 = newDocId(TYPE_ISSUE, "I1");
DocId issue2 = newDocId(TYPE_ISSUE, "I2");
underTest.onSuccess(asList(issue1, issue2));
assertThatEsTableContainsOnly(item1, item2, outOfScopeItem);
// onFinish deletes all items
IndexingResult result = new IndexingResult();
result.incrementSuccess().incrementRequests();
result.incrementSuccess().incrementRequests();
underTest.onFinish(result);
assertThatEsTableContainsOnly(outOfScopeItem);
}
use of org.sonar.db.es.EsQueueDto in project sonarqube by SonarSource.
the class OneToOneResilientIndexingListenerTest method onSuccess_deletes_rows_from_ES_QUEUE_table.
@Test
public void onSuccess_deletes_rows_from_ES_QUEUE_table() {
EsQueueDto item1 = insertInQueue(TYPE_ISSUE, "foo");
EsQueueDto item2 = insertInQueue(TYPE_ISSUE, "bar");
EsQueueDto item3 = insertInQueue(TYPE_ISSUE, "baz");
db.commit();
IndexingListener underTest = newListener(asList(item1, item2, item3));
underTest.onSuccess(emptyList());
assertThatEsTableContainsOnly(item1, item2, item3);
underTest.onSuccess(asList(toDocId(item1), toDocId(item3)));
assertThatEsTableContainsOnly(item2);
// onFinish does nothing
underTest.onFinish(new IndexingResult());
assertThatEsTableContainsOnly(item2);
}
use of org.sonar.db.es.EsQueueDto 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.db.es.EsQueueDto 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;
}
Aggregations