Search in sources :

Example 1 with IndexDetails

use of org.apache.geode.management.internal.cli.domain.IndexDetails in project geode by apache.

the class ListIndexFunction method execute.

public void execute(final FunctionContext context) {
    try {
        final Set<IndexDetails> indexDetailsSet = new HashSet<IndexDetails>();
        final Cache cache = getCache();
        final DistributedMember member = cache.getDistributedSystem().getDistributedMember();
        for (final Index index : cache.getQueryService().getIndexes()) {
            indexDetailsSet.add(new IndexDetails(member, index));
        }
        context.getResultSender().lastResult(indexDetailsSet);
    } catch (Exception e) {
        context.getResultSender().sendException(e);
    }
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) Index(org.apache.geode.cache.query.Index) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails) HashSet(java.util.HashSet) Cache(org.apache.geode.cache.Cache)

Example 2 with IndexDetails

use of org.apache.geode.management.internal.cli.domain.IndexDetails in project geode by apache.

the class IndexCommandsJUnitTest method testGetIndexListingReturnsFunctionInvocationTargetExceptionInResults.

@Test
public void testGetIndexListingReturnsFunctionInvocationTargetExceptionInResults() {
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
    final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
    final IndexDetails indexDetails = createIndexDetails("memberOne", "/Employees", "empIdIdx");
    final List<IndexDetails> expectedIndexDetails = Arrays.asList(indexDetails);
    final List<Object> results = new ArrayList<Object>(2);
    results.add(CollectionUtils.asSet(indexDetails));
    results.add(new FunctionInvocationTargetException("expected"));
    mockContext.checking(new Expectations() {

        {
            oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
            oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
            will(returnValue(mockResultCollector));
            oneOf(mockResultCollector).getResult();
            will(returnValue(results));
        }
    });
    final IndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
    final List<IndexDetails> actualIndexDetails = commands.getIndexListing();
    assertNotNull(actualIndexDetails);
    assertEquals(expectedIndexDetails, actualIndexDetails);
}
Also used : Expectations(org.jmock.Expectations) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) ArrayList(java.util.ArrayList) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalCache(org.apache.geode.internal.cache.InternalCache) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ListIndexFunction(org.apache.geode.management.internal.cli.functions.ListIndexFunction) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 3 with IndexDetails

use of org.apache.geode.management.internal.cli.domain.IndexDetails in project geode by apache.

the class IndexCommandsJUnitTest method testGetIndexListing.

@Test
public void testGetIndexListing() {
    final InternalCache mockCache = mockContext.mock(InternalCache.class, "InternalCache");
    final AbstractExecution mockFunctionExecutor = mockContext.mock(AbstractExecution.class, "Function Executor");
    final ResultCollector mockResultCollector = mockContext.mock(ResultCollector.class, "ResultCollector");
    final IndexDetails indexDetails1 = createIndexDetails("memberOne", "/Employees", "empIdIdx");
    final IndexDetails indexDetails2 = createIndexDetails("memberOne", "/Employees", "empLastNameIdx");
    final IndexDetails indexDetails3 = createIndexDetails("memberTwo", "/Employees", "empDobIdx");
    final List<IndexDetails> expectedIndexDetails = Arrays.asList(indexDetails1, indexDetails2, indexDetails3);
    final List<Set<IndexDetails>> results = new ArrayList<Set<IndexDetails>>(2);
    results.add(CollectionUtils.asSet(indexDetails2, indexDetails1));
    results.add(CollectionUtils.asSet(indexDetails3));
    mockContext.checking(new Expectations() {

        {
            oneOf(mockFunctionExecutor).setIgnoreDepartedMembers(with(equal(true)));
            oneOf(mockFunctionExecutor).execute(with(aNonNull(ListIndexFunction.class)));
            will(returnValue(mockResultCollector));
            oneOf(mockResultCollector).getResult();
            will(returnValue(results));
        }
    });
    final IndexCommands commands = createIndexCommands(mockCache, mockFunctionExecutor);
    final List<IndexDetails> actualIndexDetails = commands.getIndexListing();
    assertNotNull(actualIndexDetails);
    assertEquals(expectedIndexDetails, actualIndexDetails);
}
Also used : Expectations(org.jmock.Expectations) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Set(java.util.Set) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ListIndexFunction(org.apache.geode.management.internal.cli.functions.ListIndexFunction) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Example 4 with IndexDetails

use of org.apache.geode.management.internal.cli.domain.IndexDetails in project geode by apache.

the class ListIndexFunctionJUnitTest method createIndexDetails.

private IndexDetails createIndexDetails(final String memberId, final String regionPath, final String indexName, final IndexType indexType, final String fromClause, final String indexedExpression, final String memberName, final String projectionAttributes, final String regionName) {
    final IndexDetails indexDetails = new IndexDetails(memberId, regionPath, indexName);
    indexDetails.setFromClause(fromClause);
    indexDetails.setIndexedExpression(indexedExpression);
    indexDetails.setIndexType(indexType);
    indexDetails.setMemberName(memberName);
    indexDetails.setProjectionAttributes(projectionAttributes);
    indexDetails.setRegionName(regionName);
    return indexDetails;
}
Also used : IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails)

Example 5 with IndexDetails

use of org.apache.geode.management.internal.cli.domain.IndexDetails in project geode by apache.

the class IndexCommands method toTabularResult.

protected Result toTabularResult(final List<IndexDetails> indexDetailsList, final boolean showStats) {
    if (!indexDetailsList.isEmpty()) {
        final TabularResultData indexData = ResultBuilder.createTabularResultData();
        for (final IndexDetails indexDetails : indexDetailsList) {
            indexData.accumulate("Member Name", StringUtils.defaultString(indexDetails.getMemberName()));
            indexData.accumulate("Member ID", indexDetails.getMemberId());
            indexData.accumulate("Region Path", indexDetails.getRegionPath());
            indexData.accumulate("Name", indexDetails.getIndexName());
            indexData.accumulate("Type", StringUtils.defaultString(indexDetails.getIndexType()));
            indexData.accumulate("Indexed Expression", indexDetails.getIndexedExpression());
            indexData.accumulate("From Clause", indexDetails.getFromClause());
            if (showStats) {
                final IndexStatisticsDetailsAdapter adapter = new IndexStatisticsDetailsAdapter(indexDetails.getIndexStatisticsDetails());
                indexData.accumulate("Uses", adapter.getTotalUses());
                indexData.accumulate("Updates", adapter.getNumberOfUpdates());
                indexData.accumulate("Update Time", adapter.getTotalUpdateTime());
                indexData.accumulate("Keys", adapter.getNumberOfKeys());
                indexData.accumulate("Values", adapter.getNumberOfValues());
            }
        }
        return ResultBuilder.buildResult(indexData);
    } else {
        return ResultBuilder.createInfoResult(CliStrings.LIST_INDEX__INDEXES_NOT_FOUND_MESSAGE);
    }
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) IndexDetails(org.apache.geode.management.internal.cli.domain.IndexDetails)

Aggregations

IndexDetails (org.apache.geode.management.internal.cli.domain.IndexDetails)8 HashSet (java.util.HashSet)4 Set (java.util.Set)4 UnitTest (org.apache.geode.test.junit.categories.UnitTest)4 Expectations (org.jmock.Expectations)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 Cache (org.apache.geode.cache.Cache)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)3 ListIndexFunction (org.apache.geode.management.internal.cli.functions.ListIndexFunction)3 FunctionContext (org.apache.geode.cache.execute.FunctionContext)2 ResultCollector (org.apache.geode.cache.execute.ResultCollector)2 QueryService (org.apache.geode.cache.query.QueryService)2 DistributedSystem (org.apache.geode.distributed.DistributedSystem)2 InternalCache (org.apache.geode.internal.cache.InternalCache)2 List (java.util.List)1 TreeSet (java.util.TreeSet)1 Execution (org.apache.geode.cache.execute.Execution)1 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)1