Search in sources :

Example 1 with DistributedMember

use of org.apache.geode.distributed.DistributedMember 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)

Example 2 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class ClientCommandsDUnitTest method waitForListClientMbean3.

public void waitForListClientMbean3() {
    final VM manager = Host.getHost(0).getVM(0);
    final VM server1 = Host.getHost(0).getVM(1);
    final VM server2 = Host.getHost(0).getVM(3);
    final DistributedMember serverMember1 = getMember(server1);
    final DistributedMember serverMember2 = getMember(server2);
    assertNotNull(serverMember1);
    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("waitForListClientMbean3 Still probing for service");
                return false;
            } else {
                final ObjectName cacheServerMBeanName1 = service.getCacheServerMBeanName(port0, serverMember1);
                final ObjectName cacheServerMBeanName2 = service.getCacheServerMBeanName(port1, serverMember2);
                CacheServerMXBean bean1 = service.getMBeanProxy(cacheServerMBeanName1, CacheServerMXBean.class);
                CacheServerMXBean bean2 = service.getMBeanProxy(cacheServerMBeanName2, CacheServerMXBean.class);
                try {
                    if (bean1 != null && bean2 != null) {
                        if (bean1.getClientIds().length > 0 && bean2.getClientIds().length > 0) {
                            return true;
                        }
                    }
                    return false;
                } catch (Exception e) {
                    LogWrapper.getInstance().warning("waitForListClientMbean3 Exception in waitForListClientMbean ::: " + CliUtil.stackTraceAsString(e));
                }
                return false;
            }
        });
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName)

Example 3 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class ClientCommandsDUnitTest method waitForMixedClients.

public void waitForMixedClients() {
    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(5 * 60, TimeUnit.SECONDS).pollDelay(2, TimeUnit.SECONDS).until(() -> {
            try {
                final SystemManagementService service = (SystemManagementService) ManagementService.getManagementService(getCache());
                if (service == null) {
                    getLogWriter().info("waitForMixedClients Still probing for service");
                    return false;
                } else {
                    getLogWriter().info("waitForMixedClients 1");
                    final ObjectName cacheServerMBeanName = service.getCacheServerMBeanName(port0, serverMember);
                    getLogWriter().info("waitForMixedClients 2 cacheServerMBeanName " + cacheServerMBeanName);
                    CacheServerMXBean bean = service.getMBeanProxy(cacheServerMBeanName, CacheServerMXBean.class);
                    getLogWriter().info("waitForMixedClients 2 bean " + bean);
                    if (bean.getClientIds().length > 1) {
                        return true;
                    }
                }
            } catch (Exception e) {
                LogWrapper.getInstance().warning("waitForMixedClients Exception in waitForMbean ::: " + CliUtil.stackTraceAsString(e));
            }
            return false;
        });
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName)

Example 4 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class ClientCommandsDUnitTest method testListClient.

// GEODE-908: random ports, BindException, time sensitive, HeadlessGfsh
@Category(FlakyTest.class)
@Test
public void testListClient() throws Exception {
    setupSystemForListClient();
    final VM manager = Host.getHost(0).getVM(0);
    String commandString = CliStrings.LIST_CLIENTS;
    getLogWriter().info("testListClient commandStr=" + commandString);
    waitForListClientMbean();
    final VM server1 = Host.getHost(0).getVM(1);
    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 serverName = (String) server1.invoke("get distributed member Id", () -> getDistributedMemberId());
    CommandResult commandResult = executeCommand(commandString);
    getLogWriter().info("testListClient commandResult=" + commandResult);
    String resultAsString = commandResultToString(commandResult);
    getLogWriter().info("testListClient 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);
    getLogWriter().info("testListClients serverNames : " + serverNames);
    getLogWriter().info("testListClients clientNames : " + clientNames);
    assertEquals(2, serverNames.size());
    assertEquals(2, clientNames.size());
    assertTrue(clientNames.contains(clientIds[0]));
    assertTrue(clientNames.contains(clientIds[1]));
    serverName = serverName.replace(":", "-");
    getLogWriter().info("testListClients serverName : " + serverName);
    for (String str : serverNames) {
        assertTrue(str.contains(serverName));
    }
    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) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 5 with DistributedMember

use of org.apache.geode.distributed.DistributedMember in project geode by apache.

the class ClientCommandsDUnitTest method waitForNonSubCliMBean.

public void waitForNonSubCliMBean() {
    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(5 * 60, TimeUnit.SECONDS).pollDelay(2, TimeUnit.SECONDS).until(() -> {
            try {
                final SystemManagementService service = (SystemManagementService) ManagementService.getManagementService(getCache());
                if (service == null) {
                    getLogWriter().info("waitForNonSubScribedClientMBean Still probing for service");
                    return false;
                } else {
                    getLogWriter().info("waitForNonSubScribedClientMBean 1");
                    final ObjectName cacheServerMBeanName = service.getCacheServerMBeanName(port0, serverMember);
                    getLogWriter().info("waitForNonSubScribedClientMBean 2 cacheServerMBeanName " + cacheServerMBeanName);
                    CacheServerMXBean bean = service.getMBeanProxy(cacheServerMBeanName, CacheServerMXBean.class);
                    getLogWriter().info("waitForNonSubScribedClientMBean 2 bean " + bean);
                    if (bean.getClientIds().length > 0) {
                        return true;
                    }
                }
            } catch (Exception e) {
                LogWrapper.getInstance().warning("waitForNonSubScribedClientMBean Exception in waitForMbean ::: " + CliUtil.stackTraceAsString(e));
            }
            return false;
        });
    });
}
Also used : VM(org.apache.geode.test.dunit.VM) DistributedMember(org.apache.geode.distributed.DistributedMember) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) SystemManagementService(org.apache.geode.management.internal.SystemManagementService) ObjectName(javax.management.ObjectName)

Aggregations

DistributedMember (org.apache.geode.distributed.DistributedMember)360 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)120 Test (org.junit.Test)109 HashSet (java.util.HashSet)83 InternalCache (org.apache.geode.internal.cache.InternalCache)83 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)82 ArrayList (java.util.ArrayList)64 VM (org.apache.geode.test.dunit.VM)60 CliCommand (org.springframework.shell.core.annotation.CliCommand)59 CliMetaData (org.apache.geode.management.cli.CliMetaData)57 Result (org.apache.geode.management.cli.Result)56 Set (java.util.Set)49 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)49 List (java.util.List)48 Cache (org.apache.geode.cache.Cache)47 Region (org.apache.geode.cache.Region)42 HashMap (java.util.HashMap)39 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)39 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)39 FunctionException (org.apache.geode.cache.execute.FunctionException)37