Search in sources :

Example 21 with SectionResultData

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

the class GemfireDataCommandsDUnitTest method validateResult.

private void validateResult(CommandResult cmdResult, boolean expected) {
    if (ResultData.TYPE_COMPOSITE.equals(cmdResult.getType())) {
        CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
        SectionResultData section = rd.retrieveSectionByIndex(0);
        boolean result = (Boolean) section.retrieveObject("Result");
        assertEquals(expected, result);
    } else
        fail("Expected CompositeResult Returned Result Type " + cmdResult.getType());
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 22 with SectionResultData

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

the class GemfireDataCommandsDUnitTest method validateSelectResult.

private void validateSelectResult(CommandResult cmdResult, boolean expectedFlag, int expectedRows, String[] cols) {
    if (ResultData.TYPE_COMPOSITE.equals(cmdResult.getType())) {
        CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
        SectionResultData section = rd.retrieveSectionByIndex(0);
        boolean result = (Boolean) section.retrieveObject("Result");
        assertEquals(expectedFlag, result);
        if (expectedFlag && expectedRows != -1) {
            int rowsReturned = (Integer) section.retrieveObject("Rows");
            assertEquals(expectedRows, rowsReturned);
            if (rowsReturned > 0 && cols != null) {
                try {
                    TabularResultData table = section.retrieveTableByIndex(0);
                    GfJsonArray array = table.getHeaders();
                    assertEquals(cols.length, array.size());
                    for (String col : cols) {
                        boolean found = false;
                        getLogWriter().info("Validating column " + col);
                        for (int i = 0; i < array.size(); i++) {
                            String header = (String) array.get(i);
                            if (col.equals(header))
                                found = true;
                        }
                        assertEquals(true, found);
                    }
                } catch (GfJsonException e) {
                    fail("Error accessing table data", e);
                }
            }
        }
    } else
        fail("Expected CompositeResult Returned Result Type " + cmdResult.getType());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GfJsonArray(org.apache.geode.management.internal.cli.json.GfJsonArray) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) GfJsonException(org.apache.geode.management.internal.cli.json.GfJsonException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 23 with SectionResultData

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

the class MiscellaneousCommandsDUnitTest method testChangeLogLevelForMembers.

// GEODE-1605
@Category(FlakyTest.class)
@Test
public void testChangeLogLevelForMembers() {
    final VM vm0 = Host.getHost(0).getVM(0);
    final VM vm1 = Host.getHost(0).getVM(1);
    setupForChangeLogLelvel();
    String serverName1 = (String) vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            cachedLogLevel = System.getProperty(DistributionConfig.GEMFIRE_PREFIX + "log-level");
            return GemFireCacheImpl.getInstance().getDistributedSystem().getDistributedMember().getId();
        }
    });
    String serverName2 = (String) vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            cachedLogLevel = System.getProperty(DistributionConfig.GEMFIRE_PREFIX + "log-level");
            return GemFireCacheImpl.getInstance().getDistributedSystem().getDistributedMember().getId();
        }
    });
    String commandString = CliStrings.CHANGE_LOGLEVEL + " --" + CliStrings.CHANGE_LOGLEVEL__LOGLEVEL + "=finer" + " --" + CliStrings.CHANGE_LOGLEVEL__MEMBER + "=" + serverName1 + "," + serverName2;
    CommandResult commandResult = executeCommand(commandString);
    getLogWriter().info("testChangeLogLevel commandResult=" + commandResult);
    assertTrue(Status.OK.equals(commandResult.getStatus()));
    CompositeResultData resultData = (CompositeResultData) commandResult.getResultData();
    SectionResultData section = resultData.retrieveSection("section");
    assertNotNull(section);
    TabularResultData tableRsultData = section.retrieveTable("ChangeLogLevel");
    assertNotNull(tableRsultData);
    List<String> columns = tableRsultData.retrieveAllValues(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER);
    List<String> status = tableRsultData.retrieveAllValues(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS);
    assertEquals(columns.size(), 2);
    assertEquals(status.size(), 2);
    assertTrue(columns.contains(serverName1));
    assertTrue(columns.contains(serverName2));
    assertTrue(status.contains("true"));
}
Also used : Invoke.invokeInEveryVM(org.apache.geode.test.dunit.Invoke.invokeInEveryVM) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) 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 24 with SectionResultData

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

the class MiscellaneousCommandsDUnitTest method testChangeLogLevelForGrps.

@Test
public void testChangeLogLevelForGrps() {
    Properties localProps = new Properties();
    localProps.setProperty(NAME, "Manager");
    localProps.setProperty(GROUPS, "Group0");
    final VM vm1 = Host.getHost(0).getVM(1);
    final VM vm2 = Host.getHost(0).getVM(2);
    final String grp1 = "Group1";
    final String grp2 = "Group2";
    setUpJmxManagerOnVm0ThenConnect(localProps);
    String vm1id = (String) vm1.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Properties localProps = new Properties();
            localProps.setProperty(GROUPS, grp1);
            getSystem(localProps);
            Cache cache = getCache();
            return cache.getDistributedSystem().getDistributedMember().getId();
        }
    });
    String vm2id = (String) vm2.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            Properties localProps = new Properties();
            localProps.setProperty(GROUPS, grp2);
            getSystem(localProps);
            Cache cache = getCache();
            return cache.getDistributedSystem().getDistributedMember().getId();
        }
    });
    String commandString = CliStrings.CHANGE_LOGLEVEL + " --" + CliStrings.CHANGE_LOGLEVEL__LOGLEVEL + "=finer" + " --" + CliStrings.CHANGE_LOGLEVEL__GROUPS + "=" + grp1 + "," + grp2;
    CommandResult commandResult = executeCommand(commandString);
    getLogWriter().info("testChangeLogLevelForGrps commandResult=" + commandResult);
    assertTrue(Status.OK.equals(commandResult.getStatus()));
    CompositeResultData resultData = (CompositeResultData) commandResult.getResultData();
    SectionResultData section = resultData.retrieveSection("section");
    assertNotNull(section);
    TabularResultData tableRsultData = section.retrieveTable("ChangeLogLevel");
    assertNotNull(tableRsultData);
    List<String> columns = tableRsultData.retrieveAllValues(CliStrings.CHANGE_LOGLEVEL__COLUMN_MEMBER);
    List<String> status = tableRsultData.retrieveAllValues(CliStrings.CHANGE_LOGLEVEL__COLUMN_STATUS);
    assertEquals(columns.size(), 2);
    assertEquals(status.size(), 2);
    assertTrue(columns.contains(vm1id));
    assertTrue(columns.contains(vm2id));
    assertTrue(status.contains("true"));
}
Also used : Invoke.invokeInEveryVM(org.apache.geode.test.dunit.Invoke.invokeInEveryVM) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 25 with SectionResultData

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

the class GemfireDataCommandsDUnitTest method validateLocationsResult.

private void validateLocationsResult(CommandResult cmdResult, int expected) {
    if (ResultData.TYPE_COMPOSITE.equals(cmdResult.getType())) {
        CompositeResultData rd = (CompositeResultData) cmdResult.getResultData();
        SectionResultData section = rd.retrieveSectionByIndex(0);
        int result = (Integer) section.retrieveObject("Locations Found");
        assertEquals(expected, result);
    } else
        fail("Expected CompositeResult Returned Result Type " + cmdResult.getType());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Aggregations

SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)44 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)38 TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)22 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)10 InternalCache (org.apache.geode.internal.cache.InternalCache)9 Result (org.apache.geode.management.cli.Result)9 DistributedMember (org.apache.geode.distributed.DistributedMember)8 CliMetaData (org.apache.geode.management.cli.CliMetaData)8 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)8 CliCommand (org.springframework.shell.core.annotation.CliCommand)8 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)7 Test (org.junit.Test)7 ObjectName (javax.management.ObjectName)6 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)6 CacheServerMXBean (org.apache.geode.management.CacheServerMXBean)5 HashMap (java.util.HashMap)4 List (java.util.List)4