if (configType.contains(log4jConfigTypeContains)) {
ClusterConfigEntityPK configEntityPK = new ClusterConfigEntityPK();
configEntityPK.setClusterId(clusterId);
configEntityPK.setType(configType);
configEntityPK.setTag(defaultVersionTag);
ClusterConfigEntity configEntity = clusterDAO.findConfig(configEntityPK);
if (configEntity == null) {
String filename = configType + ".xml";
Map<String, String> properties = new HashMap<String, String>();
for (PropertyInfo propertyInfo : serviceInfo.getProperties()) {
if (filename.equals(propertyInfo.getFilename())) {
properties.put(propertyInfo.getName(), propertyInfo.getValue());
}
}
if (!properties.isEmpty()) {
String configData = gson.toJson(properties);
configEntity = new ClusterConfigEntity();
configEntity.setClusterId(clusterId);
configEntity.setType(configType);
configEntity.setTag(defaultVersionTag);
configEntity.setData(configData);
configEntity.setTimestamp(System.currentTimeMillis());
configEntity.setClusterEntity(clusterEntity);
LOG.debug("Creating new " + configType + " config...");
clusterDAO.createConfig(configEntity);
Collection<ClusterConfigMappingEntity> entities =
clusterEntity.getConfigMappingEntities();
ClusterConfigMappingEntity clusterConfigMappingEntity =
new ClusterConfigMappingEntity();
clusterConfigMappingEntity.setClusterEntity(clusterEntity);
clusterConfigMappingEntity.setClusterId(clusterId);
clusterConfigMappingEntity.setType(configType);
clusterConfigMappingEntity.setCreateTimestamp(
Long.valueOf(System.currentTimeMillis()));
clusterConfigMappingEntity.setSelected(1);
clusterConfigMappingEntity.setUser(defaultUser);
clusterConfigMappingEntity.setVersion(configEntity.getTag());
entities.add(clusterConfigMappingEntity);
clusterDAO.merge(clusterEntity);
}
}
}