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.

Bug-URL: https://bugzilla.redhat.com/1215613
Change-Id: I96ad64aa30a674bdc2c72e617fc71e13854fab85
Signed-off-by: Shubhendu Tripathi <[email protected]>
---
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
A 
packaging/dbscripts/upgrade/03_05_1460_index_audit_log_by_gluster_volume_id.sql
19 files changed, 261 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/52/40952/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 70eaed3..7f9f513 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
@@ -59,7 +59,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) {
@@ -110,6 +110,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);
+
                         }
                     }
                 }
@@ -155,6 +159,8 @@
             createdSnapshot.setStatus(GlusterSnapshotStatus.DEACTIVATED);
             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());
         }
 
         // 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 9678284..63fd611 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 05ad23f..2e86cef 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 a31319a..a9dfe98 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;
@@ -318,4 +324,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 223d3b3..3489c53c 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 35e4ac8..0f132e0 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
@@ -439,6 +439,7 @@
     GLUSTER_SETUP_GEOREP_MOUNT_BROKER(4145),
     GLUSTER_GEOREP_SESSION_CREATE_FAILED(4146, AuditLogSeverity.ERROR),
     CREATE_GLUSTER_VOLUME_GEOREP_SESSION(4147),
+    GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED(4148, 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 c03ea39..ba5c3cf 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
@@ -47,6 +47,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 b7934f0..f3b80d1 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));
@@ -182,6 +191,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..9bc0c29 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
@@ -4,11 +4,13 @@
 import java.net.UnknownHostException;
 import java.util.List;
 
+import org.apache.commons.lang.StringUtils;
 import org.ovirt.engine.core.common.businessentities.VdsStatic;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterBrickEntity;
 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 +39,10 @@
 
     private GlusterServerDao getGlusterServerDao() {
         return getDbFacade().getGlusterServerDao();
+    }
+
+    private GlusterVolumeSnapshotConfigDao getGlusterVolumeSnapshotConfigDao() 
{
+        return getDbFacade().getGlusterVolumeSnapshotConfigDao();
     }
 
     public boolean hasBricks(Guid serverId) {
@@ -178,4 +184,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 = 
StringUtils.removeEnd(config.getParamValue(), "%");
+                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 da100c7..703da244 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -845,6 +845,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 42ec895..e608d23 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
@@ -29,10 +29,11 @@
     private static final Guid VDS_ID = new 
Guid("afce7a39-8e8c-4819-ba9c-796d316592e6");
     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 */
@@ -252,7 +253,7 @@
             throws Exception {
         dao.removeAllForVds(VDS_ID, true);
         List<AuditLog> result = dao.getAll(null, false);
-        assertEquals(5, result.size());
+        assertEquals(6, result.size());
     }
 
     @Test
@@ -262,7 +263,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());
     }
 
     /**
@@ -325,4 +326,32 @@
 
         assertTrue(result.isDeleted());
     }
+
+    @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(AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED, 
entries1.get(0).getlog_type());
+    }
+
+    @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 cc56298..f55a400 100644
--- a/backend/manager/modules/dal/src/test/resources/fixtures.xml
+++ b/backend/manager/modules/dal/src/test/resources/fixtures.xml
@@ -5795,6 +5795,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>4148</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..2d78a6a 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,12 @@
     public void clearAllDismissed() {
     }
 
+    @Override
+    public List<AuditLog> getByVolumeIdAndType(Guid volumeId, int type) {
+        return null;
+    }
+
+    @Override
+    public void removeAllOfTypeForVolume(Guid volumeId, int type) {
+    }
 }
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 1d5cf02..1c45713 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
@@ -255,6 +255,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 ff139e5..27f7a50 100644
--- a/packaging/dbscripts/audit_log_sp.sql
+++ b/packaging/dbscripts/audit_log_sp.sql
@@ -234,6 +234,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
@@ -294,3 +304,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;
diff --git 
a/packaging/dbscripts/upgrade/03_05_1460_index_audit_log_by_gluster_volume_id.sql
 
b/packaging/dbscripts/upgrade/03_05_1460_index_audit_log_by_gluster_volume_id.sql
new file mode 100644
index 0000000..39d7bf0
--- /dev/null
+++ 
b/packaging/dbscripts/upgrade/03_05_1460_index_audit_log_by_gluster_volume_id.sql
@@ -0,0 +1,2 @@
+-- Create partial index for fetching audit_log by gluster_volume_id ID, when 
it's not null
+CREATE INDEX idx_audit_log_gluster_volume_id ON audit_log(gluster_volume_id) 
WHERE gluster_volume_id IS NOT NULL;


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I96ad64aa30a674bdc2c72e617fc71e13854fab85
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5-gluster
Gerrit-Owner: Shubhendu Tripathi <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to