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; CompositeResultData.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(Result.Status.ERROR); } if (i != this.commandAndStatusList.size()) { section.setFooter(Gfsh.LINE_SEPARATOR); } } return ResultBuilder.buildResult(compositeResultData); }
} else { if (i == memberPR.dsMemberList.size() - 1) { rebalanceResultData.addSection().addData( CliStrings.format( CliStrings.REBALANCE__MSG__NO_EXECUTION_FOR_REGION_0_ON_MEMBERS_1, rebalanceResultData.addSection().addData( CliStrings.format( CliStrings.REBALANCE__MSG__NO_EXECUTION_FOR_REGION_0_ON_MEMBERS_1,
CompositeResultData.SectionResultData regionSection = crd.addSection(); regionSection.addSeparator('-'); regionSection.addData("Name", regionDescription.getName()); regionSection.addData("Data Policy", dataPolicy); memberType = CliStrings.DESCRIBE_REGION__HOSTING__MEMBER; regionSection.addData(memberType, StringUtils.join(regionDescription.getHostingMembers(), '\n')); regionSection.addSeparator('.');
member.getId(), ex.getMessage()), ex); rebalanceResultData.addSection() .addData(CliStrings.format( CliStrings.REBALANCE__MSG__EXCEPTION_IN_REBALANCE_FOR_MEMBER_0_Exception, member.getId()), ex.getMessage()); member.getId(), ex.getMessage()), ex); rebalanceResultData.addSection() .addData(CliStrings.format( CliStrings.REBALANCE__MSG__EXCEPTION_IN_REBALANCE_FOR_MEMBER_0_Exception, member.getId()), ex.getMessage());
section.addData("Name", memberInformation.getName()); section.addData("Id", memberInformation.getId()); section.addData("Host", memberInformation.getHost()); section.addData("Regions", StringUtils.join(memberInformation.getHostedRegions(), '\n')); section.addData("PID", memberInformation.getProcessId()); section.addData("Groups", memberInformation.getGroups()); section.addData("Used Heap", memberInformation.getHeapUsage() + "M"); section.addData("Max Heap", memberInformation.getMaxHeapSize() + "M"); section.addData("Off Heap Size", offHeapMemorySize); section.addData("Working Dir", memberInformation.getWorkingDirPath()); section.addData("Log file", memberInformation.getLogFilePath()); section.addData("Locators", memberInformation.getLocators()); clientServiceSection.addData("Server Bind", cacheServerInfo.getBindAddress()); clientServiceSection.addData("Server Port", cacheServerInfo.getPort()); clientServiceSection.addData("Running", cacheServerInfo.isRunning()); clientServiceSection.addData("Client Connections", memberInformation.getClientCount());
section1.setHeader("section 0 header"); section1.addSeparator('-'); section1.addData("param-1", "value-1"); section1.addData("param-3", "value-3"); section1.addData("param-2", "value-2"); section1.setFooter("section 0 footer"); section2.setHeader("named section header"); section2.addSeparator('-'); section2.addData("param-A", "value-B");
for (Object object : resultList) { if (object instanceof Exception) { rebalanceResultData.addSection().addData( CliStrings.format(CliStrings.REBALANCE__MSG__NO_EXECUTION, member.getId()), ((Exception) object).getMessage()); break; } else if (object instanceof Throwable) { rebalanceResultData.addSection().addData( CliStrings.format(CliStrings.REBALANCE__MSG__NO_EXECUTION, member.getId()), ((Throwable) object).getMessage()); LogWrapper.getInstance(getCache()).info( "Rebalancing for member=" + member.getId() + ", resultList is either null or empty"); rebalanceResultData.addSection().addData("Rebalancing for member=" + member.getId(), ", resultList is either null or empty"); toContinueForOtherMembers = true;
@Test public void compositeResultDataStructure() { CompositeResultData result = ResultBuilder.createCompositeResultData(); result.setHeader("Heads"); result.setFooter("Tails"); // build up an example result.addSection().addData("section 0 key", "section 0 value"); result.addSection().addTable().accumulate("table 1 column", "table 1 value"); CommandResult cmdResult = ResultBuilder.buildResult(result); assertThat(cmdResult.getHeader()).isEqualTo("Heads"); assertThat(cmdResult.getFooter()).isEqualTo("Tails"); assertThat(cmdResult.getMapFromSection("0").get("section 0 key")).isEqualTo("section 0 value"); Map<String, List<String>> table = cmdResult.getMapFromTableContent("1", "0"); assertThat(table.get("table 1 column")).contains("table 1 value"); }
@Test public void withSectionContainingRawData() { CompositeResultData result = new CompositeResultData(); CompositeResultData.SectionResultData section = result.addSection(); section.addData("my-data", "some random string"); assertThat(result.getGfJsonObject().getJSONObject("content").getJSONObject("__sections__-0") .getString("my-data")).isEqualTo("some random string"); } }