@Transactional
  void replaceHostMappings(Map<Long, Host> hosts) {
    ConfigGroupEntity configGroupEntity = getConfigGroupEntity();

    // Delete existing mappings and create new ones
    configGroupHostMappingDAO.removeAllByGroup(configGroupEntity.getGroupId());
    configGroupEntity.setConfigGroupHostMappingEntities(new HashSet<>());

    if (hosts != null && !hosts.isEmpty()) {
      configGroupEntity = persistHostMapping(hosts.values(), configGroupEntity);
    }
  }
Replaces all existing host mappings with the new collection of hosts.
ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java