@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());
        shardObject.put("updated_timestamp_ms", taskState.getMostRecentUpdateMillis());
        if (taskState.getStatus().isActive()) {
          shardObject.put("active", true);
        } else {
          shardObject.put("active", false);
          shardObject.put("result_status", taskState.getStatus().getStatusCode());
        }
        IncrementalTask task = taskState.getTask();
        if (task instanceof IncrementalTaskWithContext) {
          IncrementalTaskContext context = ((IncrementalTaskWithContext) task).getContext();
          totalCounters.addAll(context.getCounters());
          workerCallCounts[i] = context.getWorkerCallCount();
          shardObject.put("last_work_item", context.getLastWorkItemString());
        }
        shardArray.put(shardObject);
        i++;
      }
      jobObject.put("counters", toJson(totalCounters));
      jobObject.put("shards", shardArray);
      jobObject.put("chart_width", getChartWidth(state.getTotalTaskCount()));
      jobObject.put("chart_url", getChartUrl(workerCallCounts));
      jobObject.put("chart_data", workerCallCounts);
    } catch (JSONException e) {
      throw new RuntimeException("Hard coded string is null", e);
    }

    return jobObject;
  }
@ 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 ) ; jobObject . put ( "mapreduce_id" , jobId ) ; 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 ( ) ) ; shardObject . put ( "updated_timestamp_ms" , taskState . getMostRecentUpdateMillis ( ) ) ; if ( taskState . getStatus ( ) . isActive ( ) ) { shardObject . put ( "active" , true ) ; } else { shardObject . put ( "active" , false ) ; shardObject . put ( "result_status" , taskState . getStatus ( ) . getStatusCode ( ) ) ; } IncrementalTask task = taskState . getTask ( ) ; if ( task instanceof IncrementalTaskWithContext ) { IncrementalTaskContext context = ( ( IncrementalTaskWithContext ) task ) . getContext ( ) ; totalCounters . addAll ( context . getCounters ( ) ) ; workerCallCounts [ i ] = context . getWorkerCallCount ( ) ; shardObject . put ( "last_work_item" , context . getLastWorkItemString ( ) ) ; } shardArray . put ( shardObject ) ; i ++ ; } jobObject . put ( "counters" , toJson ( totalCounters ) ) ; jobObject . put ( "shards" , shardArray ) ; jobObject . put ( "chart_width" , getChartWidth ( state . getTotalTaskCount ( ) ) ) ; jobObject . put ( "chart_url" , getChartUrl ( workerCallCounts ) ) ; jobObject . put ( "chart_data" , workerCallCounts ) ; } catch ( JSONException e ) { throw new RuntimeException ( "Hard coded string is null" , e ) ; } return jobObject ; }
Handle the get_job_detail AJAX command.