static Map<Long, ConfigGroup> checkConfigGroupsForDeletedServices(boolean warnIfFound) {
    Map<Long, ConfigGroup> configGroupMap = new HashMap<>();
    Clusters clusters = injector.getInstance(Clusters.class);
    Map<String, Cluster> clusterMap = clusters.getClusters();
    StringBuilder output = new StringBuilder("[(ConfigGroup, Service) => ");

    if (!MapUtils.isEmpty(clusterMap)) {
      for (Cluster cluster : clusterMap.values()) {
        Map<Long, ConfigGroup> configGroups = cluster.getConfigGroups();
        Map<String, Service> services = cluster.getServices();

        if (!MapUtils.isEmpty(configGroups)) {
          for (ConfigGroup configGroup : configGroups.values()) {
            if (!services.containsKey(configGroup.getServiceName())) {
              configGroupMap.put(configGroup.getId(), configGroup);
              output.append("( ");
              output.append(configGroup.getName());
              output.append(", ");
              output.append(configGroup.getServiceName());
              output.append(" ), ");
            }
          }
        }
      }
    }

    if (warnIfFound && !configGroupMap.isEmpty()) {
      output.replace(output.lastIndexOf(","), output.length(), "]");
      warning("You have config groups present in the database with no " +
        "corresponding service found, {}. Run --auto-fix-database to fix " +
          "this automatically. Please backup Ambari Server database before running --auto-fix-database.", output.toString());
    }

    return configGroupMap;
  }
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