ParserUtils { @VisibleForTesting public static boolean isValidHistFileName(String fileName, String jobIdRegex) { if (Strings.isNullOrEmpty(fileName)) { LOG.error("No filename provided!"); return false; } String histFileNoExt = fileName.substring(0, fileName.indexOf('.')); String[] metadataArr = histFileNoExt.split("-"); if (metadataArr.length < 3) { LOG.error("Missing fields in metadata"); return false; } if (fileName.endsWith(Constants.INPROGRESS)) { return metadataArr[0].matches(jobIdRegex) && metadataArr[1].matches("\\d+") && metadataArr[2].matches(metadataArr[2].toLowerCase()); } Preconditions.checkArgument(metadataArr.length == 5); return metadataArr[0].matches(jobIdRegex) && metadataArr[1].matches("\\d+") && metadataArr[2].matches("\\d+") && metadataArr[3].matches(metadataArr[3].toLowerCase()) && metadataArr[4].equals(metadataArr[4].toUpperCase()); } 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);  }
@Test public void testIsValidHistFileNameTrue() { String fileName = "job123-1-1-user1-FAILED." + Constants.HISTFILE_SUFFIX; String jobRegex = "job\\d+"; assertTrue(ParserUtils.isValidHistFileName(fileName, jobRegex)); }
@Test public void testIsValidHistFileNameFalse() { String fileName1 = "application123-1-1-user1-FAILED." + Constants.HISTFILE_SUFFIX; String fileName2 = "job123-1-1-USER-SUCCEEDED." + Constants.HISTFILE_SUFFIX; String jobRegex = "job\\d+"; assertFalse(ParserUtils.isValidHistFileName(fileName1, jobRegex)); assertFalse(ParserUtils.isValidHistFileName(fileName2, jobRegex)); }