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;
}
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);
}
}
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);
}
}
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;
}
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;
}
});
});
}
Aggregations