@Override
  BalanceAction generate(BalancerClusterState cluster) {
    int serverIndex = pickRandomServer(cluster);
    if (cluster.numServers <= 1 || serverIndex == -1) {
      return BalanceAction.NULL_ACTION;
    }

    int regionIndex =
      selectCoHostedRegionPerGroup(cluster.colocatedReplicaCountsPerServer[serverIndex],
        cluster.regionsPerServer[serverIndex], cluster.regionIndexToPrimaryIndex);

    // if there are no pairs of region replicas co-hosted, default to random generator
    if (regionIndex == -1) {
      // default to randompicker
      return randomGenerator.generate(cluster);
    }

    int toServerIndex = pickOtherRandomServer(cluster, serverIndex);
    int toRegionIndex = pickRandomRegion(cluster, toServerIndex, 0.9f);
    return getAction(serverIndex, regionIndex, toServerIndex, toRegionIndex);
  }
Randomly select one regionIndex out of all region replicas co-hosted in the same group (a group
is a server, host or rack)
@param colocatedReplicaCountsPerGroup either Cluster.colocatedReplicaCountsPerServer,
                                      colocatedReplicaCountsPerHost or
                                      colocatedReplicaCountsPerRack
@param regionsPerGroup                either Cluster.regionsPerServer, regionsPerHost or
                                      regionsPerRack
@param regionIndexToPrimaryIndex      Cluster.regionsIndexToPrimaryIndex
@return a regionIndex for the selected primary or -1 if there is no co-locating
hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/RegionReplicaCandidateGenerator.java