use of org.apache.geode.management.internal.cli.functions.ListDurableCqNamesFunction in project geode by apache.
the class DurableClientCommands method listDurableClientCqs.
@CliCommand(value = CliStrings.LIST_DURABLE_CQS, help = CliStrings.LIST_DURABLE_CQS__HELP)
@CliMetaData(shellOnly = false)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listDurableClientCqs(@CliOption(key = CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID, mandatory = true, help = CliStrings.LIST_DURABLE_CQS__DURABLECLIENTID__HELP) final String durableClientId, @CliOption(key = CliStrings.LIST_DURABLE_CQS__MEMBER, help = CliStrings.LIST_DURABLE_CQS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, @CliOption(key = CliStrings.LIST_DURABLE_CQS__GROUP, help = CliStrings.LIST_DURABLE_CQS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) {
Result result = null;
try {
boolean noResults = true;
Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
if (targetMembers.isEmpty()) {
return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
}
final ResultCollector<?, ?> rc = CliUtil.executeFunction(new ListDurableCqNamesFunction(), durableClientId, targetMembers);
final List<DurableCqNamesResult> results = (List<DurableCqNamesResult>) rc.getResult();
Map<String, List<String>> memberCqNamesMap = new TreeMap<String, List<String>>();
Map<String, List<String>> errorMessageNodes = new HashMap<String, List<String>>();
Map<String, List<String>> exceptionMessageNodes = new HashMap<String, List<String>>();
for (DurableCqNamesResult memberResult : results) {
if (memberResult != null) {
if (memberResult.isSuccessful()) {
memberCqNamesMap.put(memberResult.getMemberNameOrId(), memberResult.getCqNamesList());
} else {
if (memberResult.isOpPossible()) {
groupByMessage(memberResult.getExceptionMessage(), memberResult.getMemberNameOrId(), exceptionMessageNodes);
} else {
groupByMessage(memberResult.getErrorMessage(), memberResult.getMemberNameOrId(), errorMessageNodes);
}
}
}
}
if (!memberCqNamesMap.isEmpty()) {
TabularResultData table = ResultBuilder.createTabularResultData();
Set<String> members = memberCqNamesMap.keySet();
for (String member : members) {
boolean isFirst = true;
List<String> cqNames = memberCqNamesMap.get(member);
for (String cqName : cqNames) {
if (isFirst) {
isFirst = false;
table.accumulate(CliStrings.LIST_DURABLE_CQS__MEMBER, member);
} else {
table.accumulate(CliStrings.LIST_DURABLE_CQS__MEMBER, "");
}
table.accumulate(CliStrings.LIST_DURABLE_CQS__NAME, cqName);
}
}
result = ResultBuilder.buildResult(table);
} else {
String errorHeader = CliStrings.format(CliStrings.LIST_DURABLE_CQS__FAILURE__HEADER, durableClientId);
result = ResultBuilder.buildResult(buildFailureData(null, exceptionMessageNodes, errorMessageNodes, errorHeader));
}
} catch (Exception e) {
result = ResultBuilder.createGemFireErrorResult(e.getMessage());
}
return result;
}
Aggregations