private void validateRackAwareness() {
    if (dataNodes.size() > 0) {
      Iterator<DataNode> dataNodeIter = dataNodes.iterator();
      boolean firstHasRackId = (dataNodeIter.next().getRackId() != null);
      while (dataNodeIter.hasNext()) {
        boolean currHasRackId = (dataNodeIter.next().getRackId() != null);
        if (firstHasRackId != currHasRackId) {
          throw new IllegalStateException(
              "dataNodes in datacenter: " + name + " must all have defined rack IDs or none at all");
        }
      }
      this.rackAware = firstHasRackId;
    }
  }
A datacenter can be marked as rack-aware if all nodes have defined rack IDs. This method throws an exception
if some nodes have rack IDs and some do not.  It also sets the {@code rackAware} flag to {@code true} if all
nodes have rack IDs.

@throws IllegalStateException if some nodes have defined rack IDs and some do not.
ambry-clustermap/src/main/java/com/github/ambry/clustermap/Datacenter.java