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());
}
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());
}
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);
}
}
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());
}
}
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));
}
Aggregations