Search in sources :

Example 1 with MemberResult

use of org.apache.geode.management.internal.cli.domain.MemberResult in project geode by apache.

the class DurableClientCommands method closeDurableCqs.

@CliCommand(value = CliStrings.CLOSE_DURABLE_CQS, help = CliStrings.CLOSE_DURABLE_CQS__HELP)
@CliMetaData(shellOnly = false)
@ResourceOperation(resource = Resource.DATA, operation = Operation.MANAGE)
public Result closeDurableCqs(@CliOption(key = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__DURABLE__CLIENT__ID__HELP) final String durableClientId, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__NAME, mandatory = true, help = CliStrings.CLOSE_DURABLE_CQS__NAME__HELP) final String cqName, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__MEMBER, mandatory = false, help = CliStrings.CLOSE_DURABLE_CQS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, @CliOption(key = CliStrings.CLOSE_DURABLE_CQS__GROUP, mandatory = false, help = CliStrings.CLOSE_DURABLE_CQS__GROUP__HELP, optionContext = ConverterHint.MEMBERGROUP) final String[] group) {
    Result result = null;
    try {
        Set<DistributedMember> targetMembers = CliUtil.findMembers(group, memberNameOrId);
        if (targetMembers.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.NO_MEMBERS_FOUND_MESSAGE);
        }
        String[] params = new String[2];
        params[0] = durableClientId;
        params[1] = cqName;
        final ResultCollector<?, ?> rc = CliUtil.executeFunction(new CloseDurableCqFunction(), params, targetMembers);
        final List<MemberResult> results = (List<MemberResult>) rc.getResult();
        String failureHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__FAILURE__HEADER, cqName, durableClientId);
        String successHeader = CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__SUCCESS, cqName, durableClientId);
        result = buildResult(results, successHeader, failureHeader);
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    return result;
}
Also used : CloseDurableCqFunction(org.apache.geode.management.internal.cli.functions.CloseDurableCqFunction) MemberResult(org.apache.geode.management.internal.cli.domain.MemberResult) DistributedMember(org.apache.geode.distributed.DistributedMember) LinkedList(java.util.LinkedList) List(java.util.List) 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) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 2 with MemberResult

use of org.apache.geode.management.internal.cli.domain.MemberResult in project geode by apache.

the class DurableClientCommands method buildResult.

private Result buildResult(List<MemberResult> results, String successHeader, String failureHeader) {
    Result result = null;
    boolean failure = true;
    boolean partialFailure = false;
    Map<String, List<String>> errorMap = new HashMap<String, List<String>>();
    Map<String, List<String>> successMap = new HashMap<String, List<String>>();
    Map<String, List<String>> exceptionMap = new HashMap<String, List<String>>();
    /***
     * Aggregate the results from the members
     */
    for (MemberResult memberResult : results) {
        if (memberResult.isSuccessful()) {
            failure = false;
            groupByMessage(memberResult.getSuccessMessage(), memberResult.getMemberNameOrId(), successMap);
        } else {
            if (memberResult.isOpPossible()) {
                partialFailure = true;
                groupByMessage(memberResult.getExceptionMessage(), memberResult.getMemberNameOrId(), exceptionMap);
            } else {
                groupByMessage(memberResult.getErrorMessage(), memberResult.getMemberNameOrId(), errorMap);
            }
        }
    }
    if (!failure && !partialFailure) {
        result = ResultBuilder.buildResult(buildSuccessData(successMap));
    } else {
        result = ResultBuilder.buildResult(buildFailureData(successMap, exceptionMap, errorMap, failureHeader));
    }
    return result;
}
Also used : HashMap(java.util.HashMap) MemberResult(org.apache.geode.management.internal.cli.domain.MemberResult) LinkedList(java.util.LinkedList) List(java.util.List) 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)

Example 3 with MemberResult

use of org.apache.geode.management.internal.cli.domain.MemberResult in project geode by apache.

the class CloseDurableClientFunction method execute.

@Override
public void execute(FunctionContext context) {
    String durableClientId = (String) context.getArguments();
    final Cache cache = CliUtil.getCacheIfExists();
    final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    MemberResult memberResult = new MemberResult(memberNameOrId);
    try {
        CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance();
        if (cacheClientNotifier != null) {
            CacheClientProxy ccp = cacheClientNotifier.getClientProxy(durableClientId);
            if (ccp != null) {
                boolean isClosed = cacheClientNotifier.closeDurableClientProxy(durableClientId);
                if (isClosed) {
                    memberResult.setSuccessMessage(CliStrings.format(CliStrings.CLOSE_DURABLE_CLIENTS__SUCCESS, durableClientId));
                } else {
                    memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
                }
            } else {
                memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
            }
        } else {
            memberResult.setErrorMessage(CliStrings.NO_CLIENT_FOUND);
        }
    } catch (Exception e) {
        memberResult.setExceptionMessage(e.getMessage());
    } finally {
        context.getResultSender().lastResult(memberResult);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) MemberResult(org.apache.geode.management.internal.cli.domain.MemberResult) Cache(org.apache.geode.cache.Cache)

Example 4 with MemberResult

use of org.apache.geode.management.internal.cli.domain.MemberResult in project geode by apache.

the class CloseDurableCqFunction method execute.

@Override
public void execute(FunctionContext context) {
    final Cache cache = CliUtil.getCacheIfExists();
    final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance();
    String[] args = (String[]) context.getArguments();
    String durableClientId = args[0];
    String cqName = args[1];
    MemberResult memberResult = new MemberResult(memberNameOrId);
    try {
        if (cacheClientNotifier != null) {
            CacheClientProxy cacheClientProxy = cacheClientNotifier.getClientProxy(durableClientId);
            if (cacheClientProxy != null) {
                if (cacheClientNotifier.closeClientCq(durableClientId, cqName)) {
                    memberResult.setSuccessMessage(CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__SUCCESS, cqName, durableClientId));
                } else {
                    memberResult.setErrorMessage(CliStrings.format(CliStrings.CLOSE_DURABLE_CQS__UNABLE__TO__CLOSE__CQ, cqName, durableClientId));
                }
            } else {
                memberResult.setErrorMessage(CliStrings.format(CliStrings.NO_CLIENT_FOUND_WITH_CLIENT_ID, durableClientId));
            }
        } else {
            memberResult.setErrorMessage(CliStrings.NO_CLIENT_FOUND);
        }
    } catch (Exception e) {
        memberResult.setExceptionMessage(e.getMessage());
    } finally {
        context.getResultSender().lastResult(memberResult);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) MemberResult(org.apache.geode.management.internal.cli.domain.MemberResult) Cache(org.apache.geode.cache.Cache)

Example 5 with MemberResult

use of org.apache.geode.management.internal.cli.domain.MemberResult 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

MemberResult (org.apache.geode.management.internal.cli.domain.MemberResult)7 LinkedList (java.util.LinkedList)5 List (java.util.List)5 Result (org.apache.geode.management.cli.Result)5 DurableCqNamesResult (org.apache.geode.management.internal.cli.domain.DurableCqNamesResult)5 SubscriptionQueueSizeResult (org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult)5 HashMap (java.util.HashMap)3 DistributedMember (org.apache.geode.distributed.DistributedMember)3 CliMetaData (org.apache.geode.management.cli.CliMetaData)3 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)3 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)3 CliCommand (org.springframework.shell.core.annotation.CliCommand)3 TreeMap (java.util.TreeMap)2 Cache (org.apache.geode.cache.Cache)2 CacheClientNotifier (org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier)2 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)2 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)2 CloseDurableClientFunction (org.apache.geode.management.internal.cli.functions.CloseDurableClientFunction)1 CloseDurableCqFunction (org.apache.geode.management.internal.cli.functions.CloseDurableCqFunction)1 ListDurableCqNamesFunction (org.apache.geode.management.internal.cli.functions.ListDurableCqNamesFunction)1