private static Map<String, String> getHostToRackMap(String rackYamlFile)
            throws IOException {
      YamlReader yamlReader = new YamlReader(new FileReader(rackYamlFile));
      Map rackHostsMap;
      try {
        rackHostsMap = (Map) yamlReader.read();
      } finally {
        yamlReader.close();
      }
      Map racks = (Map) rackHostsMap.get(RACKS_YAML_KEY_NAME);
      Map<String, String> hostToRackMap = new HashMap<>();
      for (Map.Entry entry : (Set<Map.Entry>) racks.entrySet()) {
        Map rackInfoMap = (Map) entry.getValue();
        String rackName = (String) entry.getKey();
        if (rackInfoMap.containsKey(HOSTS_YAML_KEY_NAME)) {
          List<String> hostList = (List<String>) rackInfoMap.get(HOSTS_YAML_KEY_NAME);
          for (String host : hostList) {
            hostToRackMap.put(host, rackName);
          }
        }
        if (rackInfoMap.containsKey(HOST_GROUPS_YAML_KEY_NAME)) {
          List<Map> hostGroups = (List<Map>) rackInfoMap.get(HOST_GROUPS_YAML_KEY_NAME);
          for (Map hostGroup : hostGroups) {
            if (hostGroup.containsKey(HOSTS_YAML_KEY_NAME)) {
              List<String> hostList = (List<String>) hostGroup.get(HOSTS_YAML_KEY_NAME);
              for (String host : hostList) {
                hostToRackMap.put(host, rackName);
              }
            }
          }
        }
      }
      return hostToRackMap;
    }
Utility method to organize and return Rack to Hosts mapping for given rack yaml file

@param hosts        : All hosts that are part of current group
@param rackYamlFile : file path for yaml containing rack to hosts mapping
                       e.g ambari-server/src/examples/rack_hosts.yaml
@return
ambari-server/src/main/java/org/apache/ambari/server/stack/upgrade/Grouping.java