Shubhendu Tripathi has uploaded a new change for review. Change subject: gluster: Add audit log message while volume snapshot sync ......................................................................
gluster: Add audit log message while volume snapshot sync Added code to log audit log messages while syncing the gluster volume snapshots from the gluster CLI to the engine. Change-Id: I81636a86f48e977f47a4e5cbbd042446e3483ddf Bug-Url: https://bugzilla.redhat.com/1223370 Signed-off-by: Shubhendu Tripathi <shtri...@redhat.com> --- M backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJob.java M backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJobTest.java M backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java M backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties 4 files changed, 105 insertions(+), 16 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/70/42270/1 diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJob.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJob.java index 3bc12fc..4427f75 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJob.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJob.java @@ -5,12 +5,14 @@ import java.util.List; import java.util.Map; +import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.businessentities.VDS; import org.ovirt.engine.core.common.businessentities.VDSGroup; import org.ovirt.engine.core.common.businessentities.gluster.GlusterSnapshotConfigInfo; import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity; import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotConfig; import org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity; +import org.ovirt.engine.core.common.constants.gluster.GlusterConstants; import org.ovirt.engine.core.common.errors.VdcBLLException; import org.ovirt.engine.core.common.errors.VdcBllErrors; import org.ovirt.engine.core.common.vdscommands.VDSCommandType; @@ -124,6 +126,7 @@ fetchedSnapshotsMap.put(fetchedSnapshot.getId(), fetchedSnapshot); } + VDSGroup cluster = getClusterDao().get(clusterId); List<GlusterVolumeSnapshotEntity> existingSnapshots = getGlusterVolumeSnapshotDao().getAllByClusterId(clusterId); Map<Guid, GlusterVolumeSnapshotEntity> existingSnapshotsMap = new HashMap<>(); @@ -135,22 +138,52 @@ List<GlusterVolumeSnapshotEntity> newlyAddedSnapshots = new ArrayList<>(); List<GlusterVolumeSnapshotEntity> deletedSnapshots = new ArrayList<>(); - for (GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) { + for (final GlusterVolumeSnapshotEntity fetchedSnapshot : fetchedSnapshots) { GlusterVolumeSnapshotEntity correspondingExistingSnapshot = existingSnapshotsMap.get(fetchedSnapshot.getId()); if (correspondingExistingSnapshot == null) { + final GlusterVolumeEntity volume = getGlusterVolumeDao().getById(fetchedSnapshot.getVolumeId()); newlyAddedSnapshots.add(fetchedSnapshot); + log.debug("Detected new gluster volume snapshot '{}' for volume '{}' on cluster: '{}'", + fetchedSnapshot.getSnapshotName(), + volume.getName(), + cluster.getName()); + logUtil.logAuditMessage(clusterId, + volume, + null, + AuditLogType.GLUSTER_VOLUME_SNAPSHOT_DETECTED_NEW, + new HashMap<String, String>() { + { + put("snapName", fetchedSnapshot.getSnapshotName()); + put(GlusterConstants.VOLUME_NAME, volume.getName()); + } + }); } else if (correspondingExistingSnapshot.getStatus() != fetchedSnapshot.getStatus()) { correspondingExistingSnapshot.setStatus(fetchedSnapshot.getStatus()); updatedSnapshots.add(correspondingExistingSnapshot); } } - for (GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) { + for (final GlusterVolumeSnapshotEntity existingSnapshot : existingSnapshots) { GlusterVolumeSnapshotEntity correspondingFetchedSnapshot = fetchedSnapshotsMap.get(existingSnapshot.getId()); if (correspondingFetchedSnapshot == null) { + final GlusterVolumeEntity volume = getGlusterVolumeDao().getById(existingSnapshot.getVolumeId()); deletedSnapshots.add(existingSnapshot); + log.debug("Gluster volume snapshot '{}' detected removed for volume '{}' on cluster: '{}'", + existingSnapshot.getSnapshotName(), + volume.getName(), + cluster.getName()); + logUtil.logAuditMessage(clusterId, + volume, + null, + AuditLogType.GLUSTER_VOLUME_SNAPSHOT_DELETED_FROM_CLI, + new HashMap<String, String>() { + { + put("snapName", existingSnapshot.getSnapshotName()); + put(GlusterConstants.VOLUME_NAME, volume.getName()); + } + }); } } @@ -167,10 +200,11 @@ } private void addOrUpdateSnapshotsConfig(Guid clusterId, GlusterSnapshotConfigInfo configInfo) { + VDSGroup cluster = getClusterDao().get(clusterId); try (EngineLock lock = acquireVolumeSnapshotLock(clusterId)) { for (Map.Entry<String, String> entry : configInfo.getClusterConfigOptions().entrySet()) { if (entry.getValue() != null) { - addOrUpdateClusterConfig(clusterId, entry.getKey(), entry.getValue()); + addOrUpdateClusterConfig(cluster, entry.getKey(), entry.getValue()); } } } catch (Exception e) { @@ -192,8 +226,8 @@ if (volumeConfig != null) { for (Map.Entry<String, String> entry1 : volumeConfig.entrySet()) { if (entry.getValue() != null) { - addOrUpdateVolumeConfig(clusterId, - volume.getId(), + addOrUpdateVolumeConfig(cluster, + volume, entry1.getKey(), entry1.getValue()); } @@ -208,39 +242,72 @@ } } - private void addOrUpdateClusterConfig(Guid clusterId, String paramName, String paramValue) { + private void addOrUpdateClusterConfig(VDSGroup cluster, final String paramName, final String paramValue) { GlusterVolumeSnapshotConfig param = new GlusterVolumeSnapshotConfig(); - param.setClusterId(clusterId); + param.setClusterId(cluster.getId()); param.setVolumeId(null); param.setParamName(paramName); param.setParamValue(paramValue); GlusterVolumeSnapshotConfig existingParamDetail = - getGlusterVolumeSnapshotConfigDao().getConfigByClusterIdAndName(clusterId, + getGlusterVolumeSnapshotConfigDao().getConfigByClusterIdAndName(cluster.getId(), paramName); if (existingParamDetail == null) { getGlusterVolumeSnapshotConfigDao().save(param); + log.debug("Detected new gluster volume snapshot configuration '{}' with value '{}' for cluster: '{}'", + paramName, + paramValue, + cluster.getName()); + logUtil.logAuditMessage(cluster.getId(), + null, + null, + AuditLogType.GLUSTER_VOLUME_SNAPSHOT_CLUSTER_CONFIG_DETECTED_NEW, + new HashMap<String, String>() { + { + put("snapConfigName", paramName); + put("snapConfigValue", paramValue); + } + }); } else if (!(existingParamDetail.getParamValue().equals(paramValue))) { - getGlusterVolumeSnapshotConfigDao().updateConfigByClusterIdAndName(clusterId, + getGlusterVolumeSnapshotConfigDao().updateConfigByClusterIdAndName(cluster.getId(), paramName, paramValue); } } - private void addOrUpdateVolumeConfig(Guid clusterId, Guid volumeId, String paramName, String paramValue) { + private void addOrUpdateVolumeConfig(VDSGroup cluster, + final GlusterVolumeEntity volume, + final String paramName, + final String paramValue) { GlusterVolumeSnapshotConfig cfg = new GlusterVolumeSnapshotConfig(); - cfg.setClusterId(clusterId); - cfg.setVolumeId(volumeId); + cfg.setClusterId(cluster.getId()); + cfg.setVolumeId(volume.getId()); cfg.setParamName(paramName); cfg.setParamValue(paramValue); GlusterVolumeSnapshotConfig existingParamDetail = - getGlusterVolumeSnapshotConfigDao().getConfigByVolumeIdAndName(clusterId, - volumeId, + getGlusterVolumeSnapshotConfigDao().getConfigByVolumeIdAndName(cluster.getId(), + volume.getId(), paramName); if (existingParamDetail == null) { getGlusterVolumeSnapshotConfigDao().save(cfg); + log.debug("Detected new gluster volume snapshot configuration '{}' with value '{}' for volume: '{}' on cluster '{}'", + paramName, + paramValue, + cluster.getName(), + volume.getName()); + logUtil.logAuditMessage(cluster.getId(), + volume, + null, + AuditLogType.GLUSTER_VOLUME_SNAPSHOT_VOLUME_CONFIG_DETECTED_NEW, + new HashMap<String, String>() { + { + put("snapConfigName", paramName); + put("snapConfigValue", paramValue); + put(GlusterConstants.VOLUME_NAME, volume.getName()); + } + }); } else if (!(existingParamDetail.getParamValue().equals(paramValue))) { - getGlusterVolumeSnapshotConfigDao().updateConfigByVolumeIdAndName(clusterId, - volumeId, + getGlusterVolumeSnapshotConfigDao().updateConfigByVolumeIdAndName(cluster.getId(), + volume.getId(), paramName, paramValue); } diff --git a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJobTest.java b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJobTest.java index fb26e54..ea46ebe 100644 --- a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJobTest.java +++ b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJobTest.java @@ -115,6 +115,7 @@ doReturn(glusterUtil).when(syncJob).getGlusterUtil(); doReturn(getClusters()).when(clusterDao).getAll(); + doReturn(getValidCluster()).when(clusterDao).get(any(Guid.class)); doReturn(getVolumes()).when(volumeDao).getByClusterId(argThat(validClusterId())); doReturn(getVolume(CLUSTER_ID_1, VOLUME_ID_1, VOLUME_NAME_1)).when(volumeDao) .getByName(argThat(validClusterId()), argThat(validVolumeName())); @@ -132,6 +133,7 @@ doReturn(getSnapshotVDSReturnVal(true)).when(syncJob) .runVdsCommand(eq(VDSCommandType.GetGlusterVolumeSnapshotInfo), argThat(snapshotInfoParam())); + when(volumeDao.getById(any(Guid.class))).thenReturn(getVolume(CLUSTER_ID_1, VOLUME_ID_1, VOLUME_NAME_1)); syncJob.refreshSnapshotList(); Mockito.verify(snapshotDao, times(1)).saveAll(any(List.class)); Mockito.verify(snapshotDao, times(1)).removeAll(any(List.class)); @@ -329,6 +331,17 @@ return snapshots; } + private VDSGroup getValidCluster() { + VDSGroup cluster = new VDSGroup(); + cluster.setId(CLUSTER_ID_1); + cluster.setName("cluster"); + cluster.setGlusterService(true); + cluster.setVirtService(false); + cluster.setcompatibility_version(Version.v3_5); + + return cluster; + } + private List<VDSGroup> getClusters() { List<VDSGroup> list = new ArrayList<>(); diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java index c0542bc..42889fa 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java @@ -442,6 +442,11 @@ GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED(4148, AuditLogSeverity.ALERT), HOST_FEATURES_INCOMPATIBILE_WITH_CLUSTER(4149, AuditLogSeverity.ERROR), GLUSTER_VOLUME_SNAPSHOT_SCHEDULE_DELETED(4150), + GLUSTER_BRICK_STATUS_DOWN(4151, AuditLogSeverity.ALERT), + GLUSTER_VOLUME_SNAPSHOT_DETECTED_NEW(4152), + GLUSTER_VOLUME_SNAPSHOT_DELETED_FROM_CLI(4153), + GLUSTER_VOLUME_SNAPSHOT_CLUSTER_CONFIG_DETECTED_NEW(4154), + GLUSTER_VOLUME_SNAPSHOT_VOLUME_CONFIG_DETECTED_NEW(4155), USER_FORCE_SELECTED_SPM(159), USER_VDS_RESTART(41), diff --git a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties index 63408e5..163256f 100644 --- a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties +++ b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties @@ -863,6 +863,10 @@ CREATE_GLUSTER_BRICK=Brick ${brickName} created successfully. CREATE_GLUSTER_BRICK_FAILED=Failed to create brick ${brickName}. GLUSTER_VOLUME_SNAPSHOT_SCHEDULE_DELETED=Snapshot schedule deleted for volume ${glusterVolumeName} of ${vdsGroupName}. +GLUSTER_VOLUME_SNAPSHOT_DETECTED_NEW=Found new gluster volume snapshot ${snapname} for volume ${glusterVolumeName} on cluster ${VdsGroupName}, and added it to engine DB." +GLUSTER_VOLUME_SNAPSHOT_DELETED_FROM_CLI=Detected deletion of gluster volume snapshot ${snapname} for volume ${glusterVolumeName} on cluster ${VdsGroupName}, and deleting it from engine DB." +GLUSTER_VOLUME_SNAPSHOT_CLUSTER_CONFIG_DETECTED_NEW=Found new gluster volume snapshot configuration ${snapConfigName} with value ${snapConfigValue} on cluster ${VdsGroupName}, and added it to engine DB." +GLUSTER_VOLUME_SNAPSHOT_VOLUME_CONFIG_DETECTED_NEW=Found new gluster volume snapshot configuration ${snapConfigName} with value ${snapConfigValue} for volume ${glusterVolumeName} on cluster ${VdsGroupName}, and added it to engine DB." VDS_UNTRUSTED=Host ${VdsName} was set to non-operational. Host is not trusted by the attestation service. USER_ADDED_NETWORK_QOS=Network QoS ${QosName} was added. (User: ${UserName}) -- To view, visit https://gerrit.ovirt.org/42270 To unsubscribe, visit https://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I81636a86f48e977f47a4e5cbbd042446e3483ddf Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: ovirt-engine-3.5-gluster Gerrit-Owner: Shubhendu Tripathi <shtri...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches