private ConfigGroupEntity createConfigGroup(String clusterName,
String groupName, String tag, String desc, List<HostEntity> hosts,
List<ClusterConfigEntity> configs) throws Exception {
ConfigGroupEntity configGroupEntity = new ConfigGroupEntity();
ClusterEntity clusterEntity = new ClusterEntity();
clusterEntity.setClusterName(clusterName);
clusterDAO.create(clusterEntity);
configGroupEntity.setClusterEntity(clusterEntity);
configGroupEntity.setClusterId(clusterEntity.getClusterId());
configGroupEntity.setGroupName(groupName);
configGroupEntity.setDescription(desc);
configGroupEntity.setTag(tag);
configGroupDAO.create(configGroupEntity);
if (hosts != null && !hosts.isEmpty()) {
List<ConfigGroupHostMappingEntity> hostMappingEntities = new
ArrayList<ConfigGroupHostMappingEntity>();
for (HostEntity host : hosts) {
hostDAO.create(host);
ConfigGroupHostMappingEntity hostMappingEntity = new
ConfigGroupHostMappingEntity();
hostMappingEntity.setHostname(host.getHostName());
hostMappingEntity.setHostEntity(host);
hostMappingEntity.setConfigGroupEntity(configGroupEntity);
hostMappingEntity.setConfigGroupId(configGroupEntity.getGroupId());
hostMappingEntities.add(hostMappingEntity);
configGroupHostMappingDAO.create(hostMappingEntity);
}
configGroupEntity.setConfigGroupHostMappingEntities(hostMappingEntities);
configGroupDAO.merge(configGroupEntity);
}
if (configs != null && !configs.isEmpty()) {
List<ConfigGroupConfigMappingEntity> configMappingEntities = new
ArrayList<ConfigGroupConfigMappingEntity>();
for (ClusterConfigEntity config : configs) {
config.setClusterEntity(clusterEntity);
config.setClusterId(clusterEntity.getClusterId());
clusterDAO.createConfig(config);
ConfigGroupConfigMappingEntity configMappingEntity = new
ConfigGroupConfigMappingEntity();
configMappingEntity.setClusterId(clusterEntity.getClusterId());
configMappingEntity.setClusterConfigEntity(config);
configMappingEntity.setConfigGroupEntity(configGroupEntity);
configMappingEntity.setConfigGroupId(configGroupEntity.getGroupId());
configMappingEntity.setVersionTag(config.getTag());
configMappingEntity.setConfigType(config.getType());