use of org.apache.geode.management.internal.cli.domain.RegionInformation in project geode by apache.
the class RegionCommands method listRegion.
@CliCommand(value = { CliStrings.LIST_REGION }, help = CliStrings.LIST_REGION__HELP)
@CliMetaData(shellOnly = false, relatedTopic = CliStrings.TOPIC_GEODE_REGION)
@ResourceOperation(resource = Resource.DATA, operation = Operation.READ)
public Result listRegion(@CliOption(key = { CliStrings.LIST_REGION__GROUP }, optionContext = ConverterHint.MEMBERGROUP, help = CliStrings.LIST_REGION__GROUP__HELP) String[] group, @CliOption(key = { CliStrings.LIST_REGION__MEMBER }, optionContext = ConverterHint.MEMBERIDNAME, help = CliStrings.LIST_REGION__MEMBER__HELP) String[] memberNameOrId) {
Result result = null;
try {
Set<RegionInformation> regionInfoSet = new LinkedHashSet<RegionInformation>();
ResultCollector<?, ?> rc = null;
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
TabularResultData resultData = ResultBuilder.createTabularResultData();
rc = CliUtil.executeFunction(getRegionsFunction, null, targetMembers);
ArrayList<?> resultList = (ArrayList<?>) rc.getResult();
if (resultList != null) {
Iterator<?> iters = resultList.iterator();
while (iters.hasNext()) {
Object resultObj = iters.next();
if (resultObj != null) {
if (resultObj instanceof Object[]) {
Object[] resultObjectArray = (Object[]) resultObj;
for (Object regionInfo : resultObjectArray) {
if (regionInfo instanceof RegionInformation) {
regionInfoSet.add((RegionInformation) regionInfo);
}
}
}
}
}
Set<String> regionNames = new TreeSet<String>();
for (RegionInformation regionInfo : regionInfoSet) {
regionNames.add(regionInfo.getName());
Set<String> subRegionNames = regionInfo.getSubRegionNames();
for (String subRegionName : subRegionNames) {
regionNames.add(subRegionName);
}
}
for (String regionName : regionNames) {
resultData.accumulate("List of regions", regionName);
}
if (!regionNames.isEmpty()) {
result = ResultBuilder.buildResult(resultData);
} else {
result = ResultBuilder.createInfoResult(CliStrings.LIST_REGION__MSG__NOT_FOUND);
}
}
} catch (FunctionInvocationTargetException e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.LIST_REGION));
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(CliStrings.LIST_REGION__MSG__ERROR + " : " + e.getMessage());
}
return result;
}
use of org.apache.geode.management.internal.cli.domain.RegionInformation in project geode by apache.
the class GetRegionsFunction method execute.
@Override
public void execute(FunctionContext functionContext) {
try {
Cache cache = CacheFactory.getAnyInstance();
// should never return a null
Set<Region<?, ?>> regions = cache.rootRegions();
if (regions == null || regions.isEmpty()) {
functionContext.getResultSender().lastResult(null);
} else {
Set<RegionInformation> regionInformationSet = new HashSet<>();
for (Region<?, ?> region : regions) {
RegionInformation regInfo = new RegionInformation(region, true);
regionInformationSet.add(regInfo);
}
functionContext.getResultSender().lastResult(regionInformationSet.toArray());
}
} catch (Exception e) {
functionContext.getResultSender().sendException(e);
}
}
Aggregations