@Transactional
  void persistConfigMapping(ClusterEntity clusterEntity, ConfigGroupEntity configGroupEntity,
      Map<String, Config> configurations) throws AmbariException {
    configGroupConfigMappingDAO.removeAllByGroup(configGroupEntity.getGroupId());
    configGroupEntity.setConfigGroupConfigMappingEntities(new HashSet<>());

    if (configurations != null && !configurations.isEmpty()) {
      for (Entry<String, Config> entry : configurations.entrySet()) {
        Config config = entry.getValue();
        ClusterConfigEntity clusterConfigEntity = clusterDAO.findConfig
          (cluster.getClusterId(), config.getType(), config.getTag());

        if (clusterConfigEntity == null) {
          String serviceName = getServiceName();
          Service service = cluster.getService(serviceName);

          config = configFactory.createNew(service.getDesiredStackId(), config.getType(), cluster,
              config.getTag(), config.getProperties(), config.getPropertiesAttributes(), true);

          entry.setValue(config);

          clusterConfigEntity = clusterDAO.findConfig(cluster.getClusterId(), config.getType(),
              config.getTag());
        }

        ConfigGroupConfigMappingEntity configMappingEntity =
          new ConfigGroupConfigMappingEntity();

        configMappingEntity.setTimestamp(System.currentTimeMillis());
        configMappingEntity.setClusterId(clusterEntity.getClusterId());
        configMappingEntity.setClusterConfigEntity(clusterConfigEntity);
        configMappingEntity.setConfigGroupEntity(configGroupEntity);
        configMappingEntity.setConfigGroupId(configGroupEntity.getGroupId());
        configMappingEntity.setConfigType(clusterConfigEntity.getType());
        configMappingEntity.setVersionTag(clusterConfigEntity.getTag());
        configGroupConfigMappingDAO.create(configMappingEntity);
        configGroupEntity.getConfigGroupConfigMappingEntities().add
          (configMappingEntity);

        configGroupEntity = configGroupDAO.merge(configGroupEntity);
      }
    }
  }
Persist config group config mapping and create configs if not in DB

@param clusterEntity
@throws Exception
ambari-server/src/main/java/org/apache/ambari/server/state/configgroup/ConfigGroupImpl.java