Search in sources :

Example 1 with NO_CONTENT

use of io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT 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());
}
Also used : SearchStatisticsSnapshot(org.infinispan.query.core.stats.SearchStatisticsSnapshot) ResourceHandler(org.infinispan.rest.framework.ResourceHandler) LogFactory(org.infinispan.util.logging.LogFactory) INTERNAL_SERVER_ERROR(io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR) NOT_FOUND(io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) GET(org.infinispan.rest.framework.Method.GET) CompletableFuture(java.util.concurrent.CompletableFuture) POST(org.infinispan.rest.framework.Method.POST) MULTIPLE_CHOICES(io.netty.handler.codec.http.HttpResponseStatus.MULTIPLE_CHOICES) Function(java.util.function.Function) BAD_REQUEST(io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST) NO_CONTENT(io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT) Indexer(org.infinispan.query.Indexer) AdvancedCache(org.infinispan.AdvancedCache) ResourceUtil.asJsonResponse(org.infinispan.rest.resources.ResourceUtil.asJsonResponse) InfinispanQueryStatisticsInfo(org.infinispan.query.impl.InfinispanQueryStatisticsInfo) Log(org.infinispan.rest.logging.Log) RestRequest(org.infinispan.rest.framework.RestRequest) Invocations(org.infinispan.rest.framework.impl.Invocations) CacheException(org.infinispan.commons.CacheException) MassIndexerAlreadyStartedException(org.infinispan.query.impl.massindex.MassIndexerAlreadyStartedException) NettyRestResponse(org.infinispan.rest.NettyRestResponse) InvocationHelper(org.infinispan.rest.InvocationHelper) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) SearchStatistics(org.infinispan.query.core.stats.SearchStatistics) Security(org.infinispan.security.Security) ResourceUtil.asJsonResponseFuture(org.infinispan.rest.resources.ResourceUtil.asJsonResponseFuture) List(java.util.List) CompletionStage(java.util.concurrent.CompletionStage) Configuration(org.infinispan.configuration.cache.Configuration) RestResponse(org.infinispan.rest.framework.RestResponse) ComponentRegistryUtils(org.infinispan.query.impl.ComponentRegistryUtils) OK(io.netty.handler.codec.http.HttpResponseStatus.OK) Search(org.infinispan.query.Search) Indexer(org.infinispan.query.Indexer) MassIndexerAlreadyStartedException(org.infinispan.query.impl.massindex.MassIndexerAlreadyStartedException) NettyRestResponse(org.infinispan.rest.NettyRestResponse) CacheException(org.infinispan.commons.CacheException) MassIndexerAlreadyStartedException(org.infinispan.query.impl.massindex.MassIndexerAlreadyStartedException)

Aggregations

HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 BAD_REQUEST (io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST)1 INTERNAL_SERVER_ERROR (io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR)1 MULTIPLE_CHOICES (io.netty.handler.codec.http.HttpResponseStatus.MULTIPLE_CHOICES)1 NOT_FOUND (io.netty.handler.codec.http.HttpResponseStatus.NOT_FOUND)1 NO_CONTENT (io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT)1 OK (io.netty.handler.codec.http.HttpResponseStatus.OK)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1 Function (java.util.function.Function)1 AdvancedCache (org.infinispan.AdvancedCache)1 CacheException (org.infinispan.commons.CacheException)1 Configuration (org.infinispan.configuration.cache.Configuration)1 Indexer (org.infinispan.query.Indexer)1 Search (org.infinispan.query.Search)1 SearchStatistics (org.infinispan.query.core.stats.SearchStatistics)1 SearchStatisticsSnapshot (org.infinispan.query.core.stats.SearchStatisticsSnapshot)1 ComponentRegistryUtils (org.infinispan.query.impl.ComponentRegistryUtils)1