@Test public void testConversion() { Configuration conf = new PropertiesConfiguration(); conf.setProperty("p1", "v1,v2"); conf.setProperty("p2", "v3"); List<String> lines = HadoopConfigurationConverter.asXmlConfigurationLines(conf); assertThat(lines, is((List<String>) Lists.newArrayList( "<configuration>", " <property>", " <name>p1</name>", " <value>v1,v2</value>", " </property>", " <property>", " <name>p2</name>", " <value>v3</value>", " </property>", "</configuration>" ))); }
@VisibleForTesting static List<String> asXmlConfigurationLines(Configuration hadoopConfig) { List<String> lines = Lists.newArrayList(); lines.add("<configuration>"); for (@SuppressWarnings("unchecked") Iterator<String> it = hadoopConfig.getKeys(); it.hasNext(); ) { String key = it.next(); if (key.endsWith(FINAL_SUFFIX)) { continue; } String value = StringUtils.join(hadoopConfig.getStringArray(key), AbstractConfiguration.getDefaultListDelimiter()); lines.add(" <property>"); lines.add(String.format(" <name>%s</name>", key)); lines.add(String.format(" <value>%s</value>", value)); String finalValue = hadoopConfig.getString(key + FINAL_SUFFIX); if (finalValue != null) { lines.add(String.format(" <final>%s</final>", finalValue)); } lines.add(" </property>"); } lines.add("</configuration>"); return lines; }
HadoopConfigurationConverter { @VisibleForTesting static List<String> asXmlConfigurationLines(Configuration hadoopConfig) { List<String> lines = Lists.newArrayList(); lines.add("<configuration>"); for (@SuppressWarnings("unchecked") Iterator<String> it = hadoopConfig.getKeys(); it.hasNext(); ) { String key = it.next(); if (key.endsWith(FINAL_SUFFIX)) { continue; } String value = StringUtils.join(hadoopConfig.getStringArray(key), AbstractConfiguration.getDefaultListDelimiter()); lines.add(" <property>"); lines.add(String.format(" <name>%s</name>", key)); lines.add(String.format(" <value>%s</value>", value)); String finalValue = hadoopConfig.getString(key + FINAL_SUFFIX); if (finalValue != null) { lines.add(String.format(" <final>%s</final>", finalValue)); } lines.add(" </property>"); } lines.add("</configuration>"); return lines; } }
HadoopConfigurationConverter { @VisibleForTesting static List<String> asXmlConfigurationLines(Configuration hadoopConfig) { List<String> lines = Lists.newArrayList(); lines.add("<configuration>"); for (@SuppressWarnings("unchecked") Iterator<String> it = hadoopConfig.getKeys(); it.hasNext(); ) { String key = it.next(); if (key.endsWith(FINAL_SUFFIX)) { continue; } String value = StringUtils.join(hadoopConfig.getStringArray(key), AbstractConfiguration.getDefaultListDelimiter()); lines.add(" <property>"); lines.add(String.format(" <name>%s</name>", key)); lines.add(String.format(" <value>%s</value>", value)); String finalValue = hadoopConfig.getString(key + FINAL_SUFFIX); if (finalValue != null) { lines.add(String.format(" <final>%s</final>", finalValue)); } lines.add(" </property>"); } lines.add("</configuration>"); return lines; }  }
HadoopConfigurationConverter { @VisibleForTesting static List<String> asXmlConfigurationLines(Configuration hadoopConfig) { List<String> lines = Lists.newArrayList(); lines.add("<configuration>"); for (@SuppressWarnings("unchecked") Iterator<String> it = hadoopConfig.getKeys(); it.hasNext(); ) { String key = it.next(); if (key.endsWith(FINAL_SUFFIX)) { continue; } String value = StringUtils.join(hadoopConfig.getStringArray(key), AbstractConfiguration.getDefaultListDelimiter()); lines.add(" <property>"); lines.add(String.format(" <name>%s</name>", key)); lines.add(String.format(" <value>%s</value>", value)); String finalValue = hadoopConfig.getString(key + FINAL_SUFFIX); if (finalValue != null) { lines.add(String.format(" <final>%s</final>", finalValue)); } lines.add(" </property>"); } lines.add("</configuration>"); return lines; }  static Statement asCreateXmlConfigurationFileStatement(String path,
      Configuration hadoopConfig); static Statement asCreateEnvironmentVariablesFileStatement(String path,
      Configuration config); static void createClientSideHadoopSiteFile(File file, Properties config); }
HadoopConfigurationConverter { @VisibleForTesting static List<String> asXmlConfigurationLines(Configuration hadoopConfig) { List<String> lines = Lists.newArrayList(); lines.add("<configuration>"); for (@SuppressWarnings("unchecked") Iterator<String> it = hadoopConfig.getKeys(); it.hasNext(); ) { String key = it.next(); if (key.endsWith(FINAL_SUFFIX)) { continue; } String value = StringUtils.join(hadoopConfig.getStringArray(key), AbstractConfiguration.getDefaultListDelimiter()); lines.add(" <property>"); lines.add(String.format(" <name>%s</name>", key)); lines.add(String.format(" <value>%s</value>", value)); String finalValue = hadoopConfig.getString(key + FINAL_SUFFIX); if (finalValue != null) { lines.add(String.format(" <final>%s</final>", finalValue)); } lines.add(" </property>"); } lines.add("</configuration>"); return lines; }  static Statement asCreateXmlConfigurationFileStatement(String path,
      Configuration hadoopConfig); static Statement asCreateEnvironmentVariablesFileStatement(String path,
      Configuration config); static void createClientSideHadoopSiteFile(File file, Properties config);  }