use of org.infinispan.query.impl.massindex.MassIndexerAlreadyStartedException in project infinispan by infinispan.
the class SearchAdminResource method runIndexer.
private CompletionStage<RestResponse> runIndexer(RestRequest request, Function<Indexer, CompletionStage<Void>> op, boolean supportAsync) {
NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
List<String> mode = request.parameters().get("mode");
boolean asyncParams = mode != null && !mode.isEmpty() && mode.iterator().next().equalsIgnoreCase("async");
boolean async = asyncParams && supportAsync;
AdvancedCache<?, ?> cache = lookupIndexedCache(request, responseBuilder);
int status = responseBuilder.getStatus();
if (status < OK.code() || status >= MULTIPLE_CHOICES.code()) {
return completedFuture(responseBuilder.build());
}
responseBuilder.status(NO_CONTENT);
Indexer indexer = ComponentRegistryUtils.getIndexer(cache);
if (async) {
try {
LOG.asyncMassIndexerStarted();
op.apply(indexer).whenComplete((v, e) -> {
if (e == null) {
LOG.asyncMassIndexerSuccess();
} else {
LOG.errorExecutingMassIndexer(e.getCause());
}
});
} catch (Exception e) {
responseBuilder.status(INTERNAL_SERVER_ERROR).entity("Error executing the MassIndexer " + e.getCause());
}
return CompletableFuture.completedFuture(responseBuilder.build());
}
return op.apply(indexer).exceptionally(e -> {
if (e instanceof MassIndexerAlreadyStartedException) {
responseBuilder.status(BAD_REQUEST).entity("MassIndexer already started");
} else {
responseBuilder.status(INTERNAL_SERVER_ERROR).entity("Error executing the MassIndexer " + e.getCause());
}
return null;
}).thenApply(v -> responseBuilder.build());
}
Aggregations