use of org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeSnapshotSetConfigVDSParameters in project ovirt-engine by oVirt.
the class UpdateGlusterVolumeSnapshotConfigCommand method executeCommand.
@Override
protected void executeCommand() {
Guid clusterId = getParameters().getClusterId();
Guid volumeId = getParameters().getVolumeId();
List<GlusterVolumeSnapshotConfig> fetchedConfigParams = glusterVolumeSnapshotConfigDao.getConfigByClusterId(clusterId);
// segregate the fetched cluster and volume specific config params
Map<String, GlusterVolumeSnapshotConfig> fetchedClusterConfigParams = new HashMap<>();
Map<String, GlusterVolumeSnapshotConfig> fetchedVolumeConfigParams = new HashMap<>();
for (GlusterVolumeSnapshotConfig param : fetchedConfigParams) {
if (Guid.isNullOrEmpty(param.getVolumeId())) {
fetchedClusterConfigParams.put(param.getParamName(), param);
} else if (volumeId != null && param.getVolumeId().equals(volumeId)) {
fetchedVolumeConfigParams.put(param.getParamName(), param);
}
}
List<GlusterVolumeSnapshotConfig> configParams = getParameters().getConfigParams();
// segregate the cluster and volume specific config params
Map<String, GlusterVolumeSnapshotConfig> clusterConfigParams = new HashMap<>();
Map<String, GlusterVolumeSnapshotConfig> volumeConfigParams = new HashMap<>();
for (GlusterVolumeSnapshotConfig param : configParams) {
if (Guid.isNullOrEmpty(param.getVolumeId())) {
clusterConfigParams.put(param.getParamName(), param);
} else {
volumeConfigParams.put(param.getParamName(), param);
}
}
// form the final list of updated config params
List<GlusterVolumeSnapshotConfig> updatedClusterConfigParams = new ArrayList<>();
for (GlusterVolumeSnapshotConfig cfgParam : clusterConfigParams.values()) {
GlusterVolumeSnapshotConfig fetchedCfgParam = fetchedClusterConfigParams.get(cfgParam.getParamName());
if (fetchedCfgParam != null && !fetchedCfgParam.getParamValue().equals(cfgParam.getParamValue())) {
updatedClusterConfigParams.add(cfgParam);
}
}
List<GlusterVolumeSnapshotConfig> updatedVolumeConfigParams = new ArrayList<>();
for (GlusterVolumeSnapshotConfig cfgParam : volumeConfigParams.values()) {
GlusterVolumeSnapshotConfig fetchedCfgParam = fetchedVolumeConfigParams.get(cfgParam.getParamName());
if (fetchedCfgParam != null && !fetchedCfgParam.getParamValue().equals(cfgParam.getParamValue())) {
updatedVolumeConfigParams.add(cfgParam);
}
}
List<GlusterVolumeSnapshotConfig> updatedConfigs = new ArrayList<>();
for (GlusterVolumeSnapshotConfig param : updatedClusterConfigParams) {
updatedConfigs.add(param);
}
for (GlusterVolumeSnapshotConfig param : updatedVolumeConfigParams) {
updatedConfigs.add(param);
}
for (GlusterVolumeSnapshotConfig config : updatedConfigs) {
VDSReturnValue retVal = runVdsCommand(VDSCommandType.SetGlusterVolumeSnapshotConfig, new GlusterVolumeSnapshotSetConfigVDSParameters(upServer.getId(), config));
if (!retVal.getSucceeded()) {
failedCfgs.add(config.getParamName());
updatesSuccessful = false;
} else {
if (config.getVolumeId() != null) {
glusterVolumeSnapshotConfigDao.updateConfigByVolumeIdAndName(config.getClusterId(), config.getVolumeId(), config.getParamName(), config.getParamValue());
} else {
glusterVolumeSnapshotConfigDao.updateConfigByClusterIdAndName(config.getClusterId(), config.getParamName(), config.getParamValue());
}
updatesSuccessful = true;
}
}
if (!updatesSuccessful) {
addCustomValue("failedSnapshotConfigs", failedCfgs.toString());
}
setSucceeded(true);
}
Aggregations