Search in sources :

Example 6 with CacheClientProxy

use of org.apache.geode.internal.cache.tier.sockets.CacheClientProxy in project geode by apache.

the class CacheServerBridge method getClientHealthStatus.

private ClientHealthStatus getClientHealthStatus(ClientConnInfo connInfo) {
    ClientProxyMembershipID proxyId = connInfo.getClientId();
    CacheClientProxy proxy = CacheClientNotifier.getInstance().getClientProxy(proxyId);
    if (proxy != null && !proxy.isConnected() && !proxyId.isDurable()) {
        return null;
    }
    CacheServerBridge.clientVersion.set(getClientVersion(connInfo));
    int clientCQCount = 0;
    CqService cqService = cache.getCqService();
    if (cqService != null) {
        List<ServerCQ> cqs = cqService.getAllClientCqs(proxyId);
        clientCQCount = cqs.size();
    }
    ClientHealthStatus status = new ClientHealthStatus();
    Region clientHealthMonitoringRegion = ClientHealthMonitoringRegion.getInstance(this.cache);
    String clientName = proxyId.getDSMembership();
    status.setClientId(connInfo.toString());
    status.setName(clientName);
    status.setHostName(connInfo.getHostName());
    status.setClientCQCount(clientCQCount);
    // Only available for clients having subscription enabled true
    if (proxy != null) {
        status.setUpTime(proxy.getUpTime());
        status.setQueueSize(proxy.getQueueSizeStat());
        status.setConnected(proxy.isConnected());
        status.setSubscriptionEnabled(true);
    } else {
        status.setConnected(true);
        status.setSubscriptionEnabled(false);
    }
    ClientHealthStats stats = (ClientHealthStats) clientHealthMonitoringRegion.get(clientName);
    if (stats != null) {
        status.setCpus(stats.getCpus());
        status.setNumOfCacheListenerCalls(stats.getNumOfCacheListenerCalls());
        status.setNumOfGets(stats.getNumOfGets());
        status.setNumOfMisses(stats.getNumOfMisses());
        status.setNumOfPuts(stats.getNumOfPuts());
        status.setNumOfThreads(stats.getNumOfThreads());
        status.setProcessCpuTime(stats.getProcessCpuTime());
        status.setPoolStats(stats.getPoolStats());
    }
    return status;
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) ClientHealthStatus(org.apache.geode.management.ClientHealthStatus) Region(org.apache.geode.cache.Region) ClientHealthMonitoringRegion(org.apache.geode.internal.admin.ClientHealthMonitoringRegion) ServerCQ(org.apache.geode.cache.query.internal.cq.ServerCQ) CqService(org.apache.geode.cache.query.internal.cq.CqService) ClientHealthStats(org.apache.geode.internal.admin.remote.ClientHealthStats)

Example 7 with CacheClientProxy

use of org.apache.geode.internal.cache.tier.sockets.CacheClientProxy in project geode by apache.

the class CacheServerBridge method getClientVersion.

public Version getClientVersion(ClientConnInfo connInfo) {
    InternalCache cache = (InternalCache) CacheFactory.getAnyInstance();
    if (cache.getCacheServers().size() == 0) {
        return null;
    }
    CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().iterator().next();
    if (server == null) {
        return null;
    }
    AcceptorImpl acceptorImpl = server.getAcceptor();
    if (acceptorImpl == null) {
        return null;
    }
    ServerConnection[] serverConnections = acceptorImpl.getAllServerConnectionList();
    boolean flag = false;
    if (connInfo.toString().contains("primary=true")) {
        flag = true;
    }
    for (ServerConnection conn : serverConnections) {
        ClientProxyMembershipID cliIdFrmProxy = conn.getProxyID();
        ClientConnInfo cci = new ClientConnInfo(conn.getProxyID(), conn.getSocketHost(), conn.getSocketPort(), flag);
        if (connInfo.toString().equals(cci.toString())) {
            return cliIdFrmProxy.getClientVersion();
        }
    }
    // check form ccp
    ClientProxyMembershipID proxyId = connInfo.getClientId();
    CacheClientProxy proxy = CacheClientNotifier.getInstance().getClientProxy(proxyId);
    if (proxy != null) {
        return proxy.getVersion();
    } else {
        return null;
    }
}
Also used : ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) InternalCache(org.apache.geode.internal.cache.InternalCache) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 8 with CacheClientProxy

use of org.apache.geode.internal.cache.tier.sockets.CacheClientProxy in project geode by apache.

the class ContunuousQueryFunction method execute.

@Override
public void execute(FunctionContext context) {
    try {
        String clientID = (String) context.getArguments();
        InternalCache cache = getCache();
        if (cache.getCacheServers().size() > 0) {
            CacheServerImpl server = (CacheServerImpl) cache.getCacheServers().iterator().next();
            if (server != null) {
                AcceptorImpl acceptorImpl = server.getAcceptor();
                if (acceptorImpl != null) {
                    CacheClientNotifier cacheClientNotifier = acceptorImpl.getCacheClientNotifier();
                    if (cacheClientNotifier != null) {
                        Collection<CacheClientProxy> cacheClientProxySet = cacheClientNotifier.getClientProxies();
                        ClientInfo clientInfo = null;
                        boolean foundClientinCCP = false;
                        Iterator<CacheClientProxy> it = cacheClientProxySet.iterator();
                        while (it.hasNext()) {
                            CacheClientProxy ccp = it.next();
                            if (ccp != null) {
                                String clientIdFromProxy = ccp.getProxyID().getDSMembership();
                                if (clientIdFromProxy != null && clientIdFromProxy.equals(clientID)) {
                                    foundClientinCCP = true;
                                    String durableId = ccp.getProxyID().getDurableId();
                                    boolean isPrimary = ccp.isPrimary();
                                    clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), (isPrimary == true ? cache.getDistributedSystem().getDistributedMember().getId() : ""), (isPrimary == false ? cache.getDistributedSystem().getDistributedMember().getId() : ""));
                                    break;
                                }
                            }
                        }
                        // try getting from server connections
                        if (foundClientinCCP == false) {
                            ServerConnection[] serverConnections = acceptorImpl.getAllServerConnectionList();
                            for (ServerConnection conn : serverConnections) {
                                ClientProxyMembershipID cliIdFrmProxy = conn.getProxyID();
                                if (clientID.equals(cliIdFrmProxy.getDSMembership())) {
                                    String durableId = cliIdFrmProxy.getDurableId();
                                    clientInfo = new ClientInfo((durableId != null && durableId.length() > 0 ? "Yes" : "No"), "N.A.", "N.A.");
                                }
                            }
                        }
                        context.getResultSender().lastResult(clientInfo);
                    }
                }
            }
        }
    } catch (Exception e) {
        context.getResultSender().lastResult("Exception in ContunuousQueryFunction =" + e.getMessage());
    }
    context.getResultSender().lastResult(null);
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) InternalCache(org.apache.geode.internal.cache.InternalCache) ServerConnection(org.apache.geode.internal.cache.tier.sockets.ServerConnection) ClientProxyMembershipID(org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID) AcceptorImpl(org.apache.geode.internal.cache.tier.sockets.AcceptorImpl) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl)

Example 9 with CacheClientProxy

use of org.apache.geode.internal.cache.tier.sockets.CacheClientProxy 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 10 with CacheClientProxy

use of org.apache.geode.internal.cache.tier.sockets.CacheClientProxy 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);
    }
}
Also used : CacheClientProxy(org.apache.geode.internal.cache.tier.sockets.CacheClientProxy) DurableCqNamesResult(org.apache.geode.management.internal.cli.domain.DurableCqNamesResult) CacheClientNotifier(org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier) DistributedMember(org.apache.geode.distributed.DistributedMember) CqService(org.apache.geode.cache.query.internal.cq.CqService) Cache(org.apache.geode.cache.Cache)

Aggregations

CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)24 CacheClientNotifier (org.apache.geode.internal.cache.tier.sockets.CacheClientNotifier)11 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)7 IOException (java.io.IOException)6 CqException (org.apache.geode.cache.query.CqException)5 LocalRegion (org.apache.geode.internal.cache.LocalRegion)5 Cache (org.apache.geode.cache.Cache)4 CqClosedException (org.apache.geode.cache.query.CqClosedException)4 CqExistsException (org.apache.geode.cache.query.CqExistsException)4 StringId (org.apache.geode.i18n.StringId)4 QueryException (org.apache.geode.cache.query.QueryException)3 RegionNotFoundException (org.apache.geode.cache.query.RegionNotFoundException)3 CqService (org.apache.geode.cache.query.internal.cq.CqService)3 CacheServerImpl (org.apache.geode.internal.cache.CacheServerImpl)3 AcceptorImpl (org.apache.geode.internal.cache.tier.sockets.AcceptorImpl)3 Part (org.apache.geode.internal.cache.tier.sockets.Part)3 AuthorizeRequest (org.apache.geode.internal.security.AuthorizeRequest)3 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 AttributesFactory (org.apache.geode.cache.AttributesFactory)2