protected ResultModel createStatusLocatorResult(final LocatorLauncher.LocatorState state) throws NumberFormatException, IOException, ClassNotFoundException { ResultModel result = new ResultModel(); InfoResultModel info = result.addInfo(); info.addLine(state.toString()); info.addLine(ClusterConfigurationStatusRetriever.fromLocator(state)); return result; } }
if (xmlSection == null) { InfoResultModel info = result.addInfo("info"); info.addLine(String.format("xml content is empty. %s is not created.", xmlFile)); } else { File file = new File(xmlFile).getAbsoluteFile(); FileUtils.write(file, Strings.join(xmlSection.getContent(), System.lineSeparator()), Charset.defaultCharset()); xmlSection.removeLine(0); xmlSection.addLine("xml content exported to " + file.getAbsolutePath());
public InfoResultModel addInfo(String namedSection) { Object model = sections.get(namedSection); if (model != null) { if (model instanceof InfoResultModel) { return (InfoResultModel) model; } else { throw new IllegalStateException(String.format( "Section requested is %s, not InfoResultModel", model.getClass().getSimpleName())); } } InfoResultModel section = new InfoResultModel(); sections.put(namedSection, section); return section; }
private void buildInfoOrErrorCommandOutput(TableBuilder.Table resultTable, InfoResultModel model) { TableBuilder.RowGroup rowGroup = resultTable.newRowGroup(); addRowInRowGroup(rowGroup, model.getHeader()); model.getContent().forEach(c -> rowGroup.newRow().newLeftCol(c)); addRowInRowGroup(rowGroup, model.getFooter()); } }
public ListAssert<String> hasLines() { return assertThat(actual.getContent()); } }
regionsUsingSection.setHeader("Regions Using Data Source:"); if (regionsUsing.isEmpty()) { regionsUsingSection.addLine("no regions are using " + dataSourceName); } else { regionsUsingSection.setContent(regionsUsing);
if (cacheXmlContent != null) { InfoResultModel xmlSection = result.addInfo("xml"); xmlSection.setHeader(configuration.getCacheXmlFileName() + ": "); xmlSection.addLine(cacheXmlContent); if (jarNames.size() > 0) { InfoResultModel jarSection = result.addInfo("jars"); jarSection.setHeader("Jars: "); jarSection.addLine(Strings.join(jarNames, ", "));
public AbstractCharSequenceAssert<?, String> hasOutput() { String output = String.join(System.lineSeparator(), actual.getContent()); return assertThat(output); }
private void doOnConnectionFailure(final String locatorHostName, final int locatorPort, final boolean jmxManagerAuthEnabled, final boolean jmxManagerSslEnabled, final InfoResultModel infoResult) { infoResult.addLine("\n"); CommandStringBuilder commandUsage = new CommandStringBuilder(CliStrings.CONNECT) .addOption(CliStrings.CONNECT__LOCATOR, locatorHostName + "[" + locatorPort + "]"); StringBuilder message = new StringBuilder(); if (jmxManagerAuthEnabled) { commandUsage.addOption(CliStrings.CONNECT__USERNAME).addOption(CliStrings.CONNECT__PASSWORD); message.append("Authentication"); } if (jmxManagerSslEnabled) { message.append(jmxManagerAuthEnabled ? " and " : StringUtils.EMPTY) .append("SSL configuration"); } infoResult.addLine(CliStrings.format( CliStrings.START_LOCATOR__USE__0__TO__CONNECT_WITH_SECURITY, commandUsage.toString())); if (jmxManagerAuthEnabled || jmxManagerSslEnabled) { message.append(" required to connect to the Manager."); infoResult.addLine("\n"); infoResult.addLine(message.toString()); } }
@Override public String getMessageFromContent() { List<InfoResultModel> infos = result.getInfoSections(); if (infos.size() == 0) { return ""; } List<String> messages = infos.get(0).getContent(); return messages.stream().collect(Collectors.joining(". ")); }
@Override public ResultModel postExecution(GfshParseResult parseResult, ResultModel resultModel, Path tempFile) { try { for (Map.Entry<String, FileResultModel> entry : resultModel.getFiles().entrySet()) { entry.getValue().saveFile(); resultModel.addInfo().addLine("Metrics saved to: " + entry.getKey()); } } catch (IOException e) { resultModel.addInfo().addLine("Unable to save file: " + e.getMessage()); resultModel.setStatus(Result.Status.ERROR); } return resultModel; } }
@Test public void describeDataSourceWithNoRegionsUsingItReturnsResultWithNoRegionsUsingIt() { RegionConfig regionConfig = mock(RegionConfig.class); when(regionConfig.getCustomRegionElements()) .thenReturn(Collections.singletonList(mock(RegionMapping.class))); regionConfigs.add(regionConfig); ResultModel result = command.describeDataSource(DATA_SOURCE_NAME); InfoResultModel regionsUsingSection = (InfoResultModel) result .getSection(DescribeDataSourceCommand.REGIONS_USING_DATA_SOURCE_SECTION); assertThat(regionsUsingSection.getContent()) .isEqualTo(Arrays.asList("no regions are using " + DATA_SOURCE_NAME)); }
info.addLine(dir.getAbsolutePath() + " can not be created."); setStatus(Result.Status.ERROR); return; info.addLine(dir.getAbsolutePath() + " is not a directory."); setStatus(Result.Status.ERROR); return; info.addLine("Can not write to " + dir.getAbsolutePath()); setStatus(Result.Status.ERROR); return; info.addLine(fileResult.saveFile(dir));
@Test public void nonPooledWithPoolPropertiesIsError() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("false"); when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOL_PROPERTIES)) .thenReturn("pool properties value"); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.ERROR); assertThat(result.getInfoSection("info").getContent().get(0)) .contains(CreateDataSourceInterceptor.POOL_PROPERTIES_ONLY_VALID_ON_POOLED_DATA_SOURCE); }
@CliCommand(value = CliStrings.START_JVISUALVM, help = CliStrings.START_JVISUALVM__HELP) @CliMetaData(shellOnly = true, relatedTopic = {CliStrings.TOPIC_GEODE_MANAGER, CliStrings.TOPIC_GEODE_JMX, CliStrings.TOPIC_GEODE_M_AND_M}) public ResultModel startJVisualVM( @CliOption(key = CliStrings.START_JCONSOLE__J, optionContext = GfshParser.J_OPTION_CONTEXT, help = CliStrings.START_JCONSOLE__J__HELP) final String[] jvmArgs) throws IOException { String jvisualvmProcessOutput = getProcessOutput(jvmArgs); ResultModel result = new ResultModel(); InfoResultModel infoResultModel = result.addInfo(); if (StringUtils.isNotBlank(jvisualvmProcessOutput)) { infoResultModel.addLine(System.lineSeparator()); infoResultModel.addLine(jvisualvmProcessOutput); } return result; }
@Test public void nonPooledWithPoolFactoryIsError() { when(parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED)).thenReturn("false"); when( parseResult.getParamValueAsString(CreateDataSourceCommand.POOLED_DATA_SOURCE_FACTORY_CLASS)) .thenReturn("pool factory value"); ResultModel result = interceptor.preExecution(parseResult); assertThat(result.getStatus()).isEqualTo(Status.ERROR); assertThat(result.getInfoSection("info").getContent().get(0)) .contains( CreateDataSourceInterceptor.POOLED_DATA_SOURCE_FACTORY_CLASS_ONLY_VALID_ON_POOLED_DATA_SOURCE); } }
@Override public ResultModel postExecution(GfshParseResult parseResult, ResultModel resultModel, Path tempFile) { if (resultModel.getFiles().size() != 1) { resultModel.addInfo("No filename found to save"); resultModel.setStatus(Result.Status.ERROR); return resultModel; } try { for (Map.Entry<String, FileResultModel> entry : resultModel.getFiles().entrySet()) { entry.getValue().saveFile(); resultModel.addInfo().addLine( MessageFormat.format(CliStrings.SHOW_DEADLOCK__DEPENDENCIES__REVIEW, entry.getKey())); } } catch (IOException e) { resultModel.addInfo().addLine("Unable to save file: " + e.getMessage()); resultModel.setStatus(Result.Status.ERROR); } return resultModel; } }
assertThat(regionsUsingSection.getContent()) .isEqualTo(Arrays.asList("regionName1", "regionName3"));
/** * Helper method to create an {@code InfoResultModel} named "info". */ public static ResultModel createInfo(String message) { ResultModel result = new ResultModel(); result.addInfo(INFO_SECTION).addLine(message); result.setStatus(Result.Status.OK); return result; }