Search in sources :

Example 46 with CompositeResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData in project geode by apache.

the class WanCommandStatusDUnitTest method testGatewayReceiverStatus.

@Test
public void testGatewayReceiverStatus() {
    Integer lnPort = (Integer) vm1.invoke(() -> createFirstLocatorWithDSId(1));
    Properties props = getDistributedSystemProperties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "localhost[" + lnPort + "]");
    setUpJmxManagerOnVm0ThenConnect(props);
    Integer nyPort = (Integer) vm2.invoke(() -> createFirstRemoteLocator(2, lnPort));
    vm6.invoke(() -> createAndStartReceiver(nyPort));
    vm3.invoke(() -> createAndStartReceiver(lnPort));
    vm4.invoke(() -> createAndStartReceiver(lnPort));
    vm5.invoke(() -> createAndStartReceiver(lnPort));
    pause(10000);
    String command = CliStrings.STATUS_GATEWAYRECEIVER;
    CommandResult cmdResult = executeCommand(command);
    if (cmdResult != null) {
        String strCmdResult = commandResultToString(cmdResult);
        getLogWriter().info("testGatewayReceiverStatus : " + strCmdResult + ">>>>> ");
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        TabularResultData tableResultData = ((CompositeResultData) cmdResult.getResultData()).retrieveSection(CliStrings.SECTION_GATEWAY_RECEIVER_AVAILABLE).retrieveTable(CliStrings.TABLE_GATEWAY_RECEIVER);
        List<String> result_Status = tableResultData.retrieveAllValues(CliStrings.RESULT_STATUS);
        assertEquals(3, result_Status.size());
        assertFalse(result_Status.contains(CliStrings.GATEWAY_NOT_RUNNING));
        tableResultData = ((CompositeResultData) cmdResult.getResultData()).retrieveSection(CliStrings.SECTION_GATEWAY_RECEIVER_NOT_AVAILABLE).retrieveTable(CliStrings.TABLE_GATEWAY_RECEIVER);
        List<String> result_hosts = tableResultData.retrieveAllValues(CliStrings.RESULT_HOST_MEMBER);
        assertEquals(2, result_hosts.size());
    } else {
        fail("testGatewayReceiverStatus failed as did not get CommandResult");
    }
    vm3.invoke(() -> stopReceiver());
    vm4.invoke(() -> stopReceiver());
    vm5.invoke(() -> stopReceiver());
    pause(10000);
    command = CliStrings.STATUS_GATEWAYRECEIVER;
    cmdResult = executeCommand(command);
    if (cmdResult != null) {
        String strCmdResult = commandResultToString(cmdResult);
        getLogWriter().info("testGatewayReceiverStatus : " + strCmdResult + ">>>>> ");
        assertEquals(Result.Status.OK, cmdResult.getStatus());
        TabularResultData tableResultData = ((CompositeResultData) cmdResult.getResultData()).retrieveSection(CliStrings.SECTION_GATEWAY_RECEIVER_AVAILABLE).retrieveTable(CliStrings.TABLE_GATEWAY_RECEIVER);
        List<String> result_Status = tableResultData.retrieveAllValues(CliStrings.RESULT_STATUS);
        assertEquals(3, result_Status.size());
        assertFalse(result_Status.contains(CliStrings.GATEWAY_RUNNING));
        tableResultData = ((CompositeResultData) cmdResult.getResultData()).retrieveSection(CliStrings.SECTION_GATEWAY_RECEIVER_NOT_AVAILABLE).retrieveTable(CliStrings.TABLE_GATEWAY_RECEIVER);
        List<String> result_hosts = tableResultData.retrieveAllValues(CliStrings.RESULT_HOST_MEMBER);
        assertEquals(2, result_hosts.size());
    } else {
        fail("testGatewayReceiverStatus failed as did not get CommandResult");
    }
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) Properties(java.util.Properties) CommandResult(org.apache.geode.management.internal.cli.result.CommandResult) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 47 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 48 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 49 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)

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