in hyracks/hyracks-control/hyracks-control-cc/src/main/java/org/apache/hyracks/control/cc/job/JobRun.java [239:398]
public JSONObject toJSON() throws JSONException {
JSONObject result = new JSONObject();
result.put("job-id", jobId.toString());
result.put("status", getStatus());
result.put("create-time", getCreateTime());
result.put("start-time", getCreateTime());
result.put("end-time", getCreateTime());
JSONArray aClusters = new JSONArray();
for (ActivityCluster ac : acg.getActivityClusterMap().values()) {
JSONObject acJSON = new JSONObject();
acJSON.put("activity-cluster-id", String.valueOf(ac.getId()));
JSONArray activitiesJSON = new JSONArray();
for (ActivityId aid : ac.getActivityMap().keySet()) {
activitiesJSON.put(aid);
}
acJSON.put("activities", activitiesJSON);
JSONArray dependenciesJSON = new JSONArray();
for (ActivityCluster dependency : ac.getDependencies()) {
dependenciesJSON.put(String.valueOf(dependency.getId()));
}
acJSON.put("dependencies", dependenciesJSON);
ActivityClusterPlan acp = activityClusterPlanMap.get(ac.getId());
if (acp == null) {
acJSON.put("plan", (Object) null);
} else {
JSONObject planJSON = new JSONObject();
JSONArray acTasks = new JSONArray();
for (Map.Entry<ActivityId, ActivityPlan> e : acp.getActivityPlanMap().entrySet()) {
ActivityPlan acPlan = e.getValue();
JSONObject entry = new JSONObject();
entry.put("activity-id", e.getKey().toString());
ActivityPartitionDetails apd = acPlan.getActivityPartitionDetails();
entry.put("partition-count", apd.getPartitionCount());
JSONArray inPartCountsJSON = new JSONArray();
int[] inPartCounts = apd.getInputPartitionCounts();
if (inPartCounts != null) {
for (int i : inPartCounts) {
inPartCountsJSON.put(i);
}
}
entry.put("input-partition-counts", inPartCountsJSON);
JSONArray outPartCountsJSON = new JSONArray();
int[] outPartCounts = apd.getOutputPartitionCounts();
if (outPartCounts != null) {
for (int o : outPartCounts) {
outPartCountsJSON.put(o);
}
}
entry.put("output-partition-counts", outPartCountsJSON);
JSONArray tasks = new JSONArray();
for (Task t : acPlan.getTasks()) {
JSONObject task = new JSONObject();
task.put("task-id", t.getTaskId().toString());
JSONArray dependentTasksJSON = new JSONArray();
for (TaskId dependent : t.getDependents()) {
dependentTasksJSON.put(dependent.toString());
}
task.put("dependents", dependentTasksJSON);
JSONArray dependencyTasksJSON = new JSONArray();
for (TaskId dependency : t.getDependencies()) {
dependencyTasksJSON.put(dependency.toString());
}
task.put("dependencies", dependencyTasksJSON);
tasks.put(task);
}
entry.put("tasks", tasks);
acTasks.put(entry);
}
planJSON.put("activities", acTasks);
JSONArray tClusters = new JSONArray();
for (TaskCluster tc : acp.getTaskClusters()) {
JSONObject c = new JSONObject();
c.put("task-cluster-id", String.valueOf(tc.getTaskClusterId()));
JSONArray tasks = new JSONArray();
for (Task t : tc.getTasks()) {
tasks.put(t.getTaskId().toString());
}
c.put("tasks", tasks);
JSONArray prodParts = new JSONArray();
for (PartitionId p : tc.getProducedPartitions()) {
prodParts.put(p.toString());
}
c.put("produced-partitions", prodParts);
JSONArray reqdParts = new JSONArray();
for (PartitionId p : tc.getRequiredPartitions()) {
reqdParts.put(p.toString());
}
c.put("required-partitions", reqdParts);
JSONArray attempts = new JSONArray();
List<TaskClusterAttempt> tcAttempts = tc.getAttempts();
if (tcAttempts != null) {
for (TaskClusterAttempt tca : tcAttempts) {
JSONObject attempt = new JSONObject();
attempt.put("attempt", tca.getAttempt());
attempt.put("status", tca.getStatus());
attempt.put("start-time", tca.getStartTime());
attempt.put("end-time", tca.getEndTime());
JSONArray taskAttempts = new JSONArray();
for (TaskAttempt ta : tca.getTaskAttempts().values()) {
JSONObject taskAttempt = new JSONObject();
taskAttempt.put("task-id", ta.getTaskAttemptId().getTaskId());
taskAttempt.put("task-attempt-id", ta.getTaskAttemptId());
taskAttempt.put("status", ta.getStatus());
taskAttempt.put("node-id", ta.getNodeId());
taskAttempt.put("start-time", ta.getStartTime());
taskAttempt.put("end-time", ta.getEndTime());
List<Exception> exceptions = ta.getExceptions();
if (exceptions != null && !exceptions.isEmpty()) {
List<Exception> filteredExceptions = ExceptionUtils.getActualExceptions(exceptions);
for (Exception exception : filteredExceptions) {
StringWriter exceptionWriter = new StringWriter();
exception.printStackTrace(new PrintWriter(exceptionWriter));
taskAttempt.put("failure-details", exceptionWriter.toString());
}
}
taskAttempts.put(taskAttempt);
}
attempt.put("task-attempts", taskAttempts);
attempts.put(attempt);
}
}
c.put("attempts", attempts);
tClusters.put(c);
}
planJSON.put("task-clusters", tClusters);
acJSON.put("plan", planJSON);
}
aClusters.put(acJSON);
}
result.put("activity-clusters", aClusters);
result.put("profile", profile.toJSON());
return result;
}