use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity in project ovirt-engine by oVirt.
the class GlusterSyncJob method updateExistingOptions.
private void updateExistingOptions(final GlusterVolumeEntity volume, Collection<GlusterVolumeOptionEntity> entities) {
optionDao.updateAll("UpdateGlusterVolumeOption", entities);
for (final GlusterVolumeOptionEntity entity : entities) {
Map<String, String> customValues = new HashMap<>();
customValues.put(GlusterConstants.OPTION_KEY, entity.getKey());
customValues.put(GlusterConstants.OPTION_OLD_VALUE, volume.getOption(entity.getKey()).getValue());
customValues.put(GlusterConstants.OPTION_NEW_VALUE, entity.getValue());
logUtil.logAuditMessage(volume.getClusterId(), volume.getClusterName(), volume, null, AuditLogType.GLUSTER_VOLUME_OPTION_CHANGED_FROM_CLI, customValues);
log.info("Detected change in value of option '{}' of volume '{}' from '{}' to '{}'. Updating engine DB accordingly.", volume.getOption(entity.getKey()), volume.getName(), volume.getOption(entity.getKey()).getValue(), entity.getValue());
}
}
use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity in project ovirt-engine by oVirt.
the class GlusterSyncJob method updateExistingAndNewOptions.
private void updateExistingAndNewOptions(final GlusterVolumeEntity existingVolume, Collection<GlusterVolumeOptionEntity> fetchedOptions) {
Map<String, GlusterVolumeOptionEntity> existingOptions = new HashMap<>();
Map<String, GlusterVolumeOptionEntity> newOptions = new HashMap<>();
for (final GlusterVolumeOptionEntity fetchedOption : fetchedOptions) {
final GlusterVolumeOptionEntity existingOption = existingVolume.getOption(fetchedOption.getKey());
if (existingOption == null) {
newOptions.put(fetchedOption.getKey(), fetchedOption);
} else if (!existingOption.getValue().equals(fetchedOption.getValue())) {
fetchedOption.setId(existingOption.getId());
existingOptions.put(fetchedOption.getKey(), fetchedOption);
}
}
final List<GlusterVolumeOptionEntity> newOptionsSortedList = new ArrayList<>(newOptions.values());
final List<GlusterVolumeOptionEntity> existingOptionsSortedList = new ArrayList<>(existingOptions.values());
Collections.sort(newOptionsSortedList);
Collections.sort(existingOptionsSortedList);
// Insert the new options in a single transaction
if (!newOptionsSortedList.isEmpty()) {
TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
saveNewOptions(existingVolume, newOptionsSortedList);
return null;
});
}
// Update the existing options in a single transaction
if (!existingOptionsSortedList.isEmpty()) {
TransactionSupport.executeInScope(TransactionScopeOption.Required, () -> {
updateExistingOptions(existingVolume, existingOptionsSortedList);
return null;
});
}
}
use of org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity in project ovirt-engine by oVirt.
the class GlusterSyncJob method removeDeletedOptions.
@SuppressWarnings("serial")
private void removeDeletedOptions(GlusterVolumeEntity fetchedVolume, Collection<GlusterVolumeOptionEntity> existingOptions) {
List<Guid> idsToRemove = new ArrayList<>();
for (final GlusterVolumeOptionEntity existingOption : existingOptions) {
if (fetchedVolume.getOption(existingOption.getKey()) == null) {
idsToRemove.add(existingOption.getId());
log.info("Detected option '{}' reset on volume '{}'. Removing it from engine DB as well.", existingOption.getKey(), fetchedVolume.getName());
// Hence it is not required to log it as a removed option, as that would be misleading.
if (!GlusterConstants.OPTION_GROUP.equals(existingOption.getKey())) {
Map<String, String> customValues = new HashMap<>();
customValues.put(GlusterConstants.OPTION_KEY, existingOption.getKey());
customValues.put(GlusterConstants.OPTION_VALUE, existingOption.getValue());
logUtil.logAuditMessage(fetchedVolume.getClusterId(), fetchedVolume.getClusterName(), fetchedVolume, null, AuditLogType.GLUSTER_VOLUME_OPTION_RESET_FROM_CLI, customValues);
}
}
}
if (!idsToRemove.isEmpty()) {
try {
optionDao.removeAll(idsToRemove);
} catch (Exception e) {
log.error("Error while removing options of volume '{}' from database: {}", fetchedVolume.getName(), e.getMessage());
log.debug("Exception", e);
}
}
}
Aggregations