use of org.infinispan.query.core.stats.SearchStatisticsSnapshot in project infinispan by infinispan.
the class SearchStatsRetriever method getDistributedSearchStatistics.
public CompletionStage<SearchStatisticsSnapshot> getDistributedSearchStatistics() {
StatsTask statsTask = new StatsTask(cache.getName());
ClusterExecutor clusterExecutor = SecurityActions.getClusterExecutor(cache);
Collection<SearchStatisticsSnapshot> stats = new ConcurrentLinkedQueue<>();
return clusterExecutor.submitConsumer(statsTask, (address, searchStats, throwable) -> {
if (throwable != null) {
Throwable rootCause = Util.getRootCause(throwable);
throw new CacheException("Error obtaining statistics from node", rootCause);
}
stats.add(searchStats);
}).thenApply(v -> stats.stream().reduce(new SearchStatisticsSnapshotImpl(), SearchStatisticsSnapshot::merge));
}
use of org.infinispan.query.core.stats.SearchStatisticsSnapshot in project infinispan by infinispan.
the class SearchAdminResource method searchStats.
private CompletionStage<RestResponse> searchStats(RestRequest restRequest) {
NettyRestResponse.Builder responseBuilder = new NettyRestResponse.Builder();
String cacheName = restRequest.variables().get("cacheName");
AdvancedCache<?, ?> cache = invocationHelper.getRestCacheManager().getCache(cacheName, restRequest);
if (cache == null) {
responseBuilder.status(HttpResponseStatus.NOT_FOUND);
return null;
}
Configuration cacheConfiguration = SecurityActions.getCacheConfiguration(cache);
if (!cacheConfiguration.statistics().enabled()) {
responseBuilder.status(NOT_FOUND).build();
}
String scopeParam = restRequest.getParameter("scope");
if (scopeParam != null && scopeParam.equalsIgnoreCase("cluster")) {
CompletionStage<SearchStatisticsSnapshot> stats = Search.getClusteredSearchStatistics(cache);
return stats.thenApply(s -> asJsonResponse(s.toJson()));
} else {
return Search.getSearchStatistics(cache).computeSnapshot().thenApply(s -> asJsonResponse(s.toJson()));
}
}
Aggregations