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