* Converts a JobInProgress object to its corresponding Thrift representation.
* @param job Input JobInProgress object
* @param includeTasks Include task information iff true
*/
public static ThriftJobInProgress toThrift(JobInProgress job, boolean includeTasks, JobTracker tracker) {
ThriftJobInProgress ret = new ThriftJobInProgress();
// Take the lock so we can do an atomic copy
synchronized(job) {
ret.setDesiredMaps(job.desiredMaps());
ret.setDesiredReduces(job.desiredReduces());
ret.setFinishedMaps(job.finishedMaps());
ret.setFinishedReduces(job.finishedReduces());
ret.setJobID(toThrift(job.getJobID()));
ret.setPriority(toThrift(job.getPriority()));
ret.setProfile(toThrift(job.getProfile()));
// Status lock is taken here
ret.setStatus(toThrift(job.getStatus()));
ret.setStartTime(job.getStartTime());
ret.setFinishTime(job.getFinishTime());
ret.setLaunchTime(job.getLaunchTime());
}
// No need to hang on to job lock now
// TODO(henry/bc): By releasing the lock above, getInitialViewTaskList
// may see a different view of the job and its task list. This
// could cause inconsistency between the values copied above and
// the tasks themselves, but no deadlocks/CMEs.
if (includeTasks) {
ret.setTasks(getInitialViewTaskList(job, tracker));
}
return ret;
}