Search in sources :

Example 11 with LuceneService

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);
    });
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) MemberVM(org.apache.geode.test.dunit.rules.MemberVM) Member(org.apache.geode.test.dunit.rules.Member) LuceneService(org.apache.geode.cache.lucene.LuceneService) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 12 with LuceneService

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;
}
Also used : InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) CacheClosedException(org.apache.geode.cache.CacheClosedException) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) LuceneService(org.apache.geode.cache.lucene.LuceneService)

Example 13 with LuceneService

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);
}
Also used : RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) LuceneService(org.apache.geode.cache.lucene.LuceneService) Region(org.apache.geode.cache.Region) TimeUnit(java.util.concurrent.TimeUnit) AsyncEventQueueImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Cache(org.apache.geode.cache.Cache)

Example 14 with LuceneService

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);
}
Also used : CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneDestroyIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneDestroyIndexInfo) LuceneService(org.apache.geode.cache.lucene.LuceneService)

Example 15 with LuceneService

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);
    }
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) RegionFunctionContext(org.apache.geode.cache.execute.RegionFunctionContext) LuceneService(org.apache.geode.cache.lucene.LuceneService) IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) IndexWriter(org.apache.lucene.index.IndexWriter) InternalLuceneIndex(org.apache.geode.cache.lucene.internal.InternalLuceneIndex) FileSystem(org.apache.geode.cache.lucene.internal.filesystem.FileSystem) BucketNotFoundException(org.apache.geode.internal.cache.BucketNotFoundException) RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager) File(java.io.File)

Aggregations

LuceneService (org.apache.geode.cache.lucene.LuceneService)23 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)10 Test (org.junit.Test)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 Analyzer (org.apache.lucene.analysis.Analyzer)6 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)6 Cache (org.apache.geode.cache.Cache)5 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)5 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)4 VM (org.apache.geode.test.dunit.VM)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 Region (org.apache.geode.cache.Region)2 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)2 LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)2 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)2 MemberVM (org.apache.geode.test.dunit.rules.MemberVM)2