private void build(Map<String, Map<String, HostRoleCommand>> hostRoleCommands) {
    graph = new TreeMap<>();

    for (String host : hostRoleCommands.keySet()) {
      for (String role : hostRoleCommands.get(host).keySet()) {
        HostRoleCommand hostRoleCommand = hostRoleCommands.get(host).get(role);
        RoleGraphNode rgn;
        if (graph.get(role) == null) {
          rgn = new RoleGraphNode(hostRoleCommand.getRole(),
              getRoleCommand(hostRoleCommand));
          graph.put(role, rgn);
        }
        rgn = graph.get(role);
        rgn.addHost(host);
      }
    }

    // In case commandExecutionType == DEPENDENCY_ORDERED there will be only one stage, thus no need to add edges to
    // the graph
    if (commandExecutionType == CommandExecutionType.STAGE) {
      if (null != roleDependencies) {
        //Add edges
        for (String roleI : graph.keySet()) {
          for (String roleJ : graph.keySet()) {
            if (!roleI.equals(roleJ)) {
              RoleGraphNode rgnI = graph.get(roleI);
              RoleGraphNode rgnJ = graph.get(roleJ);
              int order = roleDependencies.order(rgnI, rgnJ);
              if (order == -1) {
                rgnI.addEdge(rgnJ);
              } else if (order == 1) {
                rgnJ.addEdge(rgnI);
              }
            }
          }
        }
      }
    }
  }
Initializes {@link #graph} with the supplied unordered commands. The
commands specified are in the following format: Input:

<pre>
{c6401={NAMENODE=STOP}, c6402={DATANODE=STOP}, NODEMANAGER=STOP}}
</pre>

@param hostRoleCommands
         the unordered commands to build a DAG from. The map is keyed first
         by host and the for each host it is keyed by {@link Role} to
         {@link RoleCommand}.
ambari-server/src/main/java/org/apache/ambari/server/stageplanner/RoleGraph.java