Shubhendu Tripathi has uploaded a new change for review.

Change subject: gluster: Remove volume snapshot schedule if job ended
......................................................................

gluster: Remove volume snapshot schedule if job ended

Added logic to remove the gluster volume snapshot
schedule details if the schedule has ended.

Change-Id: Ibbdb11f0d881339749dac8101ca9a01b04a334c6
Bug-Url: https://bugzilla.redhat.com/1219827
Signed-off-by: Shubhendu Tripathi <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotScheduleJob.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/RescheduleGlusterVolumeSnapshotCommand.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/ScheduleGlusterVolumeSnapshotCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/utils/GlusterUtil.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
M 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java
M 
frontend/webadmin/modules/uicompat/src/main/resources/org/ovirt/engine/ui/uicompat/LocalizedEnums.properties
8 files changed, 74 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/43/41043/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotScheduleJob.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotScheduleJob.java
index 670a605..afce8d0 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotScheduleJob.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/GlusterSnapshotScheduleJob.java
@@ -1,21 +1,25 @@
 package org.ovirt.engine.core.bll.gluster;
 
 import java.io.Serializable;
+import java.util.Date;
 import java.util.HashMap;
 
 import org.ovirt.engine.core.bll.Backend;
 import org.ovirt.engine.core.bll.interfaces.BackendInternal;
+import org.ovirt.engine.core.bll.utils.GlusterUtil;
 import org.ovirt.engine.core.common.AuditLogType;
 import org.ovirt.engine.core.common.action.VdcActionType;
 import org.ovirt.engine.core.common.action.VdcReturnValueBase;
 import 
org.ovirt.engine.core.common.action.gluster.CreateGlusterVolumeSnapshotParameters;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeEntity;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotEntity;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule;
 import org.ovirt.engine.core.common.constants.gluster.GlusterConstants;
 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.GlusterVolumeDao;
+import org.ovirt.engine.core.dao.gluster.GlusterVolumeSnapshotScheduleDao;
 import org.ovirt.engine.core.utils.timer.OnTimerMethodAnnotation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -60,6 +64,27 @@
                         }
                     });
         }
+
+        // Check if next schedule available, and if not delete the scheduling 
details from DB
+        GlusterVolumeSnapshotSchedule schedule =
+                
getGlusterVolumeSnapshotScheduleDao().getByVolumeId(volume.getId());
+        Date endDate = 
GlusterUtil.getInstance().convertDate(schedule.getEndByDate(), 
schedule.getTimeZone());
+        if (endDate.before(new Date())) {
+            
getGlusterVolumeSnapshotScheduleDao().removeByVolumeId(volume.getId());
+            logUtil.logAuditMessage(volume.getClusterId(),
+                    volume,
+                    null,
+                    AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SCHEDULE_DELETED,
+                    new HashMap<String, String>() {
+                        {
+                            put(GlusterConstants.VOLUME_NAME, 
volume.getName());
+                        }
+                    });
+        }
+    }
+
+    protected GlusterVolumeSnapshotScheduleDao 
getGlusterVolumeSnapshotScheduleDao() {
+        return DbFacade.getInstance().getGlusterVolumeSnapshotScheduleDao();
     }
 
     protected GlusterVolumeDao getGlusterVolumeDao() {
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/RescheduleGlusterVolumeSnapshotCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/RescheduleGlusterVolumeSnapshotCommand.java
index 928a942..54f5d28 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/RescheduleGlusterVolumeSnapshotCommand.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/RescheduleGlusterVolumeSnapshotCommand.java
@@ -5,6 +5,7 @@
 import org.ovirt.engine.core.common.AuditLogType;
 import 
org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters;
 import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotSchedule;
+import 
org.ovirt.engine.core.common.businessentities.gluster.GlusterVolumeSnapshotScheduleRecurrence;
 import org.ovirt.engine.core.common.errors.VdcBllMessages;
 import org.ovirt.engine.core.compat.Guid;
 import org.ovirt.engine.core.utils.timer.DBSchedulerUtilQuartzImpl;
@@ -66,7 +67,11 @@
     @Override
     public AuditLogType getAuditLogTypeValue() {
         if (getSucceeded()) {
-            return AuditLogType.GLUSTER_VOLUME_SNAPSHOT_RESCHEDULED;
+            if 
(getSchedule().getRecurrence().equals(GlusterVolumeSnapshotScheduleRecurrence.UNKNOWN))
 {
+                return AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SCHEDULE_DELETED;
+            } else {
+                return AuditLogType.GLUSTER_VOLUME_SNAPSHOT_RESCHEDULED;
+            }
         } else {
             return errorType == null ? 
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_RESCHEDULE_FAILED : errorType;
         }
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/ScheduleGlusterVolumeSnapshotCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/ScheduleGlusterVolumeSnapshotCommandBase.java
index 56f3016..6aa96b7 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/ScheduleGlusterVolumeSnapshotCommandBase.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/gluster/ScheduleGlusterVolumeSnapshotCommandBase.java
@@ -1,10 +1,7 @@
 package org.ovirt.engine.core.bll.gluster;
 
 import java.sql.Time;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
 import java.util.Date;
-import java.util.TimeZone;
 
 import org.ovirt.engine.core.bll.utils.GlusterUtil;
 import 
org.ovirt.engine.core.common.action.gluster.ScheduleGlusterVolumeSnapshotParameters;
@@ -53,8 +50,8 @@
         }
 
         // Validate the scheduling dates (start and end by dates)
-        Date convertedStartDate = convertDate(schedule.getStartDate(), 
schedule.getTimeZone());
-        Date convertedEndByDate = convertDate(schedule.getEndByDate(), 
schedule.getTimeZone());
+        Date convertedStartDate = 
getGlusterUtil().convertDate(schedule.getStartDate(), schedule.getTimeZone());
+        Date convertedEndByDate = 
getGlusterUtil().convertDate(schedule.getEndByDate(), schedule.getTimeZone());
 
         if (schedule.getRecurrence() != null
                 && schedule.getRecurrence() != 
GlusterVolumeSnapshotScheduleRecurrence.UNKNOWN
@@ -76,8 +73,8 @@
         }
 
         // convert the start date and end by date to the given timezone
-        Date convertedStartDate = convertDate(schedule.getStartDate(), 
schedule.getTimeZone());
-        Date convertedEndByDate = convertDate(schedule.getEndByDate(), 
schedule.getTimeZone());
+        Date convertedStartDate = 
getGlusterUtil().convertDate(schedule.getStartDate(), schedule.getTimeZone());
+        Date convertedEndByDate = 
getGlusterUtil().convertDate(schedule.getEndByDate(), schedule.getTimeZone());
 
         String cronExpression = 
GlusterUtil.getInstance().getCronExpression(schedule);
         if (cronExpression == null)
@@ -104,20 +101,7 @@
         return force;
     }
 
-    private Date convertDate(Date inDate, String tZone) {
-        if (inDate == null) {
-            return null;
-        }
-
-        DateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
-        String formattedStartDate = format.format(inDate);
-
-        format.setTimeZone(TimeZone.getTimeZone(tZone));
-        try {
-            return format.parse(formattedStartDate);
-        } catch (Exception ex) {
-            log.error("Error while converting the date to engine time zone");
-            return null;
-        }
+    protected GlusterUtil getGlusterUtil() {
+        return GlusterUtil.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 a9dfe98..eac2241 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
@@ -5,8 +5,11 @@
 import java.net.InetAddress;
 import java.net.UnknownHostException;
 import java.sql.Time;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Date;
 import java.util.GregorianCalendar;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -313,6 +316,12 @@
         return retStr;
     }
 
+    /**
+     * Converts the input time to engine's time zone from the provided time 
zone
+     * @param inTime input time
+     * @param fromTimeZone time zone from which to convert to engine time zone
+     * @return converted time
+     */
     public Time convertTime(Time inTime, String fromTimeZone) {
         Calendar calFrom = new 
GregorianCalendar(TimeZone.getTimeZone(fromTimeZone));
         calFrom.set(Calendar.HOUR, inTime.getHours());
@@ -360,4 +369,27 @@
             AlertDirector.removeVolumeAlert(volume.getId(), 
AuditLogType.GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED);
         }
     }
+
+    /**
+     * Converts the given date from the given time zone to engine time zone
+     * @param inDate input date
+     * @param tZone from time zone
+     * @return converted date
+     */
+    public Date convertDate(Date inDate, String tZone) {
+        if (inDate == null) {
+            return null;
+        }
+
+        DateFormat format = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
+        String formattedStartDate = format.format(inDate);
+
+        format.setTimeZone(TimeZone.getTimeZone(tZone));
+        try {
+            return format.parse(formattedStartDate);
+        } catch (Exception ex) {
+            log.error("Error while converting the date to engine time zone");
+            return null;
+        }
+    }
 }
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 0f132e0..011df8c 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
@@ -440,6 +440,7 @@
     GLUSTER_GEOREP_SESSION_CREATE_FAILED(4146, AuditLogSeverity.ERROR),
     CREATE_GLUSTER_VOLUME_GEOREP_SESSION(4147),
     GLUSTER_VOLUME_SNAPSHOT_SOFT_LIMIT_REACHED(4148, AuditLogSeverity.ALERT),
+    GLUSTER_VOLUME_SNAPSHOT_SCHEDULE_DELETED(4150),
 
     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 703da244..624869c 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -860,6 +860,7 @@
 GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED=Could not create snapshot for volume 
${glusterVolumeName} on cluster ${vdsGroupName}.
 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}.
 
 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})
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java
index 4eb14b9..9ea771f 100644
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/LocalizedEnums.java
@@ -515,6 +515,8 @@
 
     String AuditLogType___CREATE_GLUSTER_BRICK_FAILED();
 
+    String AuditLogType___GLUSTER_VOLUME_SNAPSHOT_SCHEDULE_DELETED();
+
     String VdcActionType___ActivateVds();
 
     String VdcActionType___RecoveryStoragePool();
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 1c45713..2fec130 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___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}.
+AuditLogType___GLUSTER_VOLUME_SNAPSHOT_SCHEDULE_DELETED=Snapshot schedule 
deleted for volume ${glusterVolumeName} of ${vdsGroupName}
 
 VdcActionType___ActivateVds=Activate Host
 VdcActionType___RecoveryStoragePool=Reinitialize Data Center


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

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