use of org.apache.geode.management.internal.cli.functions.CliFunctionResult 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);
}
use of org.apache.geode.management.internal.cli.functions.CliFunctionResult in project geode by apache.
the class LuceneCreateIndexFunction method execute.
public void execute(final FunctionContext context) {
String memberId = null;
try {
final LuceneIndexInfo indexInfo = (LuceneIndexInfo) context.getArguments();
final Cache cache = getCache();
memberId = cache.getDistributedSystem().getDistributedMember().getId();
LuceneService service = LuceneServiceProvider.get(cache);
INDEX_NAME.validateName(indexInfo.getIndexName());
String[] fields = indexInfo.getSearchableFieldNames();
String[] analyzerName = indexInfo.getFieldAnalyzers();
final LuceneIndexFactory indexFactory = service.createIndexFactory();
if (analyzerName == null || analyzerName.length == 0) {
for (String field : fields) {
indexFactory.addField(field);
}
} else {
if (analyzerName.length != fields.length)
throw new Exception("Mismatch in lengths of fields and analyzers");
for (int i = 0; i < fields.length; i++) {
Analyzer analyzer = toAnalyzer(analyzerName[i]);
indexFactory.addField(fields[i], analyzer);
}
}
REGION_PATH.validateName(indexInfo.getRegionPath());
indexFactory.create(indexInfo.getIndexName(), indexInfo.getRegionPath());
// TODO - update cluster configuration by returning a valid XmlEntity
XmlEntity xmlEntity = null;
context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity));
} catch (Exception e) {
String exceptionMessage = CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage());
context.getResultSender().lastResult(new CliFunctionResult(memberId, e, e.getMessage()));
}
}
use of org.apache.geode.management.internal.cli.functions.CliFunctionResult in project geode by apache.
the class LuceneIndexCommandsJUnitTest method createTestLuceneIndexCommandsForDestroyIndex.
private LuceneIndexCommands createTestLuceneIndexCommandsForDestroyIndex() {
final InternalCache mockCache = mock(InternalCache.class);
final ResultCollector mockResultCollector = mock(ResultCollector.class);
final LuceneIndexCommands commands = spy(createIndexCommands(mockCache, null));
final List<CliFunctionResult> cliFunctionResults = new ArrayList<>();
cliFunctionResults.add(new CliFunctionResult("member", true, "Index Destroyed"));
doReturn(mockResultCollector).when(commands).executeFunctionOnRegion(isA(LuceneDestroyIndexFunction.class), any(LuceneIndexInfo.class), eq(false));
doReturn(cliFunctionResults).when(mockResultCollector).getResult();
return commands;
}
use of org.apache.geode.management.internal.cli.functions.CliFunctionResult in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testDestroyAllIndexesWithRegionMembers.
@Test
@Parameters({ "true", "false" })
public void testDestroyAllIndexesWithRegionMembers(boolean expectedToSucceed) throws Exception {
LuceneIndexCommands commands = createTestLuceneIndexCommandsForDestroyIndex();
String indexName = null;
String regionPath = "regionPath";
Set<DistributedMember> members = new HashSet<>();
DistributedMember mockMember = mock(DistributedMember.class);
when(mockMember.getId()).thenReturn("member0");
members.add(mockMember);
final ResultCollector mockResultCollector = mock(ResultCollector.class);
final List<CliFunctionResult> cliFunctionResults = new ArrayList<>();
String expectedStatus;
if (expectedToSucceed) {
expectedStatus = CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEXES_FROM_REGION_0, new Object[] { regionPath });
cliFunctionResults.add(new CliFunctionResult(mockMember.getId()));
} else {
Exception e = new IllegalStateException("failed");
expectedStatus = e.getMessage();
cliFunctionResults.add(new CliFunctionResult("member0", e, e.getMessage()));
}
doReturn(mockResultCollector).when(commands).executeFunction(isA(LuceneDestroyIndexFunction.class), any(LuceneDestroyIndexInfo.class), any());
doReturn(cliFunctionResults).when(mockResultCollector).getResult();
doReturn(Collections.emptySet()).when(commands).getNormalMembers(any());
doReturn(Collections.emptySet()).when(commands).getRegionMembers(any(), any());
CommandResult result = (CommandResult) commands.destroyIndex(indexName, regionPath);
verifyDestroyIndexCommandResult(result, cliFunctionResults, expectedStatus);
}
use of org.apache.geode.management.internal.cli.functions.CliFunctionResult in project geode by apache.
the class LuceneIndexCommandsJUnitTest method testDestroyAllIndexesNoRegionMembers.
@Test
@Parameters({ "true", "false" })
public void testDestroyAllIndexesNoRegionMembers(boolean expectedToSucceed) throws Exception {
LuceneIndexCommands commands = createTestLuceneIndexCommandsForDestroyIndex();
String indexName = null;
String regionPath = "regionPath";
final ResultCollector mockResultCollector = mock(ResultCollector.class);
final List<CliFunctionResult> cliFunctionResults = new ArrayList<>();
String expectedStatus;
if (expectedToSucceed) {
expectedStatus = CliStrings.format(LuceneCliStrings.LUCENE_DESTROY_INDEX__MSG__SUCCESSFULLY_DESTROYED_INDEXES_FROM_REGION_0, new Object[] { regionPath });
cliFunctionResults.add(new CliFunctionResult("member0"));
} else {
Exception e = new IllegalStateException("failed");
expectedStatus = e.getMessage();
cliFunctionResults.add(new CliFunctionResult("member0", e, e.getMessage()));
}
doReturn(mockResultCollector).when(commands).executeFunction(isA(LuceneDestroyIndexFunction.class), any(LuceneDestroyIndexInfo.class), any());
doReturn(cliFunctionResults).when(mockResultCollector).getResult();
doReturn(Collections.emptySet()).when(commands).getNormalMembers(any());
doReturn(Collections.emptySet()).when(commands).getRegionMembers(any(), any());
CommandResult result = (CommandResult) commands.destroyIndex(indexName, regionPath);
verifyDestroyIndexCommandResult(result, cliFunctionResults, expectedStatus);
}
Aggregations