Search in sources :

Example 1 with ClientHealthStatus

use of org.apache.geode.management.ClientHealthStatus in project geode by apache.

the class ClientCommands method describeClient.

@CliCommand(value = CliStrings.DESCRIBE_CLIENT, help = CliStrings.DESCRIBE_CLIENT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_CLIENT })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeClient(@CliOption(key = CliStrings.DESCRIBE_CLIENT__ID, mandatory = true, help = CliStrings.DESCRIBE_CLIENT__ID__HELP) String clientId) {
    Result result = null;
    if (clientId.startsWith("\"")) {
        clientId = clientId.substring(1);
    }
    if (clientId.endsWith("\"")) {
        clientId = clientId.substring(0, clientId.length() - 2);
    }
    if (clientId.endsWith("\";")) {
        clientId = clientId.substring(0, clientId.length() - 2);
    }
    try {
        CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
        SectionResultData sectionResult = compositeResultData.addSection("InfoSection");
        InternalCache cache = getCache();
        ManagementService service = ManagementService.getExistingManagementService(cache);
        ObjectName[] cacheServers = service.getDistributedSystemMXBean().listCacheServerObjectNames();
        if (cacheServers.length == 0) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST));
        }
        ClientHealthStatus clientHealthStatus = null;
        for (ObjectName objName : cacheServers) {
            CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class);
            List<String> listOfClient = new ArrayList<String>(Arrays.asList((String[]) serverMbean.getClientIds()));
            if (listOfClient.contains(clientId)) {
                if (clientHealthStatus == null) {
                    try {
                        clientHealthStatus = serverMbean.showClientStats(clientId);
                        if (clientHealthStatus == null) {
                            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_STATS_FOR_CLIENT_0, clientId));
                        }
                    } catch (Exception eee) {
                        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_STATS_FOR_CLIENT_0_REASON_1, clientId, eee.getMessage()));
                    }
                }
            }
        }
        if (clientHealthStatus == null) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT__CLIENT__ID__NOT__FOUND__0, clientId));
        }
        Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
        String isDurable = null;
        List<String> primaryServers = new ArrayList<String>();
        List<String> secondaryServers = new ArrayList<String>();
        if (dsMembers.size() > 0) {
            ContunuousQueryFunction contunuousQueryFunction = new ContunuousQueryFunction();
            FunctionService.registerFunction(contunuousQueryFunction);
            List<?> resultList = (List<?>) CliUtil.executeFunction(contunuousQueryFunction, clientId, dsMembers).getResult();
            for (int i = 0; i < resultList.size(); i++) {
                try {
                    Object object = resultList.get(i);
                    if (object instanceof Throwable) {
                        LogWrapper.getInstance().warning("Exception in Describe Client " + ((Throwable) object).getMessage(), ((Throwable) object));
                        continue;
                    }
                    if (object != null) {
                        ClientInfo objectResult = (ClientInfo) object;
                        isDurable = objectResult.isDurable;
                        if (objectResult.primaryServer != null && objectResult.primaryServer.length() > 0) {
                            if (primaryServers.size() == 0) {
                                primaryServers.add(objectResult.primaryServer);
                            } else {
                                primaryServers.add(" ,");
                                primaryServers.add(objectResult.primaryServer);
                            }
                        }
                        if (objectResult.secondaryServer != null && objectResult.secondaryServer.length() > 0) {
                            if (secondaryServers.size() == 0) {
                                secondaryServers.add(objectResult.secondaryServer);
                            } else {
                                secondaryServers.add(" ,");
                                secondaryServers.add(objectResult.secondaryServer);
                            }
                        }
                    }
                } catch (Exception e) {
                    LogWrapper.getInstance().info(CliStrings.DESCRIBE_CLIENT_ERROR_FETCHING_STATS_0 + " :: " + CliUtil.stackTraceAsString(e));
                    return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_ERROR_FETCHING_STATS_0, e.getMessage()));
                }
            }
            buildTableResult(sectionResult, clientHealthStatus, isDurable, primaryServers, secondaryServers);
            result = ResultBuilder.buildResult(compositeResultData);
        } else {
            return ResultBuilder.createGemFireErrorResult(CliStrings.DESCRIBE_CLIENT_NO_MEMBERS);
        }
    } catch (Exception e) {
        LogWrapper.getInstance().info("Error in decribe clients. stack trace" + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_CLIENT_0, e.getMessage()));
    }
    LogWrapper.getInstance().info("decribe client result " + result);
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) ArrayList(java.util.ArrayList) ContunuousQueryFunction(org.apache.geode.management.internal.cli.functions.ContunuousQueryFunction) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) Result(org.apache.geode.management.cli.Result) ObjectName(javax.management.ObjectName) ManagementService(org.apache.geode.management.ManagementService) ClientHealthStatus(org.apache.geode.management.ClientHealthStatus) DistributedMember(org.apache.geode.distributed.DistributedMember) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ArrayList(java.util.ArrayList) List(java.util.List) ClientInfo(org.apache.geode.management.internal.cli.functions.ContunuousQueryFunction.ClientInfo) 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 ClientHealthStatus

use of org.apache.geode.management.ClientHealthStatus in project geode by apache.

the class CacheServerBridge method showAllClientStats.

public ClientHealthStatus[] showAllClientStats() throws Exception {
    try {
        List<ClientHealthStatus> clientHealthStatusList = null;
        Map<String, ClientConnInfo> uniqueClientIds = getUniqueClientIds();
        if (!uniqueClientIds.isEmpty()) {
            clientHealthStatusList = new ArrayList<ClientHealthStatus>();
            for (Map.Entry<String, ClientConnInfo> p : uniqueClientIds.entrySet()) {
                ClientHealthStatus status = getClientHealthStatus(p.getValue());
                if (status != null) {
                    clientHealthStatusList.add(status);
                }
            }
            ClientHealthStatus[] statusArr = new ClientHealthStatus[clientHealthStatusList.size()];
            return clientHealthStatusList.toArray(statusArr);
        }
        return new ClientHealthStatus[0];
    } finally {
        CacheServerBridge.clientVersion.set(null);
    }
}
Also used : ClientHealthStatus(org.apache.geode.management.ClientHealthStatus) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ClientHealthStatus

use of org.apache.geode.management.ClientHealthStatus in project geode by apache.

the class CacheServerBridge method showClientStats.

public ClientHealthStatus showClientStats(String clientId) throws Exception {
    try {
        Map<String, ClientConnInfo> uniqueClientIds = getUniqueClientIds();
        ClientConnInfo clientConnInfo = uniqueClientIds.get(clientId);
        ClientHealthStatus status = getClientHealthStatus(clientConnInfo);
        return status;
    } finally {
        CacheServerBridge.clientVersion.set(null);
    }
}
Also used : ClientHealthStatus(org.apache.geode.management.ClientHealthStatus)

Example 4 with ClientHealthStatus

use of org.apache.geode.management.ClientHealthStatus 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 5 with ClientHealthStatus

use of org.apache.geode.management.ClientHealthStatus in project geode by apache.

the class ClientCommandsDUnitTest method waitForMbean.

public void waitForMbean() {
    final VM manager = Host.getHost(0).getVM(0);
    final VM server1 = Host.getHost(0).getVM(1);
    final DistributedMember serverMember = getMember(server1);
    assertNotNull(serverMember);
    manager.invoke(() -> {
        Awaitility.waitAtMost(2 * 60, TimeUnit.SECONDS).pollDelay(2, TimeUnit.SECONDS).until(() -> {
            final SystemManagementService service = (SystemManagementService) ManagementService.getManagementService(getCache());
            if (service == null) {
                getLogWriter().info("waitForMbean Still probing for service");
                return false;
            } else {
                final ObjectName cacheServerMBeanName = service.getCacheServerMBeanName(port0, serverMember);
                CacheServerMXBean bean = service.getMBeanProxy(cacheServerMBeanName, CacheServerMXBean.class);
                try {
                    ClientHealthStatus stats = bean.showClientStats(bean.getClientIds()[0]);
                    Map<String, String> poolStats = stats.getPoolStats();
                    if (poolStats.size() > 0) {
                        Iterator<Entry<String, String>> it = poolStats.entrySet().iterator();
                        while (it.hasNext()) {
                            Entry<String, String> entry = it.next();
                            String poolStatsStr = entry.getValue();
                            String[] str = poolStatsStr.split(";");
                            int numCqs = Integer.parseInt(str[3].substring(str[3].indexOf("=") + 1));
                            if (numCqs == 3) {
                                return true;
                            }
                        }
                    }
                    return false;
                } catch (Exception e) {
                    LogWrapper.getInstance().warning("waitForMbean Exception in waitForMbean ::: " + CliUtil.stackTraceAsString(e));
                }
                return false;
            }
        });
    });
}
Also used : CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName) Entry(java.util.Map.Entry) ClientHealthStatus(org.apache.geode.management.ClientHealthStatus) VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember)

Aggregations

ClientHealthStatus (org.apache.geode.management.ClientHealthStatus)5 ObjectName (javax.management.ObjectName)2 DistributedMember (org.apache.geode.distributed.DistributedMember)2 CacheServerMXBean (org.apache.geode.management.CacheServerMXBean)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Region (org.apache.geode.cache.Region)1 CqService (org.apache.geode.cache.query.internal.cq.CqService)1 ServerCQ (org.apache.geode.cache.query.internal.cq.ServerCQ)1 ClientHealthMonitoringRegion (org.apache.geode.internal.admin.ClientHealthMonitoringRegion)1 ClientHealthStats (org.apache.geode.internal.admin.remote.ClientHealthStats)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 CacheClientProxy (org.apache.geode.internal.cache.tier.sockets.CacheClientProxy)1 ClientProxyMembershipID (org.apache.geode.internal.cache.tier.sockets.ClientProxyMembershipID)1 ManagementService (org.apache.geode.management.ManagementService)1 CliMetaData (org.apache.geode.management.cli.CliMetaData)1 Result (org.apache.geode.management.cli.Result)1