use of org.apache.geode.cache.lucene.LuceneService in project geode by apache.
the class LuceneClusterConfigurationDUnitTest method indexGetsCreatedUsingClusterConfiguration.
@Test
public void indexGetsCreatedUsingClusterConfiguration() throws Exception {
Member vm1 = startNodeUsingClusterConfiguration(1);
// Connect Gfsh to locator.
gfshConnector.connectAndVerify(locator);
// Create lucene index.
createLuceneIndexUsingGfsh();
createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
// Start vm2. This should have lucene index created using cluster
// configuration.
MemberVM vm2 = startNodeUsingClusterConfiguration(2);
vm2.invoke(() -> {
LuceneService luceneService = LuceneServiceProvider.get(LocatorServerStartupRule.serverStarter.getCache());
final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
assertNotNull(index);
validateIndexFields(new String[] { "field1", "field2", "field3" }, index);
});
}
use of org.apache.geode.cache.lucene.LuceneService in project geode by apache.
the class LuceneQueryFunction method getLuceneIndex.
private LuceneIndexImpl getLuceneIndex(final Region region, final LuceneFunctionContext<IndexResultCollector> searchContext) {
LuceneService service = LuceneServiceProvider.get(region.getCache());
LuceneIndexImpl index = null;
try {
index = (LuceneIndexImpl) service.getIndex(searchContext.getIndexName(), region.getFullPath());
if (index == null) {
while (service instanceof LuceneServiceImpl && (((LuceneServiceImpl) service).getDefinedIndex(searchContext.getIndexName(), region.getFullPath()) != null)) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
return null;
}
region.getCache().getCancelCriterion().checkCancelInProgress(null);
}
index = (LuceneIndexImpl) service.getIndex(searchContext.getIndexName(), region.getFullPath());
}
} catch (CacheClosedException e) {
throw new InternalFunctionInvocationTargetException("Cache is closed when attempting to retrieve index:" + region.getFullPath(), e);
}
return index;
}
use of org.apache.geode.cache.lucene.LuceneService in project geode by apache.
the class WaitUntilFlushedFunction method execute.
@Override
public void execute(FunctionContext context) {
RegionFunctionContext ctx = (RegionFunctionContext) context;
ResultSender<Boolean> resultSender = ctx.getResultSender();
Region region = ctx.getDataSet();
Cache cache = region.getCache();
WaitUntilFlushedFunctionContext arg = (WaitUntilFlushedFunctionContext) ctx.getArguments();
String indexName = arg.getIndexName();
if (indexName == null) {
throw new IllegalArgumentException("Missing index name");
}
long timeout = arg.getTimeout();
TimeUnit unit = arg.getTimeunit();
LuceneService service = LuceneServiceProvider.get(cache);
LuceneIndexImpl index = (LuceneIndexImpl) service.getIndex(indexName, region.getFullPath());
boolean result = false;
String aeqId = LuceneServiceImpl.getUniqueIndexName(indexName, region.getFullPath());
AsyncEventQueueImpl queue = (AsyncEventQueueImpl) cache.getAsyncEventQueue(aeqId);
if (queue != null) {
try {
result = queue.waitUntilFlushed(timeout, unit);
} catch (InterruptedException e) {
}
} else {
throw new IllegalArgumentException("The AEQ does not exist for the index " + indexName + " region " + region.getFullPath());
}
resultSender.lastResult(result);
}
use of org.apache.geode.cache.lucene.LuceneService in project geode by apache.
the class LuceneDestroyIndexFunction method execute.
public void execute(final FunctionContext context) {
CliFunctionResult result = null;
String memberId = getCache().getDistributedSystem().getDistributedMember().getId();
try {
LuceneDestroyIndexInfo indexInfo = (LuceneDestroyIndexInfo) context.getArguments();
String indexName = indexInfo.getIndexName();
String regionPath = indexInfo.getRegionPath();
LuceneService service = LuceneServiceProvider.get(getCache());
if (indexName == null) {
if (indexInfo.isDefinedDestroyOnly()) {
((LuceneServiceImpl) service).destroyDefinedIndexes(regionPath);
result = new CliFunctionResult(memberId);
} else {
service.destroyIndexes(regionPath);
result = new CliFunctionResult(memberId, getXmlEntity(indexName, regionPath));
}
} else {
if (indexInfo.isDefinedDestroyOnly()) {
((LuceneServiceImpl) service).destroyDefinedIndex(indexName, regionPath);
result = new CliFunctionResult(memberId);
} else {
service.destroyIndex(indexName, regionPath);
result = new CliFunctionResult(memberId, getXmlEntity(indexName, regionPath));
}
}
} catch (Exception e) {
result = new CliFunctionResult(memberId, e, e.getMessage());
}
context.getResultSender().lastResult(result);
}
use of org.apache.geode.cache.lucene.LuceneService in project geode by apache.
the class DumpDirectoryFiles method execute.
@Override
public void execute(FunctionContext context) {
RegionFunctionContext ctx = (RegionFunctionContext) context;
if (!(context.getArguments() instanceof String[])) {
throw new IllegalArgumentException("Arguments should be a string array");
}
String[] args = (String[]) context.getArguments();
if (args.length != 2) {
throw new IllegalArgumentException("Expected 2 arguments: exportLocation, indexName");
}
String exportLocation = args[0];
String indexName = args[1];
final Region<Object, Object> region = ctx.getDataSet();
LuceneService service = LuceneServiceProvider.get(ctx.getDataSet().getCache());
InternalLuceneIndex index = (InternalLuceneIndex) service.getIndex(indexName, region.getFullPath());
if (index == null) {
throw new IllegalStateException("Index not found for region " + region + " index " + indexName);
}
final RepositoryManager repoManager = index.getRepositoryManager();
try {
final Collection<IndexRepository> repositories = repoManager.getRepositories(ctx);
repositories.stream().forEach(repo -> {
final IndexWriter writer = repo.getWriter();
RegionDirectory directory = (RegionDirectory) writer.getDirectory();
FileSystem fs = directory.getFileSystem();
String bucketName = index.getName() + "_" + repo.getRegion().getFullPath();
bucketName = bucketName.replace("/", "_");
File bucketDirectory = new File(exportLocation, bucketName);
bucketDirectory.mkdirs();
fs.export(bucketDirectory);
});
context.getResultSender().lastResult(null);
} catch (BucketNotFoundException e) {
throw new FunctionException(e);
}
}
Aggregations