Shubhendu Tripathi has uploaded a new change for review.

Change subject: engine: Quartz cron scheduler to support startAt and endBy
......................................................................

engine: Quartz cron scheduler to support startAt and endBy

Modified the Quartz scheduler to support start at and end by dates for
cron based scheduler

Change-Id: I5c3372098177dabbbe886660c9d7a586784b99be
Signed-off-by: Shubhendu Tripathi <shtri...@redhat.com>
---
M 
backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/DBSchedulerUtilQuartzImpl.java
M 
backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtil.java
M 
backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtilBaseImpl.java
3 files changed, 90 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/48/39348/1

diff --git 
a/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/DBSchedulerUtilQuartzImpl.java
 
b/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/DBSchedulerUtilQuartzImpl.java
index 72880d6..f950178 100644
--- 
a/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/DBSchedulerUtilQuartzImpl.java
+++ 
b/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/DBSchedulerUtilQuartzImpl.java
@@ -4,6 +4,7 @@
 import static org.quartz.impl.matchers.GroupMatcher.jobGroupEquals;
 
 import java.io.IOException;
+import java.util.Date;
 import java.util.Properties;
 import java.util.concurrent.TimeUnit;
 
@@ -173,6 +174,20 @@
     }
 
     @Override
+    public String scheduleACronJob(Object instance,
+            String methodName,
+            Class<?>[] inputTypes,
+            Object[] inputParams,
+            String cronExpression,
+            Date startAt,
+            Date endBy) {
+        if (!validate(instance, inputTypes)) {
+            return null;
+        }
+        return super.scheduleACronJob(instance, methodName, inputTypes, 
inputParams, cronExpression, startAt, endBy);
+    }
+
+    @Override
     protected JobDetail createJobWithBasicMapValues(Object instance,
             String methodName,
             Class<?>[] inputTypes,
diff --git 
a/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtil.java
 
b/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtil.java
index b56abf6..30d0ef7 100644
--- 
a/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtil.java
+++ 
b/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtil.java
@@ -1,5 +1,6 @@
 package org.ovirt.engine.core.utils.timer;
 
+import java.util.Date;
 import java.util.concurrent.TimeUnit;
 
 import javax.ejb.Local;
@@ -145,6 +146,34 @@
                             String cronExpression);
 
     /**
+     * Schedules a cron job with specific delay and end by value
+     *
+     * @param instance
+     *            - the instance to activate the method on timeout
+     * @param methodName
+     *            - the name of the method to activate on the instance
+     * @param inputTypes
+     *            - the method input types
+     * @param inputParams
+     *            - the method input parameters
+     * @param cronExpression
+     *            - cron expression to run this job
+     * @param startAt
+     *            - when to start the task
+     * @param endBy
+     *            - when to end the task
+     * @return the scheduled job id
+     */
+    String scheduleACronJob(Object instance,
+                            String methodName,
+                            Class<?>[] inputTypes,
+                            Object[] inputParams,
+                            String cronExpression,
+                            Date startAt,
+                            Date endBy);
+
+
+    /**
      * Schedules a job with a configurable delay.
      *
      * @param instance
diff --git 
a/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtilBaseImpl.java
 
b/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtilBaseImpl.java
index 7cb619a..1940fc8 100644
--- 
a/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtilBaseImpl.java
+++ 
b/backend/manager/modules/scheduler/src/main/java/org/ovirt/engine/core/utils/timer/SchedulerUtilBaseImpl.java
@@ -228,11 +228,57 @@
         } catch (Exception se) {
             log.error("failed to schedule job: {}", se.getMessage());
             log.debug("Exception", se);
+            return null;
         }
         return job.getKey().getName();
     }
 
     /**
+     * Schedules a cron job with specific delay and end by value
+     *
+     * @param instance
+     *            - the instance to activate the method on timeout
+     * @param methodName
+     *            - the name of the method to activate on the instance
+     * @param inputTypes
+     *            - the method input types
+     * @param inputParams
+     *            - the method input parameters
+     * @param cronExpression
+     *            - cron expression to run this job
+     * @param startAt
+     *            - when to start the task
+     * @param endBy
+     *            - when to end the task
+     * @return the scheduled job id
+     */
+    public String scheduleACronJob(Object instance,
+            String methodName,
+            Class<?>[] inputTypes,
+            Object[] inputParams,
+            String cronExpression,
+            Date startAt,
+            Date endBy) {
+        JobDetail job = createJobWithBasicMapValues(instance, methodName, 
inputTypes, inputParams);
+        try {
+            String triggerName = generateUniqueNameForInstance(instance, 
TRIGGER_PREFIX);
+            Trigger trigger = newTrigger()
+                    .withIdentity(triggerName, Scheduler.DEFAULT_GROUP)
+                    .withSchedule(cronSchedule(cronExpression))
+                    .startAt(startAt)
+                    .endAt(endBy)
+                    .build();
+            sched.scheduleJob(job, trigger);
+        } catch (Exception se) {
+            log.error("failed to schedule job: {}", se.getMessage());
+            log.debug("Exception", se);
+            return null;
+        }
+        return job.getKey().getName();
+    }
+
+
+    /**
      * reschedule the job associated with the given old trigger with the new 
trigger.
      *
      * @param oldTriggerName


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I5c3372098177dabbbe886660c9d7a586784b99be
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: ovirt-engine-3.5-gluster
Gerrit-Owner: Shubhendu Tripathi <shtri...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to