Search in sources :

Example 11 with LuceneServiceImpl

use of org.apache.geode.cache.lucene.internal.LuceneServiceImpl 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 12 with LuceneServiceImpl

use of org.apache.geode.cache.lucene.internal.LuceneServiceImpl 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 13 with LuceneServiceImpl

use of org.apache.geode.cache.lucene.internal.LuceneServiceImpl in project geode by apache.

the class LuceneIndexCreationIntegrationTest method shouldReturnAllDefinedIndexes.

@Test
public void shouldReturnAllDefinedIndexes() {
    LuceneServiceImpl luceneServiceImpl = (LuceneServiceImpl) luceneService;
    luceneServiceImpl.createIndexFactory().setFields("field1", "field2", "field3").create(INDEX_NAME, REGION_NAME);
    luceneServiceImpl.createIndexFactory().setFields("field4", "field5", "field6").create("index2", "region2");
    final Collection<LuceneIndexCreationProfile> indexList = luceneServiceImpl.getAllDefinedIndexes();
    assertEquals(Arrays.asList(INDEX_NAME, "index2"), indexList.stream().map(LuceneIndexCreationProfile::getIndexName).sorted().collect(Collectors.toList()));
    createRegion();
    assertEquals(Collections.singletonList("index2"), indexList.stream().map(LuceneIndexCreationProfile::getIndexName).collect(Collectors.toList()));
}
Also used : LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)13 LuceneIndexCreationProfile (org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile)5 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)5 Test (org.junit.Test)5 LuceneIndexDetails (org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails)4 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 ArrayList (java.util.ArrayList)2 Cache (org.apache.geode.cache.Cache)2 FunctionContext (org.apache.geode.cache.execute.FunctionContext)2 ResultSender (org.apache.geode.cache.execute.ResultSender)2 LuceneService (org.apache.geode.cache.lucene.LuceneService)2 LuceneIndexInfo (org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo)2 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 TreeSet (java.util.TreeSet)1 CancelCriterion (org.apache.geode.CancelCriterion)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 LuceneIndexExistsException (org.apache.geode.cache.lucene.LuceneIndexExistsException)1