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);
}
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations