use of org.apache.geode.management.internal.cli.domain.IndexInfo in project geode by apache.
the class CreateDefinedIndexesFunction method execute.
@Override
public void execute(FunctionContext context) {
String memberId = null;
List<Index> indexes = null;
Cache cache = null;
try {
cache = CacheFactory.getAnyInstance();
memberId = cache.getDistributedSystem().getDistributedMember().getId();
QueryService queryService = cache.getQueryService();
Set<IndexInfo> indexDefinitions = (Set<IndexInfo>) context.getArguments();
for (IndexInfo indexDefinition : indexDefinitions) {
String indexName = indexDefinition.getIndexName();
String indexedExpression = indexDefinition.getIndexedExpression();
String regionPath = indexDefinition.getRegionPath();
if (indexDefinition.getIndexType() == IndexInfo.KEY_INDEX) {
queryService.defineKeyIndex(indexName, indexedExpression, regionPath);
} else if (indexDefinition.getIndexType() == IndexInfo.HASH_INDEX) {
queryService.defineHashIndex(indexName, indexedExpression, regionPath);
} else {
queryService.defineIndex(indexName, indexedExpression, regionPath);
}
}
indexes = queryService.createDefinedIndexes();
context.getResultSender().lastResult(new CliFunctionResult(memberId));
} catch (MultiIndexCreationException e) {
StringBuffer sb = new StringBuffer();
sb.append("Index creation failed for indexes: ").append("\n");
for (Map.Entry<String, Exception> failedIndex : e.getExceptionsMap().entrySet()) {
sb.append(failedIndex.getKey()).append(" : ").append(failedIndex.getValue().getMessage()).append("\n");
}
context.getResultSender().lastResult(new CliFunctionResult(memberId, e, sb.toString()));
} catch (Exception e) {
String exceptionMessage = CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage());
context.getResultSender().lastResult(new CliFunctionResult(memberId, e, exceptionMessage));
}
}
Aggregations