Search in sources :

Example 16 with GlusterVolumeOptionEntity

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());
    }
}
Also used : HashMap(java.util.HashMap) GlusterVolumeOptionEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity)

Example 17 with GlusterVolumeOptionEntity

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;
        });
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GlusterVolumeOptionEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity)

Example 18 with GlusterVolumeOptionEntity

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) GlusterVolumeOptionEntity(org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity) Guid(org.ovirt.engine.core.compat.Guid)

Aggregations

GlusterVolumeOptionEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionEntity)18 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)5 GlusterVolumeOptionParameters (org.ovirt.engine.core.common.action.gluster.GlusterVolumeOptionParameters)3 GlusterVolumeEntity (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity)3 Test (org.junit.Test)2 Option (org.ovirt.engine.api.model.Option)2 VDSReturnValue (org.ovirt.engine.core.common.vdscommands.VDSReturnValue)2 UICommand (org.ovirt.engine.ui.uicommonweb.UICommand)2 ConfirmationModel (org.ovirt.engine.ui.uicommonweb.models.ConfirmationModel)2 Set (java.util.Set)1 InOrder (org.mockito.InOrder)1 GlusterVolume (org.ovirt.engine.api.model.GlusterVolume)1 Options (org.ovirt.engine.api.model.Options)1 TransportType (org.ovirt.engine.api.model.TransportType)1 ActionReturnValue (org.ovirt.engine.core.common.action.ActionReturnValue)1 ResetGlusterVolumeOptionsParameters (org.ovirt.engine.core.common.action.gluster.ResetGlusterVolumeOptionsParameters)1 GlusterGeoRepSession (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSession)1 GlusterGeoRepSessionConfiguration (org.ovirt.engine.core.common.businessentities.gluster.GlusterGeoRepSessionConfiguration)1 GlusterVolumeOptionInfo (org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeOptionInfo)1