Search in sources :

Example 6 with Indexer

use of org.infinispan.query.Indexer 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)

Example 7 with Indexer

use of org.infinispan.query.Indexer in project infinispan by infinispan.

the class ReindexCacheTest method reindex.

private void reindex() {
    Cache<?, ?> cache = cacheManager.getCache(USER_CACHE);
    Indexer indexer = org.infinispan.query.Search.getIndexer(cache);
    CompletionStages.join(indexer.run());
}
Also used : Indexer(org.infinispan.query.Indexer)

Example 8 with Indexer

use of org.infinispan.query.Indexer in project infinispan by infinispan.

the class LifecycleManager method cacheStarting.

/**
 * Registers the Search interceptor in the cache before it gets started
 */
@Override
public void cacheStarting(ComponentRegistry cr, Configuration cfg, String cacheName) {
    InternalCacheRegistry icr = cr.getGlobalComponentRegistry().getComponent(InternalCacheRegistry.class);
    LocalQueryStatistics queryStatistics = cr.getComponent(LocalQueryStatistics.class);
    if (!icr.isInternalCache(cacheName) || icr.internalCacheHasFlag(cacheName, Flag.QUERYABLE)) {
        AdvancedCache<?, ?> cache = cr.getComponent(Cache.class).getAdvancedCache();
        SecurityActions.addCacheDependency(cache.getCacheManager(), cacheName, QueryCache.QUERY_CACHE_NAME);
        ClassLoader aggregatedClassLoader = makeAggregatedClassLoader(cr.getGlobalComponentRegistry().getGlobalConfiguration().classLoader());
        boolean isIndexed = cfg.indexing().enabled();
        SearchMapping searchMapping = null;
        if (isIndexed) {
            Map<String, Class<?>> indexedClasses = makeIndexedClassesMap(cache);
            KeyTransformationHandler keyTransformationHandler = new KeyTransformationHandler(aggregatedClassLoader);
            cr.registerComponent(keyTransformationHandler, KeyTransformationHandler.class);
            for (Map.Entry<Class<?>, Class<?>> kt : cfg.indexing().keyTransformers().entrySet()) {
                keyTransformationHandler.registerTransformer(kt.getKey(), (Class<? extends Transformer>) kt.getValue());
            }
            searchMapping = createSearchMapping(queryStatistics, cfg.indexing(), indexedClasses, cr, cache, keyTransformationHandler, aggregatedClassLoader);
            createQueryInterceptorIfNeeded(cr, cfg, cache, indexedClasses);
            Indexer massIndexer = new DistributedExecutorMassIndexer(cache);
            cr.registerComponent(massIndexer, Indexer.class);
            if (searchMapping != null) {
                BasicComponentRegistry bcr = cr.getComponent(BasicComponentRegistry.class);
                bcr.replaceComponent(IndexStatistics.class.getName(), new LocalIndexStatistics(), true);
                bcr.rewire();
            }
        }
        cr.registerComponent(ObjectReflectionMatcher.create(new ReflectionEntityNamesResolver(aggregatedClassLoader), searchMapping), ObjectReflectionMatcher.class);
        cr.registerComponent(new QueryEngine<>(cache, isIndexed), QueryEngine.class);
    }
}
Also used : ReflectionEntityNamesResolver(org.infinispan.objectfilter.impl.syntax.parser.ReflectionEntityNamesResolver) SearchMapping(org.infinispan.search.mapper.mapping.SearchMapping) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) InternalCacheRegistry(org.infinispan.registry.InternalCacheRegistry) DistributedExecutorMassIndexer(org.infinispan.query.impl.massindex.DistributedExecutorMassIndexer) LocalIndexStatistics(org.infinispan.query.stats.impl.LocalIndexStatistics) IndexStatistics(org.infinispan.query.core.stats.IndexStatistics) BasicComponentRegistry(org.infinispan.factories.impl.BasicComponentRegistry) DistributedExecutorMassIndexer(org.infinispan.query.impl.massindex.DistributedExecutorMassIndexer) Indexer(org.infinispan.query.Indexer) KeyTransformationHandler(org.infinispan.query.backend.KeyTransformationHandler) AggregatedClassLoader(org.infinispan.commons.util.AggregatedClassLoader) LocalQueryStatistics(org.infinispan.query.core.stats.impl.LocalQueryStatistics) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Cache(org.infinispan.Cache) QueryCache(org.infinispan.query.core.impl.QueryCache) AdvancedCache(org.infinispan.AdvancedCache)

Example 9 with Indexer

use of org.infinispan.query.Indexer in project infinispan by infinispan.

the class ReplRamMassIndexingTest method rebuildIndexes.

@Override
protected void rebuildIndexes() {
    for (Cache<?, ?> cache : caches()) {
        Indexer indexer = Search.getIndexer(cache);
        eventually(() -> !indexer.isRunning());
        join(indexer.run());
    }
}
Also used : Indexer(org.infinispan.query.Indexer)

Example 10 with Indexer

use of org.infinispan.query.Indexer in project infinispan by infinispan.

the class LocalCacheMassIndexerTest method testMassIndexer.

@Test
public void testMassIndexer() {
    fillData();
    Indexer massIndexer = Search.getIndexer(cache);
    assertEquals(NUM_ENTITIES, indexSize(cache));
    join(massIndexer.run());
    assertEquals(NUM_ENTITIES, indexSize(cache));
    cache.clear();
    join(massIndexer.run());
    assertEquals(0, indexSize(cache));
    fillData();
    join(massIndexer.run());
    assertFalse(massIndexer.isRunning());
    assertEquals(NUM_ENTITIES, indexSize(cache));
    // Force local
    join(massIndexer.runLocal());
    assertFalse(massIndexer.isRunning());
    assertEquals(NUM_ENTITIES, indexSize(cache));
}
Also used : Indexer(org.infinispan.query.Indexer) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) Test(org.testng.annotations.Test)

Aggregations

Indexer (org.infinispan.query.Indexer)11 AdvancedCache (org.infinispan.AdvancedCache)3 Cache (org.infinispan.Cache)2 Configuration (org.infinispan.configuration.cache.Configuration)2 QueryCache (org.infinispan.query.core.impl.QueryCache)2 DistributedExecutorMassIndexer (org.infinispan.query.impl.massindex.DistributedExecutorMassIndexer)2 Test (org.testng.annotations.Test)2 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 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 CompletionStage (java.util.concurrent.CompletionStage)1