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++;