use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class ScriptExecutionDetails method getResult.
Result getResult() {
CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
compositeResultData.setHeader("************************* Execution Summary ***********************\nScript file: " + filePath);
for (int i = 0; i < this.commandAndStatusList.size(); i++) {
int commandSrNo = i + 1;
SectionResultData section = compositeResultData.addSection("" + (i + 1));
CommandAndStatus commandAndStatus = commandAndStatusList.get(i);
section.addData("Command-" + String.valueOf(commandSrNo), commandAndStatus.command);
section.addData("Status", commandAndStatus.status);
if (commandAndStatus.status.equals("FAILED")) {
compositeResultData.setStatus(org.apache.geode.management.cli.Result.Status.ERROR);
}
if (i != this.commandAndStatusList.size()) {
section.setFooter(Gfsh.LINE_SEPARATOR);
}
}
return ResultBuilder.buildResult(compositeResultData);
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class ClientCommandsDUnitTest method verifyClientStats.
public void verifyClientStats(CommandResult commandResultForClient, String serverName) {
CompositeResultData resultData = (CompositeResultData) commandResultForClient.getResultData();
SectionResultData section = resultData.retrieveSection("InfoSection");
assertNotNull(section);
for (int i = 0; i < 1; i++) {
TabularResultData tableRsultData = section.retrieveTableByIndex(i);
getLogWriter().info("testDescribeClientWithServers getHeader=" + tableRsultData.getHeader());
assertNotNull(tableRsultData);
List<String> minConn = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_MIN_CONN);
List<String> maxConn = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_MAX_CONN);
List<String> redudancy = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_REDUDANCY);
List<String> numCqs = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_CQs);
getLogWriter().info("testDescribeClientWithServers getHeader numCqs =" + numCqs);
assertTrue(minConn.contains("1"));
assertTrue(maxConn.contains("-1"));
assertTrue(redudancy.contains("1"));
assertTrue(numCqs.contains("3"));
String puts = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_PUTS);
assertTrue(puts.equals("2"));
String queue = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_QUEUE_SIZE);
assertTrue(queue.equals("1"));
String calls = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_LISTNER_CALLS);
assertTrue(calls.equals("1"));
String primServer = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_PRIMARY_SERVERS);
assertTrue(primServer.equals(serverName));
String durable = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_DURABLE);
assertTrue(durable.equals("No"));
String threads = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_THREADS);
assertTrue(Integer.parseInt(threads) > 0);
String cpu = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_CPU);
assertTrue(Integer.parseInt(cpu) > 0);
String upTime = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_UP_TIME);
assertTrue(Integer.parseInt(upTime) >= 0);
String prcTime = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_PROCESS_CPU_TIME);
assertTrue(Long.parseLong(prcTime) > 0);
}
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class ClientCommandsDUnitTest method testDescribeClient.
@Ignore("disabled for unknown reason")
@Test
public void testDescribeClient() throws Exception {
setupSystem();
getLogWriter().info("testDescribeClient clientId=" + clientId);
assertNotNull(clientId);
String commandString = CliStrings.DESCRIBE_CLIENT + " --" + CliStrings.DESCRIBE_CLIENT__ID + "=\"" + clientId + "\"";
getLogWriter().info("testDescribeClient commandStr=" + commandString);
final VM server1 = Host.getHost(0).getVM(1);
String serverName = (String) server1.invoke("get distributed member Id", () -> getDistributedMemberId());
CommandResult commandResult = executeCommand(commandString);
getLogWriter().info("testDescribeClient commandResult=" + commandResult);
String resultAsString = commandResultToString(commandResult);
getLogWriter().info("testDescribeClient resultAsString=" + resultAsString);
assertTrue(Status.OK.equals(commandResult.getStatus()));
CompositeResultData resultData = (CompositeResultData) commandResult.getResultData();
SectionResultData section = resultData.retrieveSection("InfoSection");
assertNotNull(section);
TabularResultData tableRsultData = section.retrieveTable("Pool Stats For Pool Name = DEFAULT");
assertNotNull(tableRsultData);
List<String> minConn = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_MIN_CONN);
List<String> maxConn = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_MAX_CONN);
List<String> redudancy = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_REDUDANCY);
List<String> numCqs = tableRsultData.retrieveAllValues(CliStrings.DESCRIBE_CLIENT_CQs);
assertTrue(minConn.contains("1"));
assertTrue(maxConn.contains("-1"));
assertTrue(redudancy.contains("1"));
assertTrue(numCqs.contains("3"));
String puts = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_PUTS);
assertTrue(puts.equals("2"));
String queue = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_QUEUE_SIZE);
assertTrue(queue.equals("1"));
String calls = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_LISTNER_CALLS);
assertTrue(calls.equals("1"));
String primServer = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_PRIMARY_SERVERS);
assertTrue(primServer.equals(serverName));
String durable = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_DURABLE);
assertTrue(durable.equals("No"));
String threads = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_THREADS);
assertTrue(Integer.parseInt(threads) > 0);
String cpu = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_CPU);
assertTrue(Integer.parseInt(cpu) > 0);
String upTime = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_UP_TIME);
assertTrue(Integer.parseInt(upTime) >= 0);
String prcTime = section.retrieveString(CliStrings.DESCRIBE_CLIENT_COLUMN_PROCESS_CPU_TIME);
assertTrue(Long.parseLong(prcTime) > 0);
closeNonDurableClient(Host.getHost(0).getVM(2));
closeCacheServer(Host.getHost(0).getVM(1));
closeCacheServer(Host.getHost(0).getVM(3));
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class ClientCommandsDUnitTest method testListClientForServers.
@Test
public void testListClientForServers() throws Exception {
setupSystem3();
final VM manager = Host.getHost(0).getVM(0);
String commandString = CliStrings.LIST_CLIENTS;
System.out.println("testListClientForServers commandStr=" + commandString);
final VM server1 = Host.getHost(0).getVM(1);
final VM server2 = Host.getHost(0).getVM(3);
final DistributedMember serverMember = getMember(server1);
String[] clientIds = (String[]) manager.invoke("get client Ids", () -> {
final SystemManagementService service = (SystemManagementService) ManagementService.getManagementService(getCache());
final ObjectName cacheServerMBeanName = service.getCacheServerMBeanName(port0, serverMember);
CacheServerMXBean bean = service.getMBeanProxy(cacheServerMBeanName, CacheServerMXBean.class);
return bean.getClientIds();
});
String serverName1 = (String) server1.invoke("get distributed member Id", () -> getDistributedMemberId());
String serverName2 = (String) server2.invoke("get distributed member Id", () -> getDistributedMemberId());
CommandResult commandResult = executeCommand(commandString);
System.out.println("testListClientForServers commandResult=" + commandResult);
String resultAsString = commandResultToString(commandResult);
System.out.println("testListClientForServers resultAsString=" + resultAsString);
assertTrue(Status.OK.equals(commandResult.getStatus()));
CompositeResultData resultData = (CompositeResultData) commandResult.getResultData();
SectionResultData section = resultData.retrieveSection("section1");
assertNotNull(section);
TabularResultData tableRsultData = section.retrieveTable("TableForClientList");
assertNotNull(tableRsultData);
List<String> serverNames = tableRsultData.retrieveAllValues(CliStrings.LIST_CLIENT_COLUMN_SERVERS);
List<String> clientNames = tableRsultData.retrieveAllValues(CliStrings.LIST_CLIENT_COLUMN_Clients);
serverName1 = serverName1.replace(":", "-");
serverName2 = serverName2.replace(":", "-");
System.out.println("testListClientForServers serverNames : " + serverNames);
System.out.println("testListClientForServers serverName1 : " + serverName1);
System.out.println("testListClientForServers serverName2 : " + serverName2);
System.out.println("testListClientForServers clientNames : " + clientNames);
for (String client : clientIds) {
assertTrue(clientNames.contains(client));
}
for (String server : serverNames) {
assertTrue(server.contains(serverName1) || server.contains(serverName2));
}
closeNonDurableClient(Host.getHost(0).getVM(2));
closeCacheServer(Host.getHost(0).getVM(1));
closeCacheServer(Host.getHost(0).getVM(3));
}
use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.
the class ClientCommands method listClient.
@CliCommand(value = CliStrings.LIST_CLIENTS, help = CliStrings.LIST_CLIENT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_CLIENT })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result listClient() {
Result result = null;
try {
CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
SectionResultData section = compositeResultData.addSection("section1");
TabularResultData resultTable = section.addTable("TableForClientList");
String headerText = "ClientList";
resultTable = resultTable.setHeader(headerText);
InternalCache cache = getCache();
ManagementService service = ManagementService.getExistingManagementService(cache);
ObjectName[] cacheServers = service.getDistributedSystemMXBean().listCacheServerObjectNames();
if (cacheServers.length == 0) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST));
}
Map<String, List<String>> clientServerMap = new HashMap<String, List<String>>();
for (ObjectName objName : cacheServers) {
CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class);
String[] listOfClient = serverMbean.getClientIds();
if (listOfClient == null || listOfClient.length == 0) {
continue;
}
for (String clietName : listOfClient) {
String serverDetails = "member=" + objName.getKeyProperty("member") + ",port=" + objName.getKeyProperty("port");
if (clientServerMap.containsKey(clietName)) {
List<String> listServers = clientServerMap.get(clietName);
listServers.add(serverDetails);
} else {
List<String> listServer = new ArrayList<String>();
listServer.add(serverDetails);
clientServerMap.put(clietName, listServer);
}
}
}
if (clientServerMap.size() == 0) {
return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_COULD_NOT_RETRIEVE_CLIENT_LIST));
}
String memberSeparator = "; ";
Iterator<Entry<String, List<String>>> it = clientServerMap.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, List<String>> pairs = (Map.Entry<String, List<String>>) it.next();
String client = (String) pairs.getKey();
List<String> servers = (List<String>) pairs.getValue();
StringBuilder serverListForClient = new StringBuilder();
int serversSize = servers.size();
int i = 0;
for (String server : servers) {
serverListForClient.append(server);
if (i < serversSize - 1) {
serverListForClient.append(memberSeparator);
}
i++;
}
resultTable.accumulate(CliStrings.LIST_CLIENT_COLUMN_Clients, client);
resultTable.accumulate(CliStrings.LIST_CLIENT_COLUMN_SERVERS, serverListForClient.toString());
}
result = ResultBuilder.buildResult(compositeResultData);
} catch (Exception e) {
LogWrapper.getInstance().warning("Error in list clients. stack trace" + CliUtil.stackTraceAsString(e));
result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.LIST_CLIENT_COULD_NOT_RETRIEVE_CLIENT_LIST_0, e.getMessage()));
}
LogWrapper.getInstance().info("list client result " + result);
return result;
}
Aggregations