use of org.sonar.server.es.OneToOneResilientIndexingListener 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();
}
use of org.sonar.server.es.OneToOneResilientIndexingListener in project sonarqube by SonarSource.
the class RuleIndexer method doIndexRules.
private Optional<IndexingResult> doIndexRules(DbSession dbSession, List<EsQueueDto> items) {
if (items.isEmpty()) {
return Optional.empty();
}
BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, new OneToOneResilientIndexingListener(dbClient, dbSession, items));
bulkIndexer.start();
Set<String> ruleUuids = items.stream().map(EsQueueDto::getDocId).collect(toHashSet(items.size()));
dbClient.ruleDao().scrollIndexingRulesByKeys(dbSession, ruleUuids, r -> {
bulkIndexer.add(ruleDocOf(r).toIndexRequest());
ruleUuids.remove(r.getUuid());
});
// the remaining items reference rows that don't exist in db. They must be deleted from index.
ruleUuids.forEach(ruleUuid -> bulkIndexer.addDeletion(TYPE_RULE, ruleUuid, ruleUuid));
return Optional.of(bulkIndexer.stop());
}
use of org.sonar.server.es.OneToOneResilientIndexingListener 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.OneToOneResilientIndexingListener in project sonarqube by SonarSource.
the class ActiveRuleIndexer method doIndexActiveRules.
private IndexingResult doIndexActiveRules(DbSession dbSession, Map<String, EsQueueDto> activeRuleItems) {
OneToOneResilientIndexingListener listener = new OneToOneResilientIndexingListener(dbClient, dbSession, activeRuleItems.values());
BulkIndexer bulkIndexer = createBulkIndexer(Size.REGULAR, listener);
bulkIndexer.start();
Map<String, EsQueueDto> remaining = new HashMap<>(activeRuleItems);
dbClient.activeRuleDao().scrollByUuidsForIndexing(dbSession, toActiveRuleUuids(activeRuleItems), i -> {
remaining.remove(docIdOf(i.getUuid()));
bulkIndexer.add(newIndexRequest(i));
});
// the remaining ids reference rows that don't exist in db. They must
// be deleted from index.
remaining.values().forEach(item -> bulkIndexer.addDeletion(TYPE_ACTIVE_RULE, item.getDocId(), item.getDocRouting()));
return bulkIndexer.stop();
}
use of org.sonar.server.es.OneToOneResilientIndexingListener in project sonarqube by SonarSource.
the class ViewIndexer method index.
/**
* This is based on the fact that a WebService is only calling {@link ViewIndexer#delete(DbSession, Collection)}
* So the resiliency is only taking in account a deletion of view component
* A safety check is done by not deleting any component that still exist in database.
*
* This should not occur but prevent any misuse on this resiliency
*/
@Override
public IndexingResult index(DbSession dbSession, Collection<EsQueueDto> items) {
if (items.isEmpty()) {
return new IndexingResult();
}
Set<String> views = items.stream().map(EsQueueDto::getDocId).collect(toHashSet(items.size()));
BulkIndexer bulkIndexer = newBulkIndexer(Size.REGULAR, new OneToOneResilientIndexingListener(dbClient, dbSession, items));
bulkIndexer.start();
// Safety check to remove all views that may not have been deleted
views.removeAll(dbClient.componentDao().selectExistingUuids(dbSession, views));
views.forEach(v -> bulkIndexer.addDeletion(TYPE_VIEW, v));
return bulkIndexer.stop();
}
Aggregations