use of org.apache.geode.management.internal.cli.domain.DurableCqNamesResult in project geode by apache.
the class ListDurableCqNamesFunction method execute.
public void execute(final FunctionContext context) {
final Cache cache = getCache();
final DistributedMember member = cache.getDistributedSystem().getDistributedMember();
String memberNameOrId = CliUtil.getMemberNameOrId(member);
DurableCqNamesResult result = new DurableCqNamesResult(memberNameOrId);
String durableClientId = (String) context.getArguments();
try {
CacheClientNotifier ccn = CacheClientNotifier.getInstance();
if (ccn != null) {
CacheClientProxy ccp = ccn.getClientProxy(durableClientId);
if (ccp != null) {
CqService cqService = ccp.getCache().getCqService();
if (cqService != null && cqService.isRunning()) {
List<String> durableCqNames = cqService.getAllDurableClientCqs(ccp.getProxyID());
if (durableCqNames != null && !durableCqNames.isEmpty()) {
result.setCqNamesList(new ArrayList<String>(durableCqNames));
} else {
result.setErrorMessage(CliStrings.format(CliStrings.LIST_DURABLE_CQS__NO__CQS__FOR__CLIENT, durableClientId));
}
} else {
result.setErrorMessage(CliStrings.LIST_DURABLE_CQS__NO__CQS__REGISTERED);
}
} else {
result.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
}
} else {
result.setErrorMessage(CliStrings.NO_CLIENT_FOUND);
}
} catch (Exception e) {
result.setExceptionMessage(e.getMessage());
} finally {
context.getResultSender().lastResult(result);
}
}
use of org.apache.geode.management.internal.cli.domain.DurableCqNamesResult 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