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(","); }
// Calculate start and end time for groupvertex
long started = Long.MAX_VALUE;
long ended = 0;
// Take earliest running state and latest endstate of groupmembers
for(int j = 0; j < groupVertex.getNumberOfGroupMembers(); j++) {
ManagementVertex vertex = groupVertex.getGroupMember(j);
long running = jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.RUNNING);
if(running != 0 && running < started) {
started = running;
}
long finished = jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.FINISHED);
long canceled = jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.CANCELED);
long failed = jobmanager.getArchive().getVertexTime(jobEvent.getJobID(), vertex.getID(), ExecutionState.FAILED);
if(finished != 0 && finished > ended) {
ended = finished;
}