Search in sources :

Example 1 with SearchStatisticsSnapshot

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));
}
Also used : CacheException(org.infinispan.commons.CacheException) SearchStatisticsSnapshot(org.infinispan.query.core.stats.SearchStatisticsSnapshot) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) Collection(java.util.Collection) Util(org.infinispan.commons.util.Util) Cache(org.infinispan.Cache) Inject(org.infinispan.factories.annotations.Inject) SearchStatistics(org.infinispan.query.core.stats.SearchStatistics) Scopes(org.infinispan.factories.scopes.Scopes) CompletionStage(java.util.concurrent.CompletionStage) ClusterExecutor(org.infinispan.manager.ClusterExecutor) Scope(org.infinispan.factories.scopes.Scope) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) CacheException(org.infinispan.commons.CacheException) SearchStatisticsSnapshot(org.infinispan.query.core.stats.SearchStatisticsSnapshot) ClusterExecutor(org.infinispan.manager.ClusterExecutor) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue)

Example 2 with SearchStatisticsSnapshot

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()));
    }
}
Also used : Configuration(org.infinispan.configuration.cache.Configuration) SearchStatisticsSnapshot(org.infinispan.query.core.stats.SearchStatisticsSnapshot) NettyRestResponse(org.infinispan.rest.NettyRestResponse)

Aggregations

SearchStatisticsSnapshot (org.infinispan.query.core.stats.SearchStatisticsSnapshot)2 Collection (java.util.Collection)1 CompletionStage (java.util.concurrent.CompletionStage)1 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)1 Cache (org.infinispan.Cache)1 CacheException (org.infinispan.commons.CacheException)1 Util (org.infinispan.commons.util.Util)1 Configuration (org.infinispan.configuration.cache.Configuration)1 Inject (org.infinispan.factories.annotations.Inject)1 Scope (org.infinispan.factories.scopes.Scope)1 Scopes (org.infinispan.factories.scopes.Scopes)1 ClusterExecutor (org.infinispan.manager.ClusterExecutor)1 IndexStatistics (org.infinispan.query.core.stats.IndexStatistics)1 SearchStatistics (org.infinispan.query.core.stats.SearchStatistics)1 NettyRestResponse (org.infinispan.rest.NettyRestResponse)1