public String stringifyGraph() {
    StringBuilder builder = new StringBuilder();
    builder.append("Graph:\n");
    for (String role : graph.keySet()) {
      builder.append(graph.get(role));
      for (RoleGraphNode rgn : graph.get(role).getEdges()) {
        builder.append(" --> ");
        builder.append(rgn);
      }
      builder.append("\n");
    }
    return builder.toString();
  }
Assumes there are no incoming edges.
ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java