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 <shtri...@redhat.com>
---
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, 62 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/06/40806/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..45f1cfe 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.compareTo(new Date()) < 0) {
+            
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 7515916..1630efc 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;
@@ -54,8 +51,8 @@
 
         // Validate the scheduling dates (start and end by dates)
         Date currentDate = new Date();
-        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) {
@@ -85,8 +82,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)
@@ -113,20 +110,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 4496472..7b52e29 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;
@@ -324,4 +327,21 @@
 
         return new Time(calTo.get(Calendar.HOUR_OF_DAY), 
calTo.get(Calendar.MINUTE), calTo.get(Calendar.SECOND));
     }
+
+    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 69ba821..4967140 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
@@ -444,6 +444,7 @@
     GLUSTER_SETUP_GEOREP_MOUNT_BROKER(4145),
     GLUSTER_GEOREP_SESSION_CREATE_FAILED(4146, AuditLogSeverity.ERROR),
     CREATE_GLUSTER_VOLUME_GEOREP_SESSION(4147),
+    GLUSTER_VOLUME_SNAPSHOT_SCHEDULE_DELETED(4148),
 
     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 3dcb71a..80304cc 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -894,6 +894,7 @@
 GLUSTER_VOLUME_SNAPSHOT_CREATE_FAILED=Could not create ${snapname} for volume 
${glusterVolumeName}.
 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}.
 
 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 6d29a0f..bd6ef4b 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
@@ -529,6 +529,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 be97a75..be059bd 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
@@ -267,6 +267,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_SCHEDULE_DELETED=Snapshot schedule 
deleted for volume ${glusterVolumeName}
 
 VdcActionType___ActivateVds=Activate Host
 VdcActionType___RecoveryStoragePool=Reinitialize Data Center


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

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