Search in sources :

Example 1 with ProjectMeasuresIndexerIterator

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator in project sonarqube by SonarSource.

the class ProjectMeasuresIndexer method index.

@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
    if (items.isEmpty()) {
        return new IndexingResult();
    }
    OneToOneResilientIndexingListener listener = new OneToOneResilientIndexingListener(dbClient, dbSession, items);
    BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
    bulkIndexer.start();
    List<String> projectUuids = items.stream().map(EsQueueDto::getDocId).collect(MoreCollectors.toArrayList(items.size()));
    Iterator<String> it = projectUuids.iterator();
    while (it.hasNext()) {
        String projectUuid = it.next();
        try (ProjectMeasuresIndexerIterator rowIt = ProjectMeasuresIndexerIterator.create(dbSession, projectUuid)) {
            while (rowIt.hasNext()) {
                bulkIndexer.add(toProjectMeasuresDoc(rowIt.next()).toIndexRequest());
                it.remove();
            }
        }
    }
    // the remaining uuids reference projects that don't exist in db. They must be deleted from index.
    projectUuids.forEach(projectUuid -> bulkIndexer.addDeletion(TYPE_PROJECT_MEASURES, projectUuid, AuthorizationDoc.idOf(projectUuid)));
    return bulkIndexer.stop();
}
Also used : IndexingResult(org.sonar.server.es.IndexingResult) ProjectMeasuresIndexerIterator(org.sonar.db.measure.ProjectMeasuresIndexerIterator) BulkIndexer(org.sonar.server.es.BulkIndexer) OneToOneResilientIndexingListener(org.sonar.server.es.OneToOneResilientIndexingListener)

Example 2 with ProjectMeasuresIndexerIterator

use of org.sonar.db.measure.ProjectMeasuresIndexerIterator in project sonarqube by SonarSource.

the class ProjectMeasuresIndexer method doIndex.

private void doIndex(Size size, @Nullable String projectUuid) {
    try (DbSession dbSession = dbClient.openSession(false);
        ProjectMeasuresIndexerIterator rowIt = ProjectMeasuresIndexerIterator.create(dbSession, projectUuid)) {
        BulkIndexer bulkIndexer = createBulkIndexer(size, IndexingListener.FAIL_ON_ERROR);
        bulkIndexer.start();
        while (rowIt.hasNext()) {
            ProjectMeasures doc = rowIt.next();
            bulkIndexer.add(toProjectMeasuresDoc(doc).toIndexRequest());
        }
        bulkIndexer.stop();
    }
}
Also used : DbSession(org.sonar.db.DbSession) ProjectMeasures(org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures) ProjectMeasuresIndexerIterator(org.sonar.db.measure.ProjectMeasuresIndexerIterator) BulkIndexer(org.sonar.server.es.BulkIndexer)

Aggregations

ProjectMeasuresIndexerIterator (org.sonar.db.measure.ProjectMeasuresIndexerIterator)2 BulkIndexer (org.sonar.server.es.BulkIndexer)2 DbSession (org.sonar.db.DbSession)1 ProjectMeasures (org.sonar.db.measure.ProjectMeasuresIndexerIterator.ProjectMeasures)1 IndexingResult (org.sonar.server.es.IndexingResult)1 OneToOneResilientIndexingListener (org.sonar.server.es.OneToOneResilientIndexingListener)1