Search in sources :

Example 61 with TabularResultData

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

the class DataCommandResult method toCommandResult.

public Result toCommandResult() {
    if (StringUtils.isEmpty(keyClass)) {
        keyClass = "java.lang.String";
    }
    if (StringUtils.isEmpty(valueClass)) {
        valueClass = "java.lang.String";
    }
    if (errorString != null) {
        // return ResultBuilder.createGemFireErrorResult(errorString);
        CompositeResultData data = ResultBuilder.createCompositeResultData();
        SectionResultData section = data.addSection();
        section.addData("Message", errorString);
        section.addData(RESULT_FLAG, operationCompletedSuccessfully);
        return ResultBuilder.buildResult(data);
    }
    CompositeResultData data = ResultBuilder.createCompositeResultData();
    SectionResultData section = data.addSection();
    TabularResultData table = section.addTable();
    section.addData(RESULT_FLAG, operationCompletedSuccessfully);
    if (infoString != null) {
        section.addData("Message", infoString);
    }
    if (isGet()) {
        toCommandResult_isGet(section, table);
    } else if (isLocateEntry()) {
        toCommandResult_isLocate(section, table);
    } else if (isPut()) {
        toCommandResult_isPut(section, table);
    } else if (isRemove()) {
        toCommandResult_isRemove(section, table);
    } else if (isSelect()) {
    // its moved to its separate method
    }
    return ResultBuilder.buildResult(data);
}
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 62 with TabularResultData

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

the class ClientCommands method buildTableResult.

private void buildTableResult(SectionResultData sectionResult, ClientHealthStatus clientHealthStatus, String isDurable, List<String> primaryServers, List<String> secondaryServers) {
    StringBuilder primServers = new StringBuilder();
    for (String primaryServer : primaryServers) {
        primServers.append(primaryServer);
    }
    StringBuilder secondServers = new StringBuilder();
    for (String secondServer : secondaryServers) {
        secondServers.append(secondServer);
    }
    if (clientHealthStatus != null) {
        sectionResult.addSeparator('-');
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_PRIMARY_SERVERS, primServers);
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_SECONDARY_SERVERS, secondServers);
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_CPU, clientHealthStatus.getCpus());
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_LISTNER_CALLS, clientHealthStatus.getNumOfCacheListenerCalls());
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_GETS, clientHealthStatus.getNumOfGets());
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_MISSES, clientHealthStatus.getNumOfMisses());
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_PUTS, clientHealthStatus.getNumOfPuts());
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_THREADS, clientHealthStatus.getNumOfThreads());
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_PROCESS_CPU_TIME, clientHealthStatus.getProcessCpuTime());
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_QUEUE_SIZE, clientHealthStatus.getQueueSize());
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_UP_TIME, clientHealthStatus.getUpTime());
        sectionResult.addData(CliStrings.DESCRIBE_CLIENT_COLUMN_DURABLE, isDurable);
        sectionResult.addSeparator('-');
        Map<String, String> poolStats = clientHealthStatus.getPoolStats();
        if (poolStats.size() > 0) {
            Iterator<Entry<String, String>> it = poolStats.entrySet().iterator();
            while (it.hasNext()) {
                Entry<String, String> entry = it.next();
                TabularResultData poolStatsResultTable = sectionResult.addTable("Pool Stats For Pool Name = " + entry.getKey());
                poolStatsResultTable.setHeader("Pool Stats For Pool Name = " + entry.getKey());
                String poolStatsStr = entry.getValue();
                String[] str = poolStatsStr.split(";");
                LogWrapper.getInstance().info("decribe client clientHealthStatus min conn=" + str[0].substring(str[0].indexOf("=") + 1));
                LogWrapper.getInstance().info("decribe client clientHealthStatus max conn =" + str[1].substring(str[1].indexOf("=") + 1));
                LogWrapper.getInstance().info("decribe client clientHealthStatus redundancy =" + str[2].substring(str[2].indexOf("=") + 1));
                LogWrapper.getInstance().info("decribe client clientHealthStatus CQs =" + str[3].substring(str[3].indexOf("=") + 1));
                poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_MIN_CONN, str[0].substring(str[0].indexOf("=") + 1));
                poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_MAX_CONN, str[1].substring(str[1].indexOf("=") + 1));
                poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_REDUDANCY, str[2].substring(str[2].indexOf("=") + 1));
                poolStatsResultTable.accumulate(CliStrings.DESCRIBE_CLIENT_CQs, str[3].substring(str[3].indexOf("=") + 1));
            }
        }
    }
}
Also used : Entry(java.util.Map.Entry) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData)

Example 63 with TabularResultData

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

the class ConfigCommands method describeConfig.

@CliCommand(value = { CliStrings.DESCRIBE_CONFIG }, help = CliStrings.DESCRIBE_CONFIG__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeConfig(@CliOption(key = CliStrings.DESCRIBE_CONFIG__MEMBER, optionContext = ConverterHint.ALL_MEMBER_IDNAME, help = CliStrings.DESCRIBE_CONFIG__MEMBER__HELP, mandatory = true) String memberNameOrId, @CliOption(key = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS, help = CliStrings.DESCRIBE_CONFIG__HIDE__DEFAULTS__HELP, unspecifiedDefaultValue = "true", specifiedDefaultValue = "true") boolean hideDefaults) {
    Result result = null;
    try {
        DistributedMember targetMember = null;
        if (memberNameOrId != null && !memberNameOrId.isEmpty()) {
            targetMember = CliUtil.getDistributedMemberByNameOrId(memberNameOrId);
        }
        if (targetMember != null) {
            ResultCollector<?, ?> rc = CliUtil.executeFunction(getMemberConfigFunction, new Boolean(hideDefaults), targetMember);
            ArrayList<?> output = (ArrayList<?>) rc.getResult();
            Object obj = output.get(0);
            if (obj != null && obj instanceof MemberConfigurationInfo) {
                MemberConfigurationInfo memberConfigInfo = (MemberConfigurationInfo) obj;
                CompositeResultData crd = ResultBuilder.createCompositeResultData();
                crd.setHeader(CliStrings.format(CliStrings.DESCRIBE_CONFIG__HEADER__TEXT, memberNameOrId));
                List<String> jvmArgsList = memberConfigInfo.getJvmInputArguments();
                TabularResultData jvmInputArgs = crd.addSection().addSection().addTable();
                for (String jvmArg : jvmArgsList) {
                    jvmInputArgs.accumulate("JVM command line arguments", jvmArg);
                }
                addSection(crd, memberConfigInfo.getGfePropsSetUsingApi(), "GemFire properties defined using the API");
                addSection(crd, memberConfigInfo.getGfePropsRuntime(), "GemFire properties defined at the runtime");
                addSection(crd, memberConfigInfo.getGfePropsSetFromFile(), "GemFire properties defined with the property file");
                addSection(crd, memberConfigInfo.getGfePropsSetWithDefaults(), "GemFire properties using default values");
                addSection(crd, memberConfigInfo.getCacheAttributes(), "Cache attributes");
                List<Map<String, String>> cacheServerAttributesList = memberConfigInfo.getCacheServerAttributes();
                if (cacheServerAttributesList != null && !cacheServerAttributesList.isEmpty()) {
                    SectionResultData cacheServerSection = crd.addSection();
                    cacheServerSection.setHeader("Cache-server attributes");
                    for (Map<String, String> cacheServerAttributes : cacheServerAttributesList) {
                        addSubSection(cacheServerSection, cacheServerAttributes, "");
                    }
                }
                result = ResultBuilder.buildResult(crd);
            }
        } else {
            ErrorResultData erd = ResultBuilder.createErrorResultData();
            erd.addLine(CliStrings.format(CliStrings.DESCRIBE_CONFIG__MEMBER__NOT__FOUND, new Object[] { memberNameOrId }));
            result = ResultBuilder.buildResult(erd);
        }
    } catch (FunctionInvocationTargetException e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.DESCRIBE_CONFIG));
    } catch (Exception e) {
        ErrorResultData erd = ResultBuilder.createErrorResultData();
        erd.addLine(e.getMessage());
        result = ResultBuilder.buildResult(erd);
    }
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData) ArrayList(java.util.ArrayList) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) IOException(java.io.IOException) GfshParseResult(org.apache.geode.management.internal.cli.GfshParseResult) Result(org.apache.geode.management.cli.Result) CliFunctionResult(org.apache.geode.management.internal.cli.functions.CliFunctionResult) MemberConfigurationInfo(org.apache.geode.management.internal.cli.domain.MemberConfigurationInfo) DistributedMember(org.apache.geode.distributed.DistributedMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ErrorResultData(org.apache.geode.management.internal.cli.result.ErrorResultData) 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)

Example 64 with TabularResultData

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

the class CLIMultiStepHelper method createPageTableAndBanner.

private static void createPageTableAndBanner(SectionResultData page, String[] header, Object[][] table) {
    TabularResultData resultData = page.addTable();
    int columns = header.length;
    for (int i = 0; i < table.length; i++) {
        int rowLength = table[i].length;
        if (rowLength != columns)
            throw new RuntimeException("Row contains more than " + columns + " :  " + rowLength);
    }
    for (int i = 0; i < table.length; i++) {
        for (int j = 0; j < columns; j++) {
            resultData.accumulate(header[j], table[i][j]);
        }
    }
}
Also used : TabularResultData(org.apache.geode.management.internal.cli.result.TabularResultData)

Example 65 with TabularResultData

use of org.apache.geode.management.internal.cli.result.TabularResultData 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)

Aggregations

TabularResultData (org.apache.geode.management.internal.cli.result.TabularResultData)140 Test (org.junit.Test)74 CommandResult (org.apache.geode.management.internal.cli.result.CommandResult)68 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)63 Properties (java.util.Properties)54 DistributedMember (org.apache.geode.distributed.DistributedMember)40 CliCommand (org.springframework.shell.core.annotation.CliCommand)35 Result (org.apache.geode.management.cli.Result)34 CliMetaData (org.apache.geode.management.cli.CliMetaData)33 InternalCache (org.apache.geode.internal.cache.InternalCache)32 ResourceOperation (org.apache.geode.management.internal.security.ResourceOperation)31 CompositeResultData (org.apache.geode.management.internal.cli.result.CompositeResultData)30 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)29 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)29 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)28 VM (org.apache.geode.test.dunit.VM)27 ArrayList (java.util.ArrayList)26 SectionResultData (org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)23 CommandResultException (org.apache.geode.management.internal.cli.result.CommandResultException)18 List (java.util.List)16