public static long getSubmitTimeMillisFromJobHistory ( byte [ ] jobHistoryRaw ) { long submitTimeMillis = 0 ; if ( null == jobHistoryRaw ) { return submitTimeMillis ; } HadoopVersion hv = JobHistoryFileParserFactory . getVersion ( jobHistoryRaw ) ; switch ( hv ) { case TWO : // look for the job submitted event, since that has the job submit time int startIndex = ByteUtil . indexOf ( jobHistoryRaw , Constants . JOB_SUBMIT_EVENT_BYTES , 0 ) ; if ( startIndex != - 1 ) { // now look for the submit time in this event int secondQuoteIndex = ByteUtil . indexOf ( jobHistoryRaw , Constants . SUBMIT_TIME_PREFIX_HADOOP2_BYTES , startIndex ) ; if ( secondQuoteIndex != - 1 ) { // read the string that contains the unix timestamp String submitTimeMillisString = Bytes . toString ( jobHistoryRaw , secondQuoteIndex + Constants . EPOCH_TIMESTAMP_STRING_LENGTH , Constants . EPOCH_TIMESTAMP_STRING_LENGTH ) ; try { submitTimeMillis = Long . parseLong ( submitTimeMillisString ) ; } catch ( NumberFormatException nfe ) { LOG . error ( " caught NFE during conversion of submit time " + submitTimeMillisString + " " + nfe . getMessage ( ) ) ; submitTimeMillis = 0 ; } } } break ; case ONE : default : // The start of the history file looks like this: // Meta VERSION="1" . // Job JOBID="job_20120101120000_12345" JOBNAME="..." // USER="username" SUBMIT_TIME="1339063492288" JOBCONF=" // First we look for the first occurrence of SUBMIT_TIME=" // Then we find the place of the next close quote " // Then our value is in between those two if valid at all. startIndex = ByteUtil . indexOf ( jobHistoryRaw , Constants . SUBMIT_TIME_PREFIX_BYTES , 0 ) ; if ( startIndex != - 1 ) { int prefixEndIndex = startIndex + Constants . SUBMIT_TIME_PREFIX_BYTES . length ; // Find close quote in the snippet, start looking where the prefix ends. int secondQuoteIndex = ByteUtil . indexOf ( jobHistoryRaw , Constants . QUOTE_BYTES , prefixEndIndex ) ; if ( secondQuoteIndex != - 1 ) { int numberLength = secondQuoteIndex - prefixEndIndex ; String submitTimeMillisString = Bytes . toString ( jobHistoryRaw , prefixEndIndex , numberLength ) ; try { submitTimeMillis = Long . parseLong ( submitTimeMillisString ) ; } catch ( NumberFormatException nfe ) { LOG . error ( " caught NFE during conversion of submit time " + submitTimeMillisString + " " + nfe . getMessage ( ) ) ; submitTimeMillis = 0 ; } } } break ; } return submitTimeMillis ; }
fetches the submit time from a raw job history byte representation