Search in sources :

Example 1 with ListDurableCqNamesFunction

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;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) SubscriptionQueueSizeResult(org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult) DurableCqNamesResult(org.apache.geode.management.internal.cli.domain.DurableCqNamesResult) Result(org.apache.geode.management.cli.Result) MemberResult(org.apache.geode.management.internal.cli.domain.MemberResult) DurableCqNamesResult(org.apache.geode.management.internal.cli.domain.DurableCqNamesResult) DistributedMember(org.apache.geode.distributed.DistributedMember) ListDurableCqNamesFunction(org.apache.geode.management.internal.cli.functions.ListDurableCqNamesFunction) LinkedList(java.util.LinkedList) List(java.util.List) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 Result (org.apache.geode.management.cli.Result)1 DurableCqNamesResult (org.apache.geode.management.internal.cli.domain.DurableCqNamesResult)1 MemberResult (org.apache.geode.management.internal.cli.domain.MemberResult)1 SubscriptionQueueSizeResult (org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult)1 ListDurableCqNamesFunction (org.apache.geode.management.internal.cli.functions.ListDurableCqNamesFunction)1 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)1 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)1 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)1 CliCommand (org.springframework.shell.core.annotation.CliCommand)1