@Transactional
  ConfigGroupEntity persistHostMapping(Collection<Host> hosts,
      ConfigGroupEntity configGroupEntity) {
    for (Host host : hosts) {
      HostEntity hostEntity = hostDAO.findById(host.getHostId());
      if (hostEntity != null) {
        ConfigGroupHostMappingEntity hostMappingEntity = new ConfigGroupHostMappingEntity();
        hostMappingEntity.setHostId(hostEntity.getHostId());
        hostMappingEntity.setHostEntity(hostEntity);
        hostMappingEntity.setConfigGroupEntity(configGroupEntity);
        hostMappingEntity.setConfigGroupId(configGroupEntity.getGroupId());
        configGroupEntity.getConfigGroupHostMappingEntities().add(hostMappingEntity);
        configGroupHostMappingDAO.create(hostMappingEntity);
      } else {
        LOG.warn(
            "The host {} has been removed from the cluster and cannot be added to the configuration group {}",
            host.getHostName(), configGroupName);
      }
    }

    return configGroupDAO.merge(configGroupEntity);
  }
Adds the collection of hosts to the configuration group.
ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java