static Map<Long, Set<Long>> checkConfigGroupHostMapping(boolean warnIfFound) {
    LOG.info("Checking config group host mappings");
    Map<Long, Set<Long>> nonMappedHostIds = new HashMap<>();
    Clusters clusters = injector.getInstance(Clusters.class);
    Map<String, Cluster> clusterMap = clusters.getClusters();
    StringBuilder output = new StringBuilder("[(ConfigGroup, Service, HostCount) => ");

    if (!MapUtils.isEmpty(clusterMap)) {
      for (Cluster cluster : clusterMap.values()) {
        Map<Long, ConfigGroup> configGroups = cluster.getConfigGroups();
        Map<String, Host> clusterHosts = clusters.getHostsForCluster(cluster.getClusterName());

        if (!MapUtils.isEmpty(configGroups) && !MapUtils.isEmpty(clusterHosts)) {
          for (ConfigGroup configGroup : configGroups.values()) {
            // Based on current implementation of ConfigGroupImpl the
            // host mapping would be loaded only if the host actually exists
            // in the host table
            Map<Long, Host> hosts = configGroup.getHosts();
            boolean addToOutput = false;
            Set<String> hostnames = new HashSet<>();
            if (!MapUtils.isEmpty(hosts)) {
              for (Host host : hosts.values()) {
                // Lookup by hostname - It does have a unique constraint
                if (!clusterHosts.containsKey(host.getHostName())) {
                  Set<Long> hostIds = nonMappedHostIds.computeIfAbsent(configGroup.getId(), configGroupId -> new HashSet<>());
                  hostIds.add(host.getHostId());
                  hostnames.add(host.getHostName());
                  addToOutput = true;
                }
              }
            }
            if (addToOutput) {
              output.append("( ");
              output.append(configGroup.getName());
              output.append(", ");
              output.append(configGroup.getTag());
              output.append(", ");
              output.append(hostnames);
              output.append(" ), ");
            }
          }
        }
      }
    }
    if (!MapUtils.isEmpty(nonMappedHostIds) && warnIfFound) {
      output.replace(output.lastIndexOf(","), output.length(), "]");
      warning("You have config group host mappings with hosts that are no " +
        "longer associated with the cluster, {}. Run --auto-fix-database to " +
        "fix this automatically. Alternatively, you can remove this mapping " +
        "from the UI. Please backup Ambari Server database before running --auto-fix-database.", output.toString());
    }

    return nonMappedHostIds;
  }
This method checks if there are any ConfigGroup host mappings with hosts
that are not longer a part of the cluster.
ambari-server/src/main/java/org/apache/ambari/server/checks/DatabaseConsistencyCheckHelper.java