Search in sources :

Example 1 with SubscriptionQueueSizeResult

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

the class GetSubscriptionQueueSizeFunction method execute.

@Override
public void execute(FunctionContext context) {
    final Cache cache = CliUtil.getCacheIfExists();
    final String memberNameOrId = CliUtil.getMemberNameOrId(cache.getDistributedSystem().getDistributedMember());
    String[] args = (String[]) context.getArguments();
    String durableClientId = null, cqName = null;
    SubscriptionQueueSizeResult result = new SubscriptionQueueSizeResult(memberNameOrId);
    durableClientId = args[0];
    cqName = args[1];
    try {
        CacheClientNotifier cacheClientNotifier = CacheClientNotifier.getInstance();
        if (cacheClientNotifier != null) {
            CacheClientProxy cacheClientProxy = cacheClientNotifier.getClientProxy(durableClientId);
            // Check if the client is present or not
            if (cacheClientProxy != null) {
                if (cqName != null && !cqName.isEmpty()) {
                    CqService cqService = cacheClientProxy.getCache().getCqService();
                    if (cqService != null) {
                        CqQuery cqQuery = cqService.getClientCqFromServer(cacheClientProxy.getProxyID(), cqName);
                        if (cqQuery != null) {
                            CqQueryVsdStats cqVsdStats = ((InternalCqQuery) cqQuery).getVsdStats();
                            if (cqVsdStats != null) {
                                long queueSize = cqVsdStats.getNumHAQueuedEvents();
                                result.setSubscriptionQueueSize(queueSize);
                            } else {
                                result.setErrorMessage(CliStrings.format(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE_CQ_STATS_NOT_FOUND, durableClientId, cqName));
                            }
                        } else {
                            result.setErrorMessage(CliStrings.format(CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE_CQ_NOT_FOUND, durableClientId, cqName));
                        }
                    } else {
                        result.setErrorMessage(CliStrings.COUNT_DURABLE_CQ_EVENTS__NO__CQS__REGISTERED);
                    }
                } else {
                    result.setSubscriptionQueueSize(cacheClientNotifier.getDurableClientHAQueueSize(durableClientId));
                }
            } 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);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) InternalCqQuery(org.apache.geode.cache.query.internal.cq.InternalCqQuery) CqQuery(org.apache.geode.cache.query.CqQuery) SubscriptionQueueSizeResult(org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult) CqService(org.apache.geode.cache.query.internal.cq.CqService) Cache(org.apache.geode.cache.Cache) CqQueryVsdStats(org.apache.geode.cache.query.internal.CqQueryVsdStats)

Example 2 with SubscriptionQueueSizeResult

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

the class DurableClientCommands method buildTableResultForQueueSize.

private Result buildTableResultForQueueSize(List<SubscriptionQueueSizeResult> results, String queueSizeColumnName) {
    Result result = null;
    boolean failure = true;
    Map<String, List<String>> failureMap = new HashMap<String, List<String>>();
    Map<String, Long> memberQueueSizeTable = new TreeMap<String, Long>();
    /***
     * Aggregate the results from the members
     */
    for (SubscriptionQueueSizeResult memberResult : results) {
        if (memberResult.isSuccessful()) {
            failure = false;
            memberResult.getSubscriptionQueueSize();
            memberQueueSizeTable.put(memberResult.getMemberNameOrId(), memberResult.getSubscriptionQueueSize());
        } else {
            groupByMessage(memberResult.getErrorMessage(), memberResult.getMemberNameOrId(), failureMap);
        }
    }
    if (!failure) {
        TabularResultData table = ResultBuilder.createTabularResultData();
        Set<String> members = memberQueueSizeTable.keySet();
        for (String member : members) {
            long queueSize = memberQueueSizeTable.get(member);
            table.accumulate(CliStrings.COUNT_DURABLE_CQ_EVENTS__MEMBER, member);
            table.accumulate(queueSizeColumnName, queueSize);
        }
        result = ResultBuilder.buildResult(table);
    } else {
        ErrorResultData erd = ResultBuilder.createErrorResultData();
        buildErrorResult(erd, failureMap);
        result = ResultBuilder.buildResult(erd);
    }
    return result;
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) 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) LinkedList(java.util.LinkedList) List(java.util.List) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) SubscriptionQueueSizeResult(org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult)

Example 3 with SubscriptionQueueSizeResult

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

the class DurableClientCommands method countDurableCqEvents.

@CliCommand(value = CliStrings.COUNT_DURABLE_CQ_EVENTS, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__HELP)
@CliMetaData(shellOnly = false)
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result countDurableCqEvents(@CliOption(key = CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID, mandatory = true, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CLIENT__ID__HELP) final String durableClientId, @CliOption(key = CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CQ__NAME, mandatory = false, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__DURABLE__CQ__NAME__HELP) final String cqName, @CliOption(key = CliStrings.COUNT_DURABLE_CQ_EVENTS__MEMBER, mandatory = false, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__MEMBER__HELP, optionContext = ConverterHint.MEMBERIDNAME) final String[] memberNameOrId, @CliOption(key = CliStrings.COUNT_DURABLE_CQ_EVENTS__GROUP, mandatory = false, help = CliStrings.COUNT_DURABLE_CQ_EVENTS__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 GetSubscriptionQueueSizeFunction(), params, targetMembers);
        final List<SubscriptionQueueSizeResult> funcResults = (List<SubscriptionQueueSizeResult>) rc.getResult();
        String queueSizeColumnName;
        if (cqName != null && !cqName.isEmpty()) {
            queueSizeColumnName = CliStrings.format(CliStrings.COUNT_DURABLE_CQ_EVENTS__SUBSCRIPTION__QUEUE__SIZE__CLIENT, cqName);
        } else {
            queueSizeColumnName = CliStrings.format(CliStrings.COUNT_DURABLE_CQ_EVENTS__SUBSCRIPTION__QUEUE__SIZE__CLIENT, durableClientId);
        }
        result = buildTableResultForQueueSize(funcResults, queueSizeColumnName);
    } catch (Exception e) {
        result = ResultBuilder.createGemFireErrorResult(e.getMessage());
    }
    return result;
}
Also used : GetSubscriptionQueueSizeFunction(org.apache.geode.management.internal.cli.functions.GetSubscriptionQueueSizeFunction) DistributedMember(org.apache.geode.distributed.DistributedMember) LinkedList(java.util.LinkedList) List(java.util.List) SubscriptionQueueSizeResult(org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult) 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)

Aggregations

SubscriptionQueueSizeResult (org.apache.geode.management.internal.cli.domain.SubscriptionQueueSizeResult)3 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Result (org.apache.geode.management.cli.Result)2 DurableCqNamesResult (org.apache.geode.management.internal.cli.domain.DurableCqNamesResult)2 MemberResult (org.apache.geode.management.internal.cli.domain.MemberResult)2 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 Cache (org.apache.geode.cache.Cache)1 CqQuery (org.apache.geode.cache.query.CqQuery)1 CqQueryVsdStats (org.apache.geode.cache.query.internal.CqQueryVsdStats)1 CqService (org.apache.geode.cache.query.internal.cq.CqService)1 InternalCqQuery (org.apache.geode.cache.query.internal.cq.InternalCqQuery)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 CacheClientNotifier (org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier)1 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 GetSubscriptionQueueSizeFunction (org.apache.geode.management.internal.cli.functions.GetSubscriptionQueueSizeFunction)1 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)1 ErrorResultData (org.apache.geode.management.internal.cli.result.ErrorResultData)1