Search in sources :

Example 31 with CompositeResultData

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);
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 32 with 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);
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 33 with CompositeResultData

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));
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) VM(org.apache.geode.test.dunit.VM) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Ignore(org.junit.Ignore) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 34 with CompositeResultData

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));
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 35 with CompositeResultData

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;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) Result(org.apache.geode.management.cli.Result) ObjectName(javax.management.ObjectName) Entry(java.util.Map.Entry) ManagementService(org.apache.geode.management.ManagementService) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Aggregations

CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)49 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)39 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)30 DistributedMember (org.apache.geode.distributed.DistributedMember)15 InternalCache (org.apache.geode.internal.cache.InternalCache)14 Result (org.apache.geode.management.cli.Result)14 CliMetaData (org.apache.geode.management.cli.CliMetaData)13 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)13 CliCommand (org.springframework.shell.core.annotation.CliCommand)13 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)12 HashSet (java.util.HashSet)10 ArrayList (java.util.ArrayList)9 ObjectName (javax.management.ObjectName)9 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)9 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)8 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)8 Test (org.junit.Test)8 List (java.util.List)6 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)6