Shubhendu Tripathi has uploaded a new change for review.

Change subject: gluster: Alert if volume snapshot max limit reached
......................................................................

gluster: Alert if volume snapshot max limit reached

Modified to alert if maximum limit for gluster volume
snapshot reached for a volume.

Change-Id: I98920caac7e194f8887c0226399ff59fe2942cd9
Bug-Url: https://bugzilla.redhat.com/1224269
Signed-off-by: Shubhendu Tripathi <shtri...@redhat.com>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeSnapshotCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteAllGlusterVolumeSnapshotsCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteGlusterVolumeSnapshotCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotSyncJob.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.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/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
M 
backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
9 files changed, 63 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/72/42272/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeSnapshotCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeSnapshotCommand.java
index 6e74a24..24f8e81 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeSnapshotCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/CreateGlusterVolumeSnapshotCommand.java
@@ -115,7 +115,7 @@
                             
getDbFacade().getGlusterVolumeSnapshotDao().save(slaveVolumeSnapshot);
 
                             // check if the snapshot soft limit reached now 
for the volume and alert
-                            
getGlusterUtil().alertVolumeSnapshotSoftLimitReached(slaveVolume);
+                            
getGlusterUtil().alertVolumeSnapshotLimitsReached(slaveVolume);
 
                         }
                     }
@@ -163,7 +163,7 @@
             getDbFacade().getGlusterVolumeSnapshotDao().save(createdSnapshot);
             addCustomValue(GlusterConstants.VOLUME_SNAPSHOT_NAME, 
createdSnapshot.getSnapshotName());
             // check if the snapshot soft limit reached now for the volume and 
alert
-            
getGlusterUtil().alertVolumeSnapshotSoftLimitReached(getGlusterVolume());
+            
getGlusterUtil().alertVolumeSnapshotLimitsReached(getGlusterVolume());
         }
 
         // Resume the snapshot sessions
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteAllGlusterVolumeSnapshotsCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteAllGlusterVolumeSnapshotsCommand.java
index f45e811..afde58b 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteAllGlusterVolumeSnapshotsCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteAllGlusterVolumeSnapshotsCommand.java
@@ -88,14 +88,14 @@
                         return;
                     }
                     // Check and remove soft limit alert for the volume
-                    
getGlusterUtil().checkAndRemoveVolumeSnapshotSoftLimitAlert(slaveVolume);
+                    
getGlusterUtil().checkAndRemoveVolumeSnapshotLimitsAlert(slaveVolume);
                 }
             }
         }
 
         deleteAllGlusterVolumeSnapshots(getUpServer().getId(), 
getGlusterVolumeName(), snapshots);
         // Check and remove soft limit alert for the volume
-        
getGlusterUtil().checkAndRemoveVolumeSnapshotSoftLimitAlert(getGlusterVolume());
+        
getGlusterUtil().checkAndRemoveVolumeSnapshotLimitsAlert(getGlusterVolume());
     }
 
     @Override
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteGlusterVolumeSnapshotCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteGlusterVolumeSnapshotCommand.java
index 0a58ad1..4cc592c 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteGlusterVolumeSnapshotCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/DeleteGlusterVolumeSnapshotCommand.java
@@ -77,14 +77,14 @@
                         return;
                     }
                     // Check and remove soft limit alert for the volume
-                    
getGlusterUtil().checkAndRemoveVolumeSnapshotSoftLimitAlert(slaveVolume);
+                    
getGlusterUtil().checkAndRemoveVolumeSnapshotLimitsAlert(slaveVolume);
                 }
             }
         }
 
         deleteGlusterVolumeSnapshot(getUpServer().getId(), 
getGlusterVolumeName(), getSnapshot().getSnapshotName());
         // Check and remove soft limit alert for the volume
-        
getGlusterUtil().checkAndRemoveVolumeSnapshotSoftLimitAlert(getGlusterVolume());
+        
getGlusterUtil().checkAndRemoveVolumeSnapshotLimitsAlert(getGlusterVolume());
     }
 
     @Override
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 4427f75..e094b5c 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
@@ -86,11 +86,11 @@
             List<GlusterVolumeEntity> volumes = 
getGlusterVolumeDao().getByClusterId(cluster.getId());
             for (final GlusterVolumeEntity volume : volumes) {
                 // check if the snapshot soft limit reached for the volume and 
alert
-                getGlusterUtil().alertVolumeSnapshotSoftLimitReached(volume);
+                getGlusterUtil().alertVolumeSnapshotLimitsReached(volume);
 
                 // Check and remove soft limit alert for the volume.
                 // It might have fallen below the soft limit as part of 
deletions of snapshots
-                
getGlusterUtil().checkAndRemoveVolumeSnapshotSoftLimitAlert(volume);
+                
getGlusterUtil().checkAndRemoveVolumeSnapshotLimitsAlert(volume);
             }
         } else {
             log.error("VDS Error {}", returnValue.getVdsError().getMessage());
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java
index f6a166a..e4561e7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.java
@@ -343,40 +343,58 @@
         return new Time(calTo.get(Calendar.HOUR_OF_DAY), 
calTo.get(Calendar.MINUTE), calTo.get(Calendar.SECOND));
     }
 
-    public void alertVolumeSnapshotSoftLimitReached(final GlusterVolumeEntity 
volume) {
-        // Check if the alert already exists and if so dont alert again
-        List<AuditLog> alerts =
+    private boolean alertVolumeLimitReached(final GlusterVolumeEntity volume, 
boolean checkHardLimit) {
+        AuditLogType logType =
+                checkHardLimit ? 
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_HARD_LIMIT_REACHED
+                        : 
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED;
+
+        List<AuditLog> limitAlerts =
                 DbFacade.getInstance()
                         .getAuditLogDao()
-                        .getByVolumeIdAndType(volume.getId(),
-                                
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED.getValue());
-        if (!alerts.isEmpty()) {
-            for (AuditLog alert : alerts) {
+                        .getByVolumeIdAndType(volume.getId(), 
logType.getValue());
+        if (!limitAlerts.isEmpty()) {
+            for (AuditLog alert : limitAlerts) {
                 if (!alert.isDeleted()) {
-                    return;
+                    return true;
                 }
             }
         }
 
         // Alert
-        if (GlusterDBUtils.getInstance().isSoftLimitReached(volume.getId())) {
+        boolean limitReached =
+                checkHardLimit ? 
GlusterDBUtils.getInstance().isVolumeSnapshotHardLimitReached(volume.getId())
+                        : 
GlusterDBUtils.getInstance().isVolumeSnapshotSoftLimitReached(volume.getId());
+        if (limitReached) {
             
GlusterAuditLogUtil.getInstance().logAuditMessage(volume.getClusterId(),
                     volume,
                     null,
-                    AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED,
+                    logType,
                     new HashMap<String, String>() {
                         {
                             put(GlusterConstants.VOLUME_NAME, 
volume.getName());
                             put(GlusterConstants.CLUSTER, 
volume.getVdsGroupName());
                         }
                     });
+            return true;
+        }
+
+        return false;
+    }
+
+    public void alertVolumeSnapshotLimitsReached(final GlusterVolumeEntity 
volume) {
+        if (!alertVolumeLimitReached(volume, true)) {
+            alertVolumeLimitReached(volume, false);
         }
     }
 
-    public void checkAndRemoveVolumeSnapshotSoftLimitAlert(final 
GlusterVolumeEntity volume) {
-        if (!GlusterDBUtils.getInstance().isSoftLimitReached(volume.getId())) {
+    public void checkAndRemoveVolumeSnapshotLimitsAlert(final 
GlusterVolumeEntity volume) {
+        if 
(!GlusterDBUtils.getInstance().isVolumeSnapshotSoftLimitReached(volume.getId()))
 {
             AlertDirector.removeVolumeAlert(volume.getId(), 
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED);
         }
+
+        if 
(!GlusterDBUtils.getInstance().isVolumeSnapshotHardLimitReached(volume.getId()))
 {
+            AlertDirector.removeVolumeAlert(volume.getId(), 
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_HARD_LIMIT_REACHED);
+        }
     }
 
     /**
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 ea46ebe..b6caf31 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
@@ -123,8 +123,8 @@
         when(glusterUtil.isGlusterSnapshotSupported(eq(Version.v3_4), 
any(Guid.class))).thenReturn(false);
         when(glusterUtil.isGlusterSnapshotSupported(eq(Version.v3_5), 
any(Guid.class))).thenReturn(true);
         
doReturn(engineLock).when(syncJob).acquireVolumeSnapshotLock(any(Guid.class));
-        
doNothing().when(glusterUtil).alertVolumeSnapshotSoftLimitReached(any(GlusterVolumeEntity.class));
-        
doNothing().when(glusterUtil).checkAndRemoveVolumeSnapshotSoftLimitAlert(any(GlusterVolumeEntity.class));
+        
doNothing().when(glusterUtil).alertVolumeSnapshotLimitsReached(any(GlusterVolumeEntity.class));
+        
doNothing().when(glusterUtil).checkAndRemoveVolumeSnapshotLimitsAlert(any(GlusterVolumeEntity.class));
     }
 
     @Test
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 42889fa..e7e5558 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
@@ -447,6 +447,7 @@
     GLUSTER_VOLUME_SNAPSHOT_DELETED_FROM_CLI(4153),
     GLUSTER_VOLUME_SNAPSHOT_CLUSTER_CONFIG_DETECTED_NEW(4154),
     GLUSTER_VOLUME_SNAPSHOT_VOLUME_CONFIG_DETECTED_NEW(4155),
+    GLUSTER_VOLUME_SNAPSHOT_HARD_LIMIT_REACHED(4156, AuditLogSeverity.ALERT),
 
     USER_FORCE_SELECTED_SPM(159),
     USER_VDS_RESTART(41),
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
index 9bc0c29..da1ada3 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/gluster/GlusterDBUtils.java
@@ -184,7 +184,7 @@
         return getGlusterVolumeDao().getByName(vdsGroupId, volumeName);
     }
 
-    public boolean isSoftLimitReached(Guid volumeId) {
+    public boolean isVolumeSnapshotSoftLimitReached(Guid volumeId) {
         GlusterVolumeEntity volume = getGlusterVolumeDao().getById(volumeId);
 
         if (volume != null) {
@@ -206,4 +206,24 @@
 
         return false;
     }
+
+    public boolean isVolumeSnapshotHardLimitReached(Guid volumeId) {
+        GlusterVolumeEntity volume = getGlusterVolumeDao().getById(volumeId);
+
+        if (volume != null) {
+            GlusterVolumeSnapshotConfig config =
+                    
getGlusterVolumeSnapshotConfigDao().getConfigByVolumeIdAndName(volume.getClusterId(),
+                            volumeId,
+                            "snap-max-hard-limit");
+
+            if (config != null) {
+                int snapMaxHardLimit = 
Integer.parseInt(config.getParamValue());
+                int snapshotCount = volume.getSnapshotsCount();
+
+                return snapshotCount >= snapMaxHardLimit;
+            }
+        }
+
+        return false;
+    }
 }
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 4863a45..a316af4 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -848,6 +848,7 @@
 GLUSTER_VOLUME_SNAPSHOT_CONFIG_UPDATE_FAILED=Failed to update gluster volume 
snapshot configuration(s).
 GLUSTER_VOLUME_SNAPSHOT_CONFIG_UPDATE_FAILED_PARTIALLY=Failed to update 
gluster volume snapshot configuration(s) ${failedSnapshotConfigs}.
 GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED=Gluster Volume Snapshot soft limit 
reached for the volume ${glusterVolumeName} on cluster ${vdsGroupName}.
+GLUSTER_VOLUME_SNAPSHOT_HARD_LIMIT_REACHED=Gluster Volume Snapshot hard limit 
reached for the volume ${glusterVolumeName} on cluster ${vdsGroupName}.
 NEW_STORAGE_DEVICE_DETECTED=Found new storage device ${storageDevice} on host 
${VdsName}, and added it to engine DB."
 STORAGE_DEVICE_REMOVED_FROM_THE_HOST=Detected deletion of storage device 
${storageDevice} on host ${VdsName}, and deleting it from engine DB."
 SYNC_STORAGE_DEVICES_IN_HOST=Manually synced the storage devices from host 
${VdsName}


-- 
To view, visit https://gerrit.ovirt.org/42272
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I98920caac7e194f8887c0226399ff59fe2942cd9
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

Reply via email to