Search in sources :

Example 1 with SectionResultData

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

the class ClientCommands method describeClient.

@CliCommand(value = CliStrings.DESCRIBE_CLIENT, help = CliStrings.DESCRIBE_CLIENT__HELP)
@CliMetaData(relatedTopic = { CliStrings.TOPIC_CLIENT })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeClient(@CliOption(key = CliStrings.DESCRIBE_CLIENT__ID, mandatory = true, help = CliStrings.DESCRIBE_CLIENT__ID__HELP) String clientId) {
    Result result = null;
    if (clientId.startsWith("\"")) {
        clientId = clientId.substring(1);
    }
    if (clientId.endsWith("\"")) {
        clientId = clientId.substring(0, clientId.length() - 2);
    }
    if (clientId.endsWith("\";")) {
        clientId = clientId.substring(0, clientId.length() - 2);
    }
    try {
        CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
        SectionResultData sectionResult = compositeResultData.addSection("InfoSection");
        InternalCache cache = getCache();
        ManagementService service = ManagementService.getExistingManagementService(cache);
        ObjectName[] cacheServers = service.getDistributedSystemMXBean().listCacheServerObjectNames();
        if (cacheServers.length == 0) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_SERVER_LIST));
        }
        ClientHealthStatus clientHealthStatus = null;
        for (ObjectName objName : cacheServers) {
            CacheServerMXBean serverMbean = service.getMBeanInstance(objName, CacheServerMXBean.class);
            List<String> listOfClient = new ArrayList<String>(Arrays.asList((String[]) serverMbean.getClientIds()));
            if (listOfClient.contains(clientId)) {
                if (clientHealthStatus == null) {
                    try {
                        clientHealthStatus = serverMbean.showClientStats(clientId);
                        if (clientHealthStatus == null) {
                            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_STATS_FOR_CLIENT_0, clientId));
                        }
                    } catch (Exception eee) {
                        return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_STATS_FOR_CLIENT_0_REASON_1, clientId, eee.getMessage()));
                    }
                }
            }
        }
        if (clientHealthStatus == null) {
            return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT__CLIENT__ID__NOT__FOUND__0, clientId));
        }
        Set<DistributedMember> dsMembers = CliUtil.getAllMembers(cache);
        String isDurable = null;
        List<String> primaryServers = new ArrayList<String>();
        List<String> secondaryServers = new ArrayList<String>();
        if (dsMembers.size() > 0) {
            ContunuousQueryFunction contunuousQueryFunction = new ContunuousQueryFunction();
            FunctionService.registerFunction(contunuousQueryFunction);
            List<?> resultList = (List<?>) CliUtil.executeFunction(contunuousQueryFunction, clientId, dsMembers).getResult();
            for (int i = 0; i < resultList.size(); i++) {
                try {
                    Object object = resultList.get(i);
                    if (object instanceof Throwable) {
                        LogWrapper.getInstance().warning("Exception in Describe Client " + ((Throwable) object).getMessage(), ((Throwable) object));
                        continue;
                    }
                    if (object != null) {
                        ClientInfo objectResult = (ClientInfo) object;
                        isDurable = objectResult.isDurable;
                        if (objectResult.primaryServer != null && objectResult.primaryServer.length() > 0) {
                            if (primaryServers.size() == 0) {
                                primaryServers.add(objectResult.primaryServer);
                            } else {
                                primaryServers.add(" ,");
                                primaryServers.add(objectResult.primaryServer);
                            }
                        }
                        if (objectResult.secondaryServer != null && objectResult.secondaryServer.length() > 0) {
                            if (secondaryServers.size() == 0) {
                                secondaryServers.add(objectResult.secondaryServer);
                            } else {
                                secondaryServers.add(" ,");
                                secondaryServers.add(objectResult.secondaryServer);
                            }
                        }
                    }
                } catch (Exception e) {
                    LogWrapper.getInstance().info(CliStrings.DESCRIBE_CLIENT_ERROR_FETCHING_STATS_0 + " :: " + CliUtil.stackTraceAsString(e));
                    return ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_ERROR_FETCHING_STATS_0, e.getMessage()));
                }
            }
            buildTableResult(sectionResult, clientHealthStatus, isDurable, primaryServers, secondaryServers);
            result = ResultBuilder.buildResult(compositeResultData);
        } else {
            return ResultBuilder.createGemFireErrorResult(CliStrings.DESCRIBE_CLIENT_NO_MEMBERS);
        }
    } catch (Exception e) {
        LogWrapper.getInstance().info("Error in decribe clients. stack trace" + CliUtil.stackTraceAsString(e));
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.DESCRIBE_CLIENT_COULD_NOT_RETRIEVE_CLIENT_0, e.getMessage()));
    }
    LogWrapper.getInstance().info("decribe client result " + result);
    return result;
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) ArrayList(java.util.ArrayList) ContunuousQueryFunction(org.apache.geode.management.internal.cli.functions.ContunuousQueryFunction) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheServerMXBean(org.apache.geode.management.CacheServerMXBean) Result(org.apache.geode.management.cli.Result) ObjectName(javax.management.ObjectName) ManagementService(org.apache.geode.management.ManagementService) ClientHealthStatus(org.apache.geode.management.ClientHealthStatus) DistributedMember(org.apache.geode.distributed.DistributedMember) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) ArrayList(java.util.ArrayList) List(java.util.List) ClientInfo(org.apache.geode.management.internal.cli.functions.ContunuousQueryFunction.ClientInfo) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 2 with SectionResultData

use of org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData 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 3 with SectionResultData

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

the class ConfigCommands method addSection.

private void addSection(CompositeResultData crd, Map<String, String> attrMap, String headerText) {
    if (attrMap != null && !attrMap.isEmpty()) {
        SectionResultData section = crd.addSection();
        section.setHeader(headerText);
        section.addSeparator('.');
        Set<String> attributes = new TreeSet<>(attrMap.keySet());
        for (String attribute : attributes) {
            String attributeValue = attrMap.get(attribute);
            section.addData(attribute, attributeValue);
        }
    }
}
Also used : TreeSet(java.util.TreeSet) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 4 with SectionResultData

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

the class CLIMultiStepHelper method createBannerResult.

public static Result createBannerResult(List<String> fields, @SuppressWarnings("rawtypes") List values, String step) {
    CompositeResultData result = ResultBuilder.createCompositeResultData();
    SectionResultData section = result.addSection(STEP_SECTION);
    section.addData(NEXT_STEP_NAME, step);
    SectionResultData page = result.addSection(ARG_SECTION);
    if (fields.size() != values.size()) {
        throw new RuntimeException("Fields array and its value arraylength dont match");
    }
    for (int i = 0; i < fields.size(); i++) {
        page.addData(fields.get(i), values.get(i));
    }
    return ResultBuilder.buildResult(result);
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 5 with SectionResultData

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

the class CLIMultiStepHelper method createBannerResult.

public static Result createBannerResult(String[] fields, Object[] values, String step) {
    CompositeResultData result = ResultBuilder.createCompositeResultData();
    SectionResultData section = result.addSection(STEP_SECTION);
    section.addData(NEXT_STEP_NAME, step);
    SectionResultData page = result.addSection(ARG_SECTION);
    if (fields.length != values.length) {
        throw new RuntimeException("Fields array and its value arraylength dont match");
    }
    for (int i = 0; i < fields.length; i++) {
        page.addData(fields[i], values[i]);
    }
    return ResultBuilder.buildResult(result);
}
Also used : 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