Shubhendu Tripathi has uploaded a new change for review.

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

gluster: Alert if volume snapshot max soft limit reached

Introduced alerting mechanism when gluster volume snapshot
max soft limit reached.

Change-Id: I96ad64aa30a674bdc2c72e617fc71e13854fab85
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/GlusterSnapshotCommandBase.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/dal/dbbroker/auditloghandling/AlertDirector.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAO.java
M 
backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAODbFacadeImpl.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
M 
backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AuditLogDAOTest.java
M backend/manager/modules/dal/src/test/resources/fixtures.xml
M 
backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/AuditLogDaoMocker.java
M 
frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties
M packaging/dbscripts/audit_log_sp.sql
18 files changed, 266 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/31/39231/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 a76f2ff..26600bf 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
@@ -58,7 +58,7 @@
         if (georepSessions != null && georepSessions.size() > 0) {
             for (GlusterGeoRepSession session : georepSessions) {
                 if (session.getStatus() != GeoRepSessionStatus.PAUSED) {
-                    GlusterVolumeEntity slaveVolume =
+                    final GlusterVolumeEntity slaveVolume =
                             
getDbFacade().getGlusterVolumeDao().getById(session.getSlaveVolumeId());
 
                     if (slaveVolume == null) {
@@ -87,6 +87,9 @@
                         setSucceeded(false);
                         return false;
                     } else {
+                        // check if the snapshot soft limit reached for the 
volume and alert
+                        
getGlusterUtil().alertVolumeSnapshotSoftLimitReached(slaveVolume);
+
                         // Create snapshot for slave volume
                         VDSReturnValue snapCreationRetVal =
                                 
runVdsCommand(VDSCommandType.CreateGlusterVolumeSnapshot,
@@ -109,6 +112,10 @@
                             
slaveVolumeSnapshot.setDescription(snapshot.getDescription());
                             
slaveVolumeSnapshot.setStatus(GlusterSnapshotStatus.DEACTIVATED);
                             
getDbFacade().getGlusterVolumeSnapshotDao().save(slaveVolumeSnapshot);
+
+                            // check if the snapshot soft limit reached now 
for the volume and alert
+                            
getGlusterUtil().alertVolumeSnapshotSoftLimitReached(slaveVolume);
+
                         }
                     }
                 }
@@ -133,6 +140,9 @@
             return;
         }
 
+        // check if the snapshot soft limit reached for the volume and alert
+        
getGlusterUtil().alertVolumeSnapshotSoftLimitReached(getGlusterVolume());
+
         // Create snapshot for the master volume
         VDSReturnValue retVal =
                 runVdsCommand(VDSCommandType.CreateGlusterVolumeSnapshot,
@@ -153,6 +163,9 @@
             createdSnapshot.setDescription(snapshot.getDescription());
             createdSnapshot.setStatus(GlusterSnapshotStatus.DEACTIVATED);
             getDbFacade().getGlusterVolumeSnapshotDao().save(createdSnapshot);
+
+            // check if the snapshot soft limit reached now for the volume and 
alert
+            
getGlusterUtil().alertVolumeSnapshotSoftLimitReached(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 9c8180b..6ffebb8 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
@@ -86,11 +86,15 @@
                             slaveVolumeSnapshots)) {
                         return;
                     }
+                    // Check and remove soft limit alert for the volume
+                    
getGlusterUtil().checkAndRemoveVolumeSnapshotSoftLimitAlert(slaveVolume);
                 }
             }
         }
 
         deleteAllGlusterVolumeSnapshots(getUpServer().getId(), 
getGlusterVolumeName(), snapshots);
+        // Check and remove soft limit alert for the volume
+        
getGlusterUtil().checkAndRemoveVolumeSnapshotSoftLimitAlert(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 6472186..242fd04 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
@@ -75,11 +75,15 @@
                             getSnapshot().getSnapshotName())) {
                         return;
                     }
+                    // Check and remove soft limit alert for the volume
+                    
getGlusterUtil().checkAndRemoveVolumeSnapshotSoftLimitAlert(slaveVolume);
                 }
             }
         }
 
         deleteGlusterVolumeSnapshot(getUpServer().getId(), 
getGlusterVolumeName(), getSnapshot().getSnapshotName());
+        // Check and remove soft limit alert for the volume
+        
getGlusterUtil().checkAndRemoveVolumeSnapshotSoftLimitAlert(getGlusterVolume());
     }
 
     @Override
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotCommandBase.java
index ee02222..4afae74 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotCommandBase.java
@@ -4,6 +4,7 @@
 import java.util.Map;
 
 import org.ovirt.engine.core.bll.LockMessagesMatchUtil;
+import org.ovirt.engine.core.bll.utils.GlusterUtil;
 import org.ovirt.engine.core.common.action.LockProperties;
 import org.ovirt.engine.core.common.action.LockProperties.Scope;
 import org.ovirt.engine.core.common.action.gluster.GlusterVolumeParameters;
@@ -68,4 +69,8 @@
         LockManagerFactory.getLockManager().acquireLockWait(lock);
         return lock;
     }
+
+    protected GlusterUtil getGlusterUtil() {
+        return GlusterUtil.getInstance();
+    }
 }
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 c0a6b86..bc5567f 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
@@ -19,6 +19,8 @@
 import 
org.ovirt.engine.core.common.vdscommands.gluster.GlusterVolumeSnapshotVDSParameters;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import 
org.ovirt.engine.core.dal.dbbroker.auditloghandling.gluster.GlusterAuditLogUtil;
+import org.ovirt.engine.core.dao.gluster.GlusterDBUtils;
 import org.ovirt.engine.core.dao.gluster.GlusterVolumeDao;
 import org.ovirt.engine.core.dao.gluster.GlusterVolumeSnapshotConfigDao;
 import org.ovirt.engine.core.dao.gluster.GlusterVolumeSnapshotDao;
@@ -78,6 +80,17 @@
                 new GlusterVolumeSnapshotVDSParameters(upServer.getId(), 
cluster.getId(), null));
         if (returnValue.getSucceeded()) {
             addOrUpdateSnapshots(cluster.getId(), 
(ArrayList<GlusterVolumeSnapshotEntity>) returnValue.getReturnValue());
+
+            // check if the snapshot soft limit reached for a volume and alert
+            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);
+
+                // 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);
+            }
         } else {
             log.error("VDS Error {}", returnValue.getVdsError().getMessage());
             log.debug("VDS Error {}", returnValue.getVdsError());
@@ -266,4 +279,12 @@
     protected GlusterVolumeSnapshotConfigDao 
getGlusterVolumeSnapshotConfigDao() {
         return DbFacade.getInstance().getGlusterVolumeSnapshotConfigDao();
     }
+
+    protected GlusterDBUtils getGlusterDbUtils() {
+        return GlusterDBUtils.getInstance();
+    }
+
+    protected GlusterAuditLogUtil getAuditLogUtil() {
+        return GlusterAuditLogUtil.getInstance();
+    }
 }
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 4496472..5231a30 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
@@ -21,6 +21,8 @@
 import org.ovirt.engine.core.bll.Backend;
 import org.ovirt.engine.core.bll.LockMessagesMatchUtil;
 import org.ovirt.engine.core.bll.interfaces.BackendInternal;
+import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.businessentities.AuditLog;
 import org.ovirt.engine.core.common.businessentities.VDS;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterServer;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterServerInfo;
@@ -29,6 +31,7 @@
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import org.ovirt.engine.core.common.config.Config;
 import org.ovirt.engine.core.common.config.ConfigValues;
+import org.ovirt.engine.core.common.constants.gluster.GlusterConstants;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.common.gluster.GlusterFeatureSupported;
 import org.ovirt.engine.core.common.locks.LockingGroup;
@@ -38,6 +41,9 @@
 import org.ovirt.engine.core.common.utils.Pair;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.dal.dbbroker.DbFacade;
+import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AlertDirector;
+import 
org.ovirt.engine.core.dal.dbbroker.auditloghandling.gluster.GlusterAuditLogUtil;
+import org.ovirt.engine.core.dao.gluster.GlusterDBUtils;
 import org.ovirt.engine.core.utils.XmlUtils;
 import org.ovirt.engine.core.utils.lock.EngineLock;
 import org.ovirt.engine.core.utils.lock.LockManagerFactory;
@@ -324,4 +330,40 @@
 
         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 =
+                DbFacade.getInstance()
+                        .getAuditLogDao()
+                        .getByVolumeIdAndType(volume.getId(),
+                                
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED.getValue());
+        if (!alerts.isEmpty()) {
+            for (AuditLog alert : alerts) {
+                if (!alert.isDeleted()) {
+                    return;
+                }
+            }
+        }
+
+        // Alert
+        if (GlusterDBUtils.getInstance().isSoftLimitReached(volume.getId())) {
+            
GlusterAuditLogUtil.getInstance().logAuditMessage(volume.getClusterId(),
+                    volume,
+                    null,
+                    AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED,
+                    new HashMap<String, String>() {
+                        {
+                            put(GlusterConstants.VOLUME_NAME, 
volume.getName());
+                            put(GlusterConstants.CLUSTER, 
volume.getVdsGroupName());
+                        }
+                    });
+        }
+    }
+
+    public void checkAndRemoveVolumeSnapshotSoftLimitAlert(final 
GlusterVolumeEntity volume) {
+        if (!GlusterDBUtils.getInstance().isSoftLimitReached(volume.getId())) {
+            AlertDirector.RemoveVolumeAlert(volume.getId(), 
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_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 a35bb28..0cc638d 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
@@ -3,6 +3,7 @@
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.argThat;
 import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.times;
 import static org.ovirt.engine.core.utils.MockConfigRule.mockConfig;
@@ -110,6 +111,7 @@
         doReturn(snapshotDao).when(syncJob).getGlusterVolumeSnapshotDao();
         
doReturn(snapshotConfigDao).when(syncJob).getGlusterVolumeSnapshotConfigDao();
         doReturn(clusterUtils).when(syncJob).getClusterUtils();
+        doReturn(glusterUtil).when(syncJob).getGlusterUtil();
 
         doReturn(getClusters()).when(clusterDao).getAll();
         
doReturn(getVolumes()).when(volumeDao).getByClusterId(argThat(validClusterId()));
@@ -118,6 +120,8 @@
         
doReturn(getServer()).when(clusterUtils).getRandomUpServer(any(Guid.class));
 
         
doReturn(engineLock).when(syncJob).acquireVolumeSnapshotLock(any(Guid.class));
+        
doNothing().when(glusterUtil).alertVolumeSnapshotSoftLimitReached(any(GlusterVolumeEntity.class));
+        
doNothing().when(glusterUtil).checkAndRemoveVolumeSnapshotSoftLimitAlert(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 2786aac..9942a9c 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
@@ -436,6 +436,7 @@
     GLUSTER_VOLUME_SNAPSHOT_RESCHEDULE_FAILED(4137, AuditLogSeverity.ERROR),
     CREATE_GLUSTER_BRICK(4138),
     CREATE_GLUSTER_BRICK_FAILED(4139),
+    GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED(4140, 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/dal/dbbroker/auditloghandling/AlertDirector.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AlertDirector.java
index c13ab11..edc634c 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AlertDirector.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dal/dbbroker/auditloghandling/AlertDirector.java
@@ -51,6 +51,17 @@
     }
 
     /**
+     * Removes the alert
+     * @param volumeId
+     *            The volume id
+     * @param type
+     *            The alert type
+     */
+    public static void RemoveVolumeAlert(Guid volumeId, AuditLogType type) {
+        
DbFacade.getInstance().getAuditLogDao().removeAllOfTypeForVolume(volumeId, 
type.getValue());
+    }
+
+    /**
      * Removes all alerts.
      *
      * @param vdsId
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAO.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAO.java
index b42c23d..4f88c5d 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAO.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAO.java
@@ -32,6 +32,16 @@
     AuditLog getByOriginAndCustomEventId(String origin, int customEventId);
 
     /**
+     * Get all entries got a volume with given type
+     * @param volumeId
+     *            The volume id
+     * @param type
+     *            The entry type
+     * @return
+     */
+    List<AuditLog> getByVolumeIdAndType(Guid volumeId, int type);
+
+    /**
      * Finds all entries created after the specified cutoff date
      *
      * @param cutoff
@@ -144,6 +154,15 @@
     void removeAllOfTypeForVds(Guid id, int type);
 
     /**
+     * Removes entries of the specified type for the given volume id.
+     * @param volumeId
+     *            The volume id
+     * @param type
+     *            The entry type
+     */
+    void removeAllOfTypeForVolume(Guid volumeId, int type);
+
+    /**
      * Get time to wait in seconds before another PM operation is allowed on 
the given Host
      * @param vdsName Host name
      * @param event [USER_VDS_STOP | USER_VDS_START | USER_VDS_RESTART]
diff --git 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAODbFacadeImpl.java
 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAODbFacadeImpl.java
index c610a23..a742d2b 100644
--- 
a/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAODbFacadeImpl.java
+++ 
b/backend/manager/modules/dal/src/main/java/org/ovirt/engine/core/dao/AuditLogDAODbFacadeImpl.java
@@ -95,6 +95,15 @@
     }
 
     @Override
+    public List<AuditLog> getByVolumeIdAndType(Guid volumeId, int type) {
+        MapSqlParameterSource parameterSource =
+                getCustomMapSqlParameterSource()
+                        .addValue("gluster_volume_id", volumeId)
+                        .addValue("log_type", type);
+        return 
getCallsHandler().executeReadList("GetAuditLogByVolumeIdAndType", 
auditLogRowMapper, parameterSource);
+    }
+
+    @Override
     public void save(AuditLog event) {
         if (event.isExternal()) {
             getCallsHandler().executeModification("InsertExternalAuditLog", 
getExternalEventSqlMapper(event));
@@ -183,6 +192,14 @@
     }
 
     @Override
+    public void removeAllOfTypeForVolume(Guid volumeId, int type) {
+        MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
+                .addValue("gluster_volume_id", volumeId).addValue("log_type", 
type);
+
+        
getCallsHandler().executeModification("DeleteAuditAlertLogByVolumeIDAndType", 
parameterSource);
+    }
+
+    @Override
     public int getTimeToWaitForNextPmOp(String vdsName, String event) {
         MapSqlParameterSource parameterSource = 
getCustomMapSqlParameterSource()
                 .addValue("vds_name", vdsName)
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 82fa4a9..4972183 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
@@ -9,6 +9,7 @@
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterServer;
 import org.ovirt.engine.core.common.businessentities.gluster.GlusterStatus;
 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.GlusterVolumeType;
 import 
org.ovirt.engine.core.common.businessentities.network.VdsNetworkInterface;
 import org.ovirt.engine.core.compat.Guid;
@@ -37,6 +38,10 @@
 
     private GlusterServerDao getGlusterServerDao() {
         return getDbFacade().getGlusterServerDao();
+    }
+
+    private GlusterVolumeSnapshotConfigDao getGlusterVolumeSnapshotConfigDao() 
{
+        return getDbFacade().getGlusterVolumeSnapshotConfigDao();
     }
 
     public boolean hasBricks(Guid serverId) {
@@ -178,4 +183,26 @@
         return getGlusterVolumeDao().getByName(vdsGroupId, volumeName);
     }
 
+    public boolean isSoftLimitReached(Guid volumeId) {
+        GlusterVolumeEntity volume = getGlusterVolumeDao().getById(volumeId);
+
+        if (volume != null) {
+            GlusterVolumeSnapshotConfig config =
+                    
getGlusterVolumeSnapshotConfigDao().getConfigByClusterIdAndName(volume.getClusterId(),
+                            "snap-max-soft-limit");
+
+            if (config != null) {
+                // remove the % sign in the last
+                String configValue = config.getParamValue().substring(0, 
config.getParamValue().length() - 1);
+                int snapMaxSoftLimitPcnt = Integer.parseInt(configValue);
+
+                int snapshotCount = volume.getSnapshotsCount();
+                int snapMaxLimit = volume.getSnapMaxLimit();
+
+                return snapshotCount >= (snapMaxLimit * snapMaxSoftLimitPcnt) 
/ 100;
+            }
+        }
+
+        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 c2916e0..383b5f1 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -849,6 +849,7 @@
 GLUSTER_VOLUME_SNAPSHOT_CONFIG_UPDATED=Updated Gluster volume snapshot 
configuration(s).
 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}.
 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}
diff --git 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AuditLogDAOTest.java
 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AuditLogDAOTest.java
index 3f49214..501fdd3 100644
--- 
a/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AuditLogDAOTest.java
+++ 
b/backend/manager/modules/dal/src/test/java/org/ovirt/engine/core/dao/AuditLogDAOTest.java
@@ -30,10 +30,11 @@
     private static final String VDS_NAME = "magenta-vdsc";
     private static final Guid VM_ID = new 
Guid("77296e00-0cad-4e5a-9299-008a7b6f4354");
     private static final Guid VM_TEMPLATE_ID = new 
Guid("1b85420c-b84c-4f29-997e-0eb674b40b79");
+    private static final Guid GLUSTER_VOLUME_ID = new 
Guid("0c3f45f6-3fe9-4b35-a30c-be0d1a835ea8");
     private static final long EXISTING_ENTRY_ID = 44291;
     private static final long EXTERNAL_ENTRY_ID = 44296;
-    private static final int FILTERED_COUNT = 5;
-    private static final int TOTAL_COUNT = 6;
+    private static final int FILTERED_COUNT = 6;
+    private static final int TOTAL_COUNT = 7;
     private AuditLogDAO dao;
 
     /** Note that {@link SimpleDateFormat} is inherently not thread-safe, and 
should not be static */
@@ -253,7 +254,7 @@
             throws Exception {
         dao.removeAllForVds(VDS_ID, true);
         List<AuditLog> result = dao.getAll(null, false);
-        assertEquals(5, result.size());
+        assertEquals(6, result.size());
     }
 
     @Test
@@ -263,7 +264,7 @@
                 AuditLogType.IRS_DISK_SPACE_LOW_ERROR.getValue());
         // show be 1 left that was in event_notification_hist
         List<AuditLog> result = dao.getAll(PRIVILEGED_USER_ID, true);
-        assertEquals(2, result.size());
+        assertEquals(3, result.size());
     }
 
     /**
@@ -394,4 +395,32 @@
         // test if 2nd alert was also stored in db
         assertEquals(2, getAlertCount(entry, dao.getAll(null, false)));
     }
+
+    @Test
+    public void testRemoveAllOfTypeForVolume() {
+        List<AuditLog> entries =
+                dao.getByVolumeIdAndType(GLUSTER_VOLUME_ID,
+                        
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED.getValue());
+
+        assertEquals(1, entries.size());
+
+        dao.removeAllOfTypeForVolume(GLUSTER_VOLUME_ID,
+                
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED.getValue());
+
+        List<AuditLog> entries1 =
+                dao.getByVolumeIdAndType(GLUSTER_VOLUME_ID,
+                        
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED.getValue());
+
+        assertEquals(1, entries1.size());
+        assertEquals(entries1.get(0).getLogType(), 
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED);
+    }
+
+    @Test
+    public void testGetByVolumeIdAndType() {
+        List<AuditLog> entries =
+                dao.getByVolumeIdAndType(GLUSTER_VOLUME_ID,
+                        
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED.getValue());
+
+        assertEquals(1, entries.size());
+    }
 }
diff --git a/backend/manager/modules/dal/src/test/resources/fixtures.xml 
b/backend/manager/modules/dal/src/test/resources/fixtures.xml
index 7fc618e..215871f 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -6174,6 +6174,40 @@
             <value></value>
             <value>false</value>
         </row>
+        <row>
+            <value>44297</value>
+            <value>9bf7c640-b620-456f-a550-0348f366544a</value>
+            <value>userportal2</value>
+            <value>77296e00-0cad-4e5a-9299-008a7b6f4354</value>
+            <value>rhel5-pool-50</value>
+            <value>1b85420c-b84c-4f29-997e-0eb674b40b79</value>
+            <value>1</value>
+            <value>afce7a39-8e8c-4819-ba9c-796d316592e6</value>
+            <value>magenta-vdsc</value>
+            <value>2010-12-20 13:10:29</value>
+            <value>GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED</value>
+            <value>4140</value>
+            <value>10</value>
+            <value>Gluster Volume Snapshot soft limit reached for the 
volume</value>
+            <value>true</value>
+            <value>6d849ebf-755f-4552-ad09-9a090cda105d</value>
+            <value>rhel6.iscsi</value>
+            <value>72e3a666-89e1-4005-a7ca-f7548004a9ab</value>
+            <value>fDMzhE-wx3s-zo3q-Qcxd-T0li-yoYU-QvVePk</value>
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <null />
+            <value>0c3f45f6-3fe9-4b35-a30c-be0d1a835ea8</value>
+            <value>test-vol-distribute-1</value>
+            <value>oVirt</value>
+            <value>-1</value>
+            <value>30</value>
+            <value></value>
+            <value>false</value>
+        </row>
     </table>
 
     <table name="event_notification_hist">
diff --git 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/AuditLogDaoMocker.java
 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/AuditLogDaoMocker.java
index 7f0d723..1322b7e 100644
--- 
a/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/AuditLogDaoMocker.java
+++ 
b/backend/manager/modules/vdsbroker/src/main/java/org/ovirt/engine/core/vdsbroker/AuditLogDaoMocker.java
@@ -108,4 +108,13 @@
     public void clearAllDismissed() {
     }
 
+    @Override
+    public List<AuditLog> getByVolumeIdAndType(Guid volumeId, int type) {
+        return null;
+    }
+
+    @Override
+    public void removeAllOfTypeForVolume(Guid volumeId, int type) {
+        // TODO Auto-generated method stub
+    }
 }
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties
 
b/frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties
index 179d56f..81fe730 100644
--- 
a/frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties
+++ 
b/frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties
@@ -256,6 +256,7 @@
 AuditLogType___GLUSTER_MASTER_VOLUME_SNAPSHOT_RESTORE_FAILED=Could not restore 
master volume ${glusterVolumeName}.
 AuditLogType___CREATE_GLUSTER_BRICK=Brick ${brickName} created successfully.
 AuditLogType___CREATE_GLUSTER_BRICK_FAILED=Failed to create brick ${brickName}.
+AuditLogType___GLUSTER_VOLUME_SNAPSHOT_CONFIG_UPDATE_FAILED_PARTIALLY=Failed 
to update gluster volume snapshot configuration(s) ${failedSnapshotConfigs}.
 
 VdcActionType___ActivateVds=Activate Host
 VdcActionType___RecoveryStoragePool=Reinitialize Data Center
diff --git a/packaging/dbscripts/audit_log_sp.sql 
b/packaging/dbscripts/audit_log_sp.sql
index 3cebdd3..c641417 100644
--- a/packaging/dbscripts/audit_log_sp.sql
+++ b/packaging/dbscripts/audit_log_sp.sql
@@ -235,6 +235,16 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+Create or replace FUNCTION 
DeleteAuditAlertLogByVolumeIDAndType(v_gluster_volume_id UUID,
+    v_log_type INTEGER)
+RETURNS VOID
+   AS $procedure$
+BEGIN
+      UPDATE audit_log set deleted = true
+      where gluster_volume_id = v_gluster_volume_id and log_type = v_log_type;
+END; $procedure$
+LANGUAGE plpgsql;
+
 Create or replace FUNCTION DeleteAuditLogAlertsByVdsID(v_vds_id UUID,
     v_delete_config_alerts BOOLEAN=true)
 RETURNS VOID
@@ -295,3 +305,12 @@
 END; $procedure$
 LANGUAGE plpgsql;
 
+Create or replace FUNCTION GetAuditLogByVolumeIdAndType(v_gluster_volume_id 
UUID, v_log_type INTEGER)
+RETURNS SETOF audit_log STABLE
+   AS $procedure$
+BEGIN
+      RETURN QUERY SELECT *
+      FROM audit_log
+      WHERE gluster_volume_id = v_gluster_volume_id and log_type = v_log_type;
+END; $procedure$
+LANGUAGE plpgsql;


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I96ad64aa30a674bdc2c72e617fc71e13854fab85
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
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