@Transactional
  static void fixConfigGroupsForDeletedServices() {
    Map<Long, ConfigGroup> configGroupMap = checkConfigGroupsForDeletedServices(false);
    Clusters clusters = injector.getInstance(Clusters.class);

    if (!MapUtils.isEmpty(configGroupMap)) {
      for (Map.Entry<Long, ConfigGroup> configGroupEntry : configGroupMap.entrySet()) {
        Long id = configGroupEntry.getKey();
        ConfigGroup configGroup = configGroupEntry.getValue();
        if (!StringUtils.isEmpty(configGroup.getServiceName())) {
          LOG.info("Deleting config group {} with id {} for deleted service {}",
                  configGroup.getName(), id, configGroup.getServiceName());
          try {
            Cluster cluster = clusters.getCluster(configGroup.getClusterName());
            cluster.deleteConfigGroup(id);
          } catch (AmbariException e) {
            // Ignore if cluster not found
          }
        }
        else {
          warning("The config group {} with id {} can not be fixed automatically because service name is missing.",
                  configGroup.getName(), id);
        }
      }
    }
  }
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