@Test public void testParseConfigSuccess() { Path jobFolder = new Path(Constants.TONY_CORE_SRC + "test/resources/typicalHistFolder/job1"); List<JobConfig> expected = new ArrayList<>(); JobConfig expectedConfig = new JobConfig(); expectedConfig.setName("name"); expectedConfig.setValue("value"); expectedConfig.setFinal(true); expectedConfig.setSource("source"); expected.add(expectedConfig); List<JobConfig> actual = ParserUtils.parseConfig(fs, jobFolder); assertEquals(actual.size(), expected.size()); assertEquals(actual.get(0).getName(), expected.get(0).getName()); assertEquals(actual.get(0).getValue(), expected.get(0).getValue()); assertEquals(actual.get(0).isFinal(), expected.get(0).isFinal()); assertEquals(actual.get(0).getSource(), expected.get(0).getSource()); }
public static List<JobConfig> parseConfig(FileSystem fs, Path jobFolderPath) { if (!pathExists(fs, jobFolderPath)) { return Collections.emptyList(); } Path configFilePath = new Path(jobFolderPath, Constants.TONY_FINAL_XML); try { if (!fs.exists(configFilePath)) { configFilePath = new Path(jobFolderPath, "config.xml"); } } catch (IOException e) { LOG.error("Encountered exception while checking existence of " + configFilePath, e); } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); List<JobConfig> configs = new ArrayList<>(); try (FSDataInputStream inStrm = fs.open(configFilePath)) { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inStrm); doc.getDocumentElement().normalize(); NodeList properties = doc.getElementsByTagName("property"); for (int i = 0; i < properties.getLength(); i++) { Node property = properties.item(i); if (property.getNodeType() == Node.ELEMENT_NODE) { Element p = (Element) property; JobConfig jobConf = new JobConfig(); String name = getNodeElementText(p, "name"); String value = getNodeElementText(p, "value"); if (name == null || value == null) { LOG.warn("Found config with null name or value. Name = " + name + ", value = " + value); continue; } jobConf.setName(name); jobConf.setValue(value); String finalText = getNodeElementText(p, "final"); if (finalText != null && finalText.equalsIgnoreCase("true")) { jobConf.setFinal(true); } jobConf.setSource(getNodeElementText(p, "source")); configs.add(jobConf); } } } catch (SAXException e) { LOG.error("Failed to parse config file", e); return Collections.emptyList(); } catch (ParserConfigurationException e) { LOG.error("Failed to init XML parser", e); return Collections.emptyList(); } catch (IOException e) { LOG.error("Failed to read config file", e); return Collections.emptyList(); } LOG.debug("Successfully parsed config"); return configs; }
ParserUtils { public static List<JobConfig> parseConfig(FileSystem fs, Path jobFolderPath) { if (!pathExists(fs, jobFolderPath)) { return Collections.emptyList(); } Path configFilePath = new Path(jobFolderPath, Constants.TONY_FINAL_XML); try { if (!fs.exists(configFilePath)) { configFilePath = new Path(jobFolderPath, "config.xml"); } } catch (IOException e) { LOG.error("Encountered exception while checking existence of " + configFilePath, e); } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); List<JobConfig> configs = new ArrayList<>(); try (FSDataInputStream inStrm = fs.open(configFilePath)) { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inStrm); doc.getDocumentElement().normalize(); NodeList properties = doc.getElementsByTagName("property"); for (int i = 0; i < properties.getLength(); i++) { Node property = properties.item(i); if (property.getNodeType() == Node.ELEMENT_NODE) { Element p = (Element) property; JobConfig jobConf = new JobConfig(); String name = getNodeElementText(p, "name"); String value = getNodeElementText(p, "value"); if (name == null || value == null) { LOG.warn("Found config with null name or value. Name = " + name + ", value = " + value); continue; } jobConf.setName(name); jobConf.setValue(value); String finalText = getNodeElementText(p, "final"); if (finalText != null && finalText.equalsIgnoreCase("true")) { jobConf.setFinal(true); } jobConf.setSource(getNodeElementText(p, "source")); configs.add(jobConf); } } } catch (SAXException e) { LOG.error("Failed to parse config file", e); return Collections.emptyList(); } catch (ParserConfigurationException e) { LOG.error("Failed to init XML parser", e); return Collections.emptyList(); } catch (IOException e) { LOG.error("Failed to read config file", e); return Collections.emptyList(); } LOG.debug("Successfully parsed config"); return configs; } }
ParserUtils { public static List<JobConfig> parseConfig(FileSystem fs, Path jobFolderPath) { if (!pathExists(fs, jobFolderPath)) { return Collections.emptyList(); } Path configFilePath = new Path(jobFolderPath, Constants.TONY_FINAL_XML); try { if (!fs.exists(configFilePath)) { configFilePath = new Path(jobFolderPath, "config.xml"); } } catch (IOException e) { LOG.error("Encountered exception while checking existence of " + configFilePath, e); } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); List<JobConfig> configs = new ArrayList<>(); try (FSDataInputStream inStrm = fs.open(configFilePath)) { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inStrm); doc.getDocumentElement().normalize(); NodeList properties = doc.getElementsByTagName("property"); for (int i = 0; i < properties.getLength(); i++) { Node property = properties.item(i); if (property.getNodeType() == Node.ELEMENT_NODE) { Element p = (Element) property; JobConfig jobConf = new JobConfig(); String name = getNodeElementText(p, "name"); String value = getNodeElementText(p, "value"); if (name == null || value == null) { LOG.warn("Found config with null name or value. Name = " + name + ", value = " + value); continue; } jobConf.setName(name); jobConf.setValue(value); String finalText = getNodeElementText(p, "final"); if (finalText != null && finalText.equalsIgnoreCase("true")) { jobConf.setFinal(true); } jobConf.setSource(getNodeElementText(p, "source")); configs.add(jobConf); } } } catch (SAXException e) { LOG.error("Failed to parse config file", e); return Collections.emptyList(); } catch (ParserConfigurationException e) { LOG.error("Failed to init XML parser", e); return Collections.emptyList(); } catch (IOException e) { LOG.error("Failed to read config file", e); return Collections.emptyList(); } LOG.debug("Successfully parsed config"); return configs; } private  ParserUtils(); }
ParserUtils { public static List<JobConfig> parseConfig(FileSystem fs, Path jobFolderPath) { if (!pathExists(fs, jobFolderPath)) { return Collections.emptyList(); } Path configFilePath = new Path(jobFolderPath, Constants.TONY_FINAL_XML); try { if (!fs.exists(configFilePath)) { configFilePath = new Path(jobFolderPath, "config.xml"); } } catch (IOException e) { LOG.error("Encountered exception while checking existence of " + configFilePath, e); } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); List<JobConfig> configs = new ArrayList<>(); try (FSDataInputStream inStrm = fs.open(configFilePath)) { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inStrm); doc.getDocumentElement().normalize(); NodeList properties = doc.getElementsByTagName("property"); for (int i = 0; i < properties.getLength(); i++) { Node property = properties.item(i); if (property.getNodeType() == Node.ELEMENT_NODE) { Element p = (Element) property; JobConfig jobConf = new JobConfig(); String name = getNodeElementText(p, "name"); String value = getNodeElementText(p, "value"); if (name == null || value == null) { LOG.warn("Found config with null name or value. Name = " + name + ", value = " + value); continue; } jobConf.setName(name); jobConf.setValue(value); String finalText = getNodeElementText(p, "final"); if (finalText != null && finalText.equalsIgnoreCase("true")) { jobConf.setFinal(true); } jobConf.setSource(getNodeElementText(p, "source")); configs.add(jobConf); } } } catch (SAXException e) { LOG.error("Failed to parse config file", e); return Collections.emptyList(); } catch (ParserConfigurationException e) { LOG.error("Failed to init XML parser", e); return Collections.emptyList(); } catch (IOException e) { LOG.error("Failed to read config file", e); return Collections.emptyList(); } LOG.debug("Successfully parsed config"); return configs; } private  ParserUtils(); @VisibleForTesting static boolean isValidHistFileName(String fileName, String jobIdRegex); static String getJhistFilePath(FileSystem fs, Path jobFolderPath); static long getCompletedTimeFromJhistFileName(String jhistFileName); static JobMetadata parseMetadata(FileSystem fs, YarnConfiguration yarnConf, Path jobFolderPath, String jobIdRegex); static List<JobConfig> parseConfig(FileSystem fs, Path jobFolderPath); static List<Event> parseEvents(FileSystem fs, Path jobFolderPath); static List<JobEvent> mapEventToJobEvent(List<Event> events); static List<JobLog> mapEventToJobLog(List<Event> events, JobLogMetaData jobLogMetaData); static String getYearMonthDayDirectory(Date date, ZoneId zoneId); }
ParserUtils { public static List<JobConfig> parseConfig(FileSystem fs, Path jobFolderPath) { if (!pathExists(fs, jobFolderPath)) { return Collections.emptyList(); } Path configFilePath = new Path(jobFolderPath, Constants.TONY_FINAL_XML); try { if (!fs.exists(configFilePath)) { configFilePath = new Path(jobFolderPath, "config.xml"); } } catch (IOException e) { LOG.error("Encountered exception while checking existence of " + configFilePath, e); } DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); List<JobConfig> configs = new ArrayList<>(); try (FSDataInputStream inStrm = fs.open(configFilePath)) { DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(inStrm); doc.getDocumentElement().normalize(); NodeList properties = doc.getElementsByTagName("property"); for (int i = 0; i < properties.getLength(); i++) { Node property = properties.item(i); if (property.getNodeType() == Node.ELEMENT_NODE) { Element p = (Element) property; JobConfig jobConf = new JobConfig(); String name = getNodeElementText(p, "name"); String value = getNodeElementText(p, "value"); if (name == null || value == null) { LOG.warn("Found config with null name or value. Name = " + name + ", value = " + value); continue; } jobConf.setName(name); jobConf.setValue(value); String finalText = getNodeElementText(p, "final"); if (finalText != null && finalText.equalsIgnoreCase("true")) { jobConf.setFinal(true); } jobConf.setSource(getNodeElementText(p, "source")); configs.add(jobConf); } } } catch (SAXException e) { LOG.error("Failed to parse config file", e); return Collections.emptyList(); } catch (ParserConfigurationException e) { LOG.error("Failed to init XML parser", e); return Collections.emptyList(); } catch (IOException e) { LOG.error("Failed to read config file", e); return Collections.emptyList(); } LOG.debug("Successfully parsed config"); return configs; } private  ParserUtils(); @VisibleForTesting static boolean isValidHistFileName(String fileName, String jobIdRegex); static String getJhistFilePath(FileSystem fs, Path jobFolderPath); static long getCompletedTimeFromJhistFileName(String jhistFileName); static JobMetadata parseMetadata(FileSystem fs, YarnConfiguration yarnConf, Path jobFolderPath, String jobIdRegex); static List<JobConfig> parseConfig(FileSystem fs, Path jobFolderPath); static List<Event> parseEvents(FileSystem fs, Path jobFolderPath); static List<JobEvent> mapEventToJobEvent(List<Event> events); static List<JobLog> mapEventToJobLog(List<Event> events, JobLogMetaData jobLogMetaData); static String getYearMonthDayDirectory(Date date, ZoneId zoneId);  }