use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.
the class ProjectMeasuresIndexerTest method update_index_when_project_is_created.
@Test
public void update_index_when_project_is_created() {
ComponentDto project = db.components().insertPrivateProject();
IndexingResult result = indexProject(project, PROJECT_CREATION);
assertThatIndexContainsOnly(project);
assertThat(result.getTotal()).isOne();
assertThat(result.getSuccess()).isOne();
}
use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.
the class ProjectMeasuresIndexerTest method delete_doc_from_index_when_project_is_deleted.
@Test
public void delete_doc_from_index_when_project_is_deleted() {
ComponentDto project = db.components().insertPrivateProject();
indexProject(project, PROJECT_CREATION);
assertThatIndexContainsOnly(project);
db.getDbClient().purgeDao().deleteProject(db.getSession(), project.uuid(), Qualifiers.PROJECT, project.name(), project.getKey());
IndexingResult result = indexProject(project, PROJECT_DELETION);
assertThat(es.countDocuments(TYPE_PROJECT_MEASURES)).isZero();
assertThat(result.getTotal()).isOne();
assertThat(result.getSuccess()).isOne();
}
use of org.sonar.server.es.IndexingResult in project sonarqube by SonarSource.
the class ProjectMeasuresIndexerTest method errors_during_indexing_are_recovered.
@Test
public void errors_during_indexing_are_recovered() {
ComponentDto project = db.components().insertPrivateProject();
es.lockWrites(TYPE_PROJECT_MEASURES);
IndexingResult result = indexProject(project, 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_PROJECT_MEASURES)).isZero();
assertThatEsQueueTableHasSize(1);
es.unlockWrites(TYPE_PROJECT_MEASURES);
result = recover();
assertThat(result.getTotal()).isOne();
assertThat(result.getFailures()).isZero();
assertThatEsQueueTableHasSize(0);
assertThatIndexContainsOnly(project);
}
use of org.sonar.server.es.IndexingResult 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.server.es.IndexingResult in project sonarqube by SonarSource.
the class ComponentIndexer method index.
@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
if (items.isEmpty()) {
return new IndexingResult();
}
OneToManyResilientIndexingListener listener = new OneToManyResilientIndexingListener(dbClient, dbSession, items);
BulkIndexer bulkIndexer = new BulkIndexer(esClient, TYPE_COMPONENT, Size.REGULAR, listener);
bulkIndexer.start();
Set<String> branchUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toHashSet(items.size()));
Set<String> remaining = new HashSet<>(branchUuids);
for (String branchUuid : branchUuids) {
// TODO allow scrolling multiple projects at the same time
dbClient.componentDao().scrollForIndexing(dbSession, branchUuid, context -> {
ComponentDto dto = context.getResultObject();
bulkIndexer.add(toDocument(dto).toIndexRequest());
remaining.remove(dto.projectUuid());
});
}
// the remaining uuids reference projects that don't exist in db. They must
// be deleted from index.
remaining.forEach(projectUuid -> addProjectDeletionToBulkIndexer(bulkIndexer, projectUuid));
return bulkIndexer.stop();
}
Aggregations