@ Override public List < TaskStatusEvent > getJobHistory ( final JobId jobId , final String host ) throws JobDoesNotExistException { final Job descriptor = getJob ( jobId ) ; if ( descriptor == null ) { throw new JobDoesNotExistException ( jobId ) ; } final ZooKeeperClient client = provider . get ( "getJobHistory" ) ; final List < String > hosts ; try { hosts = ( ! isNullOrEmpty ( host ) ) ? singletonList ( host ) : client . getChildren ( Paths . historyJobHosts ( jobId ) ) ; } catch ( NoNodeException e ) { return emptyList ( ) ; } catch ( KeeperException e ) { throw new RuntimeException ( e ) ; } final List < TaskStatusEvent > jsEvents = Lists . newArrayList ( ) ; for ( final String h : hosts ) { final List < String > events ; try { events = client . getChildren ( Paths . historyJobHostEvents ( jobId , h ) ) ; } catch ( NoNodeException e ) { continue ; } catch ( KeeperException e ) { throw new RuntimeException ( e ) ; } for ( final String event : events ) { try { final byte [ ] data = client . getData ( Paths . historyJobHostEventsTimestamp ( jobId , h , Long . valueOf ( event ) ) ) ; final TaskStatus status = Json . read ( data , TaskStatus . class ) ; jsEvents . add ( new TaskStatusEvent ( status , Long . valueOf ( event ) , h ) ) ; } catch ( NoNodeException e ) { // ignore, it went away before we read it } catch ( KeeperException | IOException e ) { throw new RuntimeException ( e ) ; } } } return Ordering . from ( EVENT_COMPARATOR ) . sortedCopy ( jsEvents ) ; }
Given a jobId and host returns the N most recent events in its history on that host in the cluster .