/**
* Handle the get_job_detail AJAX command.
*/
@VisibleForTesting
static JSONObject handleGetJobDetail(String jobId) {
ShardedJobService shardedJobService = ShardedJobServiceFactory.getShardedJobService();
ShardedJobState state = shardedJobService.getJobState(jobId);
if (state == null) {
return null;
}
JSONObject jobObject = new JSONObject();
try {
jobObject.put("name", jobId); // For display
jobObject.put("mapreduce_id", jobId); // This is the sharedJobId but it needs be be called
// mapreduce_id for python compatibility.
jobObject.put("start_timestamp_ms", state.getStartTimeMillis());
if (state.getStatus().isActive()) {
jobObject.put("active", true);
jobObject.put("updated_timestamp_ms", System.currentTimeMillis());
} else {
jobObject.put("active", false);
jobObject.put("result_status", String.valueOf(state.getStatus().getStatusCode()));
jobObject.put("updated_timestamp_ms", state.getMostRecentUpdateTimeMillis());
}
jobObject.put("shards", state.getTotalTaskCount());
jobObject.put("active_shards", state.getActiveTaskCount());
JSONObject mapperParams = new JSONObject();
mapperParams.put("Shards completed",
state.getTotalTaskCount() - state.getActiveTaskCount());
mapperParams.put("Shards active", state.getActiveTaskCount());
mapperParams.put("Shards total", state.getTotalTaskCount());
JSONObject mapperSpec = new JSONObject();
mapperSpec.put("mapper_params", mapperParams);
jobObject.put("mapper_spec", mapperSpec);
JSONArray shardArray = new JSONArray();
Counters totalCounters = new CountersImpl();
int i = 0;
long[] workerCallCounts = new long[state.getTotalTaskCount()];
Iterator<IncrementalTaskState<IncrementalTask>> tasks = shardedJobService.lookupTasks(state);
while (tasks.hasNext()) {
IncrementalTaskState<?> taskState = tasks.next();
JSONObject shardObject = new JSONObject();
shardObject.put("shard_number", i);
shardObject.put("shard_description", taskState.getTaskId());