Search in sources :

Example 11 with SectionResultData

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

the class CLIMultiStepHelper method createPageResult.

public static Result createPageResult(List<String> fields, @SuppressWarnings("rawtypes") List values, String step, String[] header, Object[][] table) {
    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));
    }
    createPageTableAndBanner(page, header, table);
    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 12 with SectionResultData

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

the class ScriptExecutionDetails method getResult.

Result getResult() {
    CompositeResultData compositeResultData = ResultBuilder.createCompositeResultData();
    compositeResultData.setHeader("************************* Execution Summary ***********************\nScript file: " + filePath);
    for (int i = 0; i < this.commandAndStatusList.size(); i++) {
        int commandSrNo = i + 1;
        SectionResultData section = compositeResultData.addSection("" + (i + 1));
        CommandAndStatus commandAndStatus = commandAndStatusList.get(i);
        section.addData("Command-" + String.valueOf(commandSrNo), commandAndStatus.command);
        section.addData("Status", commandAndStatus.status);
        if (commandAndStatus.status.equals("FAILED")) {
            compositeResultData.setStatus(org.apache.geode.management.cli.Result.Status.ERROR);
        }
        if (i != this.commandAndStatusList.size()) {
            section.setFooter(Gfsh.LINE_SEPARATOR);
        }
    }
    return ResultBuilder.buildResult(compositeResultData);
}
Also used : CompositeResultData(org.apache.geode.management.internal.cli.result.CompositeResultData) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 13 with SectionResultData

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

the class RegionCommands method describeRegion.

@CliCommand(value = { CliStrings.DESCRIBE_REGION }, help = CliStrings.DESCRIBE_REGION__HELP)
@CliMetaData(shellOnly = false, relatedTopic = { CliStrings.TOPIC_GEODE_REGION, CliStrings.TOPIC_GEODE_CONFIG })
@ResourceOperation(resource = Resource.CLUSTER, operation = Operation.READ)
public Result describeRegion(@CliOption(key = CliStrings.DESCRIBE_REGION__NAME, optionContext = ConverterHint.REGION_PATH, help = CliStrings.DESCRIBE_REGION__NAME__HELP, mandatory = true) String regionName) {
    Result result = null;
    try {
        if (regionName == null || regionName.isEmpty()) {
            return ResultBuilder.createUserErrorResult("Please provide a region name");
        }
        if (regionName.equals(Region.SEPARATOR)) {
            return ResultBuilder.createUserErrorResult(CliStrings.INVALID_REGION_NAME);
        }
        InternalCache cache = getCache();
        ResultCollector<?, ?> rc = CliUtil.executeFunction(getRegionDescription, regionName, CliUtil.getAllMembers(cache));
        List<?> resultList = (List<?>) rc.getResult();
        // The returned result could be a region description with per member and /or single local
        // region
        Object[] results = resultList.toArray();
        List<RegionDescription> regionDescriptionList = new ArrayList<RegionDescription>();
        for (int i = 0; i < results.length; i++) {
            if (results[i] instanceof RegionDescriptionPerMember) {
                RegionDescriptionPerMember regionDescPerMember = (RegionDescriptionPerMember) results[i];
                if (regionDescPerMember != null) {
                    RegionDescription regionDescription = new RegionDescription();
                    regionDescription.add(regionDescPerMember);
                    for (int j = i + 1; j < results.length; j++) {
                        if (results[j] != null && results[j] instanceof RegionDescriptionPerMember) {
                            RegionDescriptionPerMember preyRegionDescPerMember = (RegionDescriptionPerMember) results[j];
                            if (regionDescription.add(preyRegionDescPerMember)) {
                                results[j] = null;
                            }
                        }
                    }
                    regionDescriptionList.add(regionDescription);
                }
            } else if (results[i] instanceof Throwable) {
                Throwable t = (Throwable) results[i];
                LogWrapper.getInstance().info(t.getMessage(), t);
            }
        }
        if (regionDescriptionList.isEmpty()) {
            return ResultBuilder.createUserErrorResult(CliStrings.format(CliStrings.REGION_NOT_FOUND, regionName));
        }
        CompositeResultData crd = ResultBuilder.createCompositeResultData();
        Iterator<RegionDescription> iters = regionDescriptionList.iterator();
        while (iters.hasNext()) {
            RegionDescription regionDescription = iters.next();
            // No point in displaying the scope for PR's
            if (regionDescription.isPartition()) {
                regionDescription.getCndRegionAttributes().remove(RegionAttributesNames.SCOPE);
            } else {
                String scope = regionDescription.getCndRegionAttributes().get(RegionAttributesNames.SCOPE);
                if (scope != null) {
                    scope = scope.toLowerCase().replace('_', '-');
                    regionDescription.getCndRegionAttributes().put(RegionAttributesNames.SCOPE, scope);
                }
            }
            SectionResultData regionSection = crd.addSection();
            regionSection.addSeparator('-');
            regionSection.addData("Name", regionDescription.getName());
            String dataPolicy = regionDescription.getDataPolicy().toString().toLowerCase().replace('_', ' ');
            regionSection.addData("Data Policy", dataPolicy);
            String memberType = "";
            if (regionDescription.isAccessor()) {
                memberType = CliStrings.DESCRIBE_REGION__ACCESSOR__MEMBER;
            } else {
                memberType = CliStrings.DESCRIBE_REGION__HOSTING__MEMBER;
            }
            regionSection.addData(memberType, CliUtil.convertStringSetToString(regionDescription.getHostingMembers(), '\n'));
            regionSection.addSeparator('.');
            TabularResultData commonNonDefaultAttrTable = regionSection.addSection().addTable();
            commonNonDefaultAttrTable.setHeader(CliStrings.format(CliStrings.DESCRIBE_REGION__NONDEFAULT__COMMONATTRIBUTES__HEADER, memberType));
            // Common Non Default Region Attributes
            Map<String, String> cndRegionAttrsMap = regionDescription.getCndRegionAttributes();
            // Common Non Default Eviction Attributes
            Map<String, String> cndEvictionAttrsMap = regionDescription.getCndEvictionAttributes();
            // Common Non Default Partition Attributes
            Map<String, String> cndPartitionAttrsMap = regionDescription.getCndPartitionAttributes();
            writeCommonAttributesToTable(commonNonDefaultAttrTable, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__REGION, cndRegionAttrsMap);
            writeCommonAttributesToTable(commonNonDefaultAttrTable, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__EVICTION, cndEvictionAttrsMap);
            writeCommonAttributesToTable(commonNonDefaultAttrTable, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__PARTITION, cndPartitionAttrsMap);
            // Member-wise non default Attributes
            Map<String, RegionDescriptionPerMember> regDescPerMemberMap = regionDescription.getRegionDescriptionPerMemberMap();
            Set<String> members = regDescPerMemberMap.keySet();
            TabularResultData table = regionSection.addSection().addTable();
            // table.setHeader(CliStrings.format(CliStrings.DESCRIBE_REGION__NONDEFAULT__PERMEMBERATTRIBUTES__HEADER,
            // memberType));
            boolean setHeader = false;
            for (String member : members) {
                RegionDescriptionPerMember regDescPerMem = regDescPerMemberMap.get(member);
                Map<String, String> ndRa = regDescPerMem.getNonDefaultRegionAttributes();
                Map<String, String> ndEa = regDescPerMem.getNonDefaultEvictionAttributes();
                Map<String, String> ndPa = regDescPerMem.getNonDefaultPartitionAttributes();
                // Get all the member-specific non-default attributes by removing the common keys
                ndRa.keySet().removeAll(cndRegionAttrsMap.keySet());
                ndEa.keySet().removeAll(cndEvictionAttrsMap.keySet());
                ndPa.keySet().removeAll(cndPartitionAttrsMap.keySet());
                // Scope is not valid for PR's
                if (regionDescription.isPartition()) {
                    if (ndRa.get(RegionAttributesNames.SCOPE) != null) {
                        ndRa.remove(RegionAttributesNames.SCOPE);
                    }
                }
                List<FixedPartitionAttributesInfo> fpaList = regDescPerMem.getFixedPartitionAttributes();
                if (!(ndRa.isEmpty() && ndEa.isEmpty() && ndPa.isEmpty()) || fpaList != null) {
                    setHeader = true;
                    boolean memberNameAdded = false;
                    memberNameAdded = writeAttributesToTable(table, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__REGION, ndRa, member, memberNameAdded);
                    memberNameAdded = writeAttributesToTable(table, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__EVICTION, ndEa, member, memberNameAdded);
                    memberNameAdded = writeAttributesToTable(table, CliStrings.DESCRIBE_REGION__ATTRIBUTE__TYPE__PARTITION, ndPa, member, memberNameAdded);
                    writeFixedPartitionAttributesToTable(table, "", fpaList, member, memberNameAdded);
                // Fix for #46767
                // writeAttributeToTable(table, "", "", "", "");
                }
            }
            if (setHeader == true) {
                table.setHeader(CliStrings.format(CliStrings.DESCRIBE_REGION__NONDEFAULT__PERMEMBERATTRIBUTES__HEADER, memberType));
            }
        }
        result = ResultBuilder.buildResult(crd);
    } catch (FunctionInvocationTargetException e) {
        result = ResultBuilder.createGemFireErrorResult(CliStrings.format(CliStrings.COULD_NOT_EXECUTE_COMMAND_TRY_AGAIN, CliStrings.DESCRIBE_REGION));
    } catch (Exception e) {
        String errorMessage = CliStrings.format(CliStrings.EXCEPTION_CLASS_AND_MESSAGE, e.getClass().getName(), e.getMessage());
        result = ResultBuilder.createGemFireErrorResult(errorMessage);
    }
    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) InternalCache(org.apache.geode.internal.cache.InternalCache) Result(org.apache.geode.management.cli.Result) FixedPartitionAttributesInfo(org.apache.geode.management.internal.cli.domain.FixedPartitionAttributesInfo) ArrayList(java.util.ArrayList) List(java.util.List) ConverterHint(org.apache.geode.management.cli.ConverterHint) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CommandResultException(org.apache.geode.management.internal.cli.result.CommandResultException) RegionDescription(org.apache.geode.management.internal.cli.domain.RegionDescription) RegionDescriptionPerMember(org.apache.geode.management.internal.cli.domain.RegionDescriptionPerMember) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData) CliCommand(org.springframework.shell.core.annotation.CliCommand) CliMetaData(org.apache.geode.management.cli.CliMetaData) ResourceOperation(org.apache.geode.management.internal.security.ResourceOperation)

Example 14 with SectionResultData

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

the class RegionCommands method addChildSection.

public void addChildSection(SectionResultData parentSection, Map<String, String> map, String header) {
    if (!map.isEmpty()) {
        Set<String> attributes = map.keySet();
        SectionResultData section = parentSection.addSection();
        section.setHeader(header);
        for (String attribute : attributes) {
            section.addData(attribute, map.get(attribute));
        }
    }
}
Also used : SectionResultData(org.apache.geode.management.internal.cli.result.CompositeResultData.SectionResultData)

Example 15 with SectionResultData

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

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