try {
wrt.write("[");
ManagementGraph jobManagementGraph = jobmanager.getManagementGraph(jobEvent.getJobID());
//Serialize job to json
wrt.write("{");
wrt.write("\"jobid\": \"" + jobEvent.getJobID() + "\",");
wrt.write("\"jobname\": \"" + jobEvent.getJobName()+"\",");
wrt.write("\"status\": \""+ jobEvent.getJobStatus() + "\",");
wrt.write("\"SCHEDULED\": "+ jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.SCHEDULED) + ",");
wrt.write("\"RUNNING\": "+ jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.RUNNING) + ",");
wrt.write("\"FINISHED\": "+ jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.FINISHED) + ",");
wrt.write("\"FAILED\": "+ jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.FAILED) + ",");
wrt.write("\"CANCELED\": "+ jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.CANCELED) + ",");
wrt.write("\"CREATED\": " + jobmanager.getArchive().getJobTime(jobEvent.getJobID(), JobStatus.CREATED)+",");
if (jobEvent.getJobStatus() == JobStatus.FAILED) {
ManagementGraphIterator managementGraphIterator = new ManagementGraphIterator(jobManagementGraph,true);
wrt.write("\"failednodes\": [");
HashSet<String> map = new HashSet<String>();
boolean first = true;
while (managementGraphIterator.hasNext()) {
ManagementVertex managementVertex = managementGraphIterator.next();
String instanceName = managementVertex.getInstanceName();
if (managementVertex.getExecutionState() == ExecutionState.FAILED && !map.contains(instanceName)) {
if (first) {
first = false;
} else {
wrt.write(",");
}
wrt.write("{");
wrt.write("\"node\": \"" + instanceName + "\",");
wrt.write("\"message\": \"" + StringUtils.escapeHtml(managementVertex.getOptMessage()) + "\"");
wrt.write("}");
map.add(instanceName);
}
}
wrt.write("],");
}
// Serialize ManagementGraph to json
wrt.write("\"groupvertices\": [");
boolean first = true;
for(ManagementGroupVertex groupVertex : jobManagementGraph.getGroupVerticesInTopologicalOrder()) {
//Write seperator between json objects
if(first) {
first = false;
} else {
wrt.write(","); }
wrt.write(groupVertex.toJson());
}
wrt.write("],");
// write accumulators
AccumulatorEvent accumulators = jobmanager.getAccumulatorResults(jobEvent.getJobID());
Map<String, Object> accMap = AccumulatorHelper.toResultMap(accumulators.getAccumulators());
wrt.write("\n\"accumulators\": [");
int i = 0;
for( Entry<String, Object> accumulator : accMap.entrySet()) {
wrt.write("{ \"name\": \""+accumulator.getKey()+" (" + accumulator.getValue().getClass().getName()+")\","
+ " \"value\": \""+accumulator.getValue().toString()+"\"}\n");
if(++i < accMap.size()) {
wrt.write(",");
}
}
wrt.write("],\n");
wrt.write("\"groupverticetimes\": {");
first = true;
for(ManagementGroupVertex groupVertex : jobManagementGraph.getGroupVerticesInTopologicalOrder()) {
if(first) {
first = false;
} else {
wrt.write(","); }