Search in sources :

Example 1 with LuceneServiceImpl

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

the class LuceneDescribeIndexFunction method execute.

public void execute(final FunctionContext context) {
    LuceneIndexDetails result = null;
    final Cache cache = getCache();
    final String serverName = cache.getDistributedSystem().getDistributedMember().getName();
    final LuceneIndexInfo indexInfo = (LuceneIndexInfo) context.getArguments();
    LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
    LuceneIndex index = service.getIndex(indexInfo.getIndexName(), indexInfo.getRegionPath());
    LuceneIndexCreationProfile profile = service.getDefinedIndex(indexInfo.getIndexName(), indexInfo.getRegionPath());
    if (index != null) {
        result = new LuceneIndexDetails((LuceneIndexImpl) index, serverName);
    } else if (profile != null) {
        result = new LuceneIndexDetails(profile, serverName);
    }
    context.getResultSender().lastResult(result);
}
Also used : LuceneIndexInfo(org.apache.geode.cache.lucene.internal.cli.LuceneIndexInfo) LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) Cache(org.apache.geode.cache.Cache)

Example 2 with LuceneServiceImpl

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

the class LuceneIndexCreation method beforeCreate.

@Override
public void beforeCreate(Extensible<Region<?, ?>> source, Cache cache) {
    LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
    Analyzer analyzer = this.fieldAnalyzers == null ? new StandardAnalyzer() : new PerFieldAnalyzerWrapper(new StandardAnalyzer(), this.fieldAnalyzers);
    try {
        service.createIndex(getName(), getRegionPath(), analyzer, this.fieldAnalyzers, getFieldNames());
    } catch (LuceneIndexExistsException e) {
        logger.info(LocalizedStrings.LuceneIndexCreation_IGNORING_DUPLICATE_INDEX_CREATION_0_ON_REGION_1.toLocalizedString(e.getIndexName(), e.getRegionPath()));
    }
}
Also used : LuceneIndexExistsException(org.apache.geode.cache.lucene.LuceneIndexExistsException) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) PerFieldAnalyzerWrapper(org.apache.lucene.analysis.miscellaneous.PerFieldAnalyzerWrapper)

Example 3 with LuceneServiceImpl

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

the class LuceneListIndexFunction method execute.

public void execute(final FunctionContext context) {
    final Set<LuceneIndexDetails> indexDetailsSet = new HashSet<>();
    final Cache cache = getCache();
    final String serverName = cache.getDistributedSystem().getDistributedMember().getName();
    LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
    for (LuceneIndex index : service.getAllIndexes()) {
        indexDetailsSet.add(new LuceneIndexDetails((LuceneIndexImpl) index, serverName));
    }
    for (LuceneIndexCreationProfile profile : service.getAllDefinedIndexes()) {
        indexDetailsSet.add(new LuceneIndexDetails(profile, serverName));
    }
    context.getResultSender().lastResult(indexDetailsSet);
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) LuceneIndexDetails(org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexImpl(org.apache.geode.cache.lucene.internal.LuceneIndexImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) HashSet(java.util.HashSet) Cache(org.apache.geode.cache.Cache)

Example 4 with LuceneServiceImpl

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

the class LuceneIndexCommandsDUnitTest method createIndexWithoutRegionShouldReturnCorrectResults.

@Test
public void createIndexWithoutRegionShouldReturnCorrectResults() throws Exception {
    final VM vm1 = Host.getHost(0).getVM(1);
    vm1.invoke(() -> {
        getCache();
    });
    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
    String resultAsString = executeCommandAndLogResult(csb);
    vm1.invoke(() -> {
        LuceneServiceImpl luceneService = (LuceneServiceImpl) LuceneServiceProvider.get(getCache());
        final ArrayList<LuceneIndexCreationProfile> profiles = new ArrayList<>(luceneService.getAllDefinedIndexes());
        assertEquals(1, profiles.size());
        assertEquals(INDEX_NAME, profiles.get(0).getIndexName());
    });
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) ArrayList(java.util.ArrayList) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 5 with LuceneServiceImpl

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

the class LuceneQueryFunctionJUnitTest method whenServiceReturnsNullIndexButHasDefinedLuceneIndexDuringQueryExecutionShouldBlockUntilAvailable.

@Test
public void whenServiceReturnsNullIndexButHasDefinedLuceneIndexDuringQueryExecutionShouldBlockUntilAvailable() throws Exception {
    LuceneServiceImpl mockServiceImpl = mock(LuceneServiceImpl.class);
    when(mockCache.getService(any())).thenReturn(mockServiceImpl);
    when(mockServiceImpl.getIndex(eq("indexName"), eq(regionPath))).thenAnswer(new Answer() {

        private boolean calledFirstTime = false;

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            if (calledFirstTime == false) {
                calledFirstTime = true;
                return null;
            } else {
                return mockIndex;
            }
        }
    });
    when(mockServiceImpl.getDefinedIndex(eq("indexName"), eq(regionPath))).thenAnswer(new Answer() {

        private int count = 10;

        @Override
        public Object answer(final InvocationOnMock invocation) throws Throwable {
            if (count-- > 0) {
                return mock(LuceneIndexCreationProfile.class);
            }
            return null;
        }
    });
    when(mockContext.getDataSet()).thenReturn(mockRegion);
    when(mockContext.getArguments()).thenReturn(searchArgs);
    when(mockContext.<TopEntriesCollector>getResultSender()).thenReturn(mockResultSender);
    CancelCriterion mockCancelCriterion = mock(CancelCriterion.class);
    when(mockCache.getCancelCriterion()).thenReturn(mockCancelCriterion);
    when(mockCancelCriterion.isCancelInProgress()).thenReturn(false);
    LuceneQueryFunction function = new LuceneQueryFunction();
    function.execute(mockContext);
}
Also used : Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) CancelCriterion(org.apache.geode.CancelCriterion) LuceneServiceImpl(org.apache.geode.cache.lucene.internal.LuceneServiceImpl) LuceneIndexCreationProfile(org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

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