jobObject.put("mapper_spec", mapperSpec);
JSONArray shardArray = new JSONArray();
// Iterate in ascending order rather than the map's entrySet() order.
for (int i = 0; i < state.getTotalTaskCount(); i++) {
WorkerShardState shard = aggregateResult.getWorkerShardStates().get(i);
JSONObject shardObject = new JSONObject();
shardObject.put("shard_number", i);
if (shard == null) {
shardObject.put("active", false);
shardObject.put("result_status", "initializing");
shardObject.put("shard_description", ""); // TODO
} else {
boolean done = aggregateResult.getClosedWriters().get(i) != null;
if (done) {
shardObject.put("active", false);
// result_status is only displayed if active is false.
shardObject.put("result_status", "done");
} else {
shardObject.put("active", true);
}
shardObject.put("shard_description", ""); // TODO
shardObject.put("updated_timestamp_ms", shard.getMostRecentUpdateTimeMillis());
shardObject.put("last_work_item", shard.getLastWorkItem());
}
shardArray.put(shardObject);
}
jobObject.put("shards", shardArray);
}