/**
* Sets the cron expression for the calendar to a new value
* @param expression the new string value to build a cron expression from
* @throws ParseException
* if the string expression cannot be parsed
public void setCronExpression(String expression) throws ParseException {
CronExpression newExp = new CronExpression(expression);
this.cronExpression = newExp;
public static void validateExpression(String cronExpression) throws ParseException {
new CronExpression(cronExpression);
public
static void validateExpression(String cronExpression) throws ParseException {
new CronExpression(cronExpression);
/**
* Indicates whether the specified cron expression can be parsed into a
* valid cron expression
* @param cronExpression the expression to evaluate
* @return a boolean indicating whether the given expression is a valid cron
* expression
public static boolean isValidExpression(String cronExpression) {
try {
new CronExpression(cronExpression);
} catch (ParseException pe) {
return false;
return true;
/**
* Indicates whether the specified cron expression can be parsed into a
* valid cron expression
* @param cronExpression the expression to evaluate
* @return a boolean indicating whether the given expression is a valid cron
* expression
public static boolean isValidExpression(String cronExpression) {
try {
new CronExpression(cronExpression);
} catch (ParseException pe) {
return false;
return true;
@Override @Deprecated public Object clone() { return new CronExpression(this);
@Override @Deprecated public Object clone() { return new CronExpression(this);
/**
* Create a CronScheduleBuilder with the given cron-expression string -
* which may not be a valid cron expression (and hence a ParseException will
* be thrown if it is not).
* @param cronExpression
* the cron expression string to base the schedule on.
* @return the new CronScheduleBuilder
* @throws ParseException
* if the expression is invalid
* @see CronExpression
public static
CronScheduleBuilder cronScheduleNonvalidatedExpression(
String cronExpression) throws ParseException {
return cronSchedule(new CronExpression(cronExpression));
/**
* Create a CronScheduleBuilder with the given cron-expression string -
* which may not be a valid cron expression (and hence a ParseException will
* be thrown if it is not).
* @param cronExpression
* the cron expression string to base the schedule on.
* @return the new CronScheduleBuilder
* @throws ParseException
* if the expression is invalid
* @see CronExpression
public static CronScheduleBuilder cronScheduleNonvalidatedExpression(
String cronExpression) throws ParseException {
return cronSchedule(new CronExpression(cronExpression));
private static CronScheduleBuilder cronScheduleNoParseException(
String presumedValidCronExpression) {
try {
return cronSchedule(new CronExpression(presumedValidCronExpression));
} catch (ParseException e) {
// all methods of construction ensure the expression is valid by
// this point...
throw new RuntimeException(
"CronExpression '"
+ presumedValidCronExpression
+ "' is invalid, which should not be possible, please report bug to Quartz developers.",
private
static CronScheduleBuilder cronScheduleNoParseException(
String presumedValidCronExpression) {
try {
return cronSchedule(new CronExpression(presumedValidCronExpression));
} catch (ParseException e) {
// all methods of construction ensure the expression is valid by
// this point...
throw new RuntimeException(
"CronExpression '"
+ presumedValidCronExpression
+ "' is invalid, which should not be possible, please report bug to Quartz developers.",
@Override public Object clone() { CronCalendar clone = (CronCalendar) super.clone(); clone.cronExpression = new CronExpression(cronExpression); return clone;
private void validateTimer() { if (isBlank(schedule)) { return; try { new CronExpression(schedule); } catch (ParseException pe) { errors.add(SCHEDULE, "Invalid cron syntax for backup configuration at offset " + pe.getErrorOffset() + ": " + pe.getMessage());
public void validate(ValidationContext validationContext) {
if (timerSpec == null) {
errors.add(TIMER_SPEC, "Timer Spec can not be null.");
return;
try {
new CronExpression(timerSpec);
} catch (ParseException pe) {
errors.add(TIMER_SPEC, "Invalid cron syntax: " + pe.getMessage());
@Override public Object clone() { CronTriggerImpl copy = (CronTriggerImpl) super.clone(); if (cronEx != null) { copy.setCronExpression(new CronExpression(cronEx)); return copy;
public void setCronExpression(String cronExpression) throws ParseException {
TimeZone origTz = getTimeZone();
this.cronEx = new CronExpression(cronExpression);
this
.cronEx.setTimeZone(origTz);
public
void setCronExpression(String cronExpression) throws ParseException {
TimeZone origTz = getTimeZone();
this.cronEx = new CronExpression(cronExpression);
this.cronEx.setTimeZone(origTz);
@Override public Object clone() { CronTriggerImpl copy = (CronTriggerImpl) super.clone(); if (cronEx != null) { copy.setCronExpression(new CronExpression(cronEx)); return copy;
private void scheduleNewBackupJob(BackupConfig newBackupConfig) {
if (newBackupConfig == null || isBlank(newBackupConfig.getSchedule())) {
return;
try {
JobDetail jobDetail = newJob()
.withIdentity(jobKey())
.ofType(ScheduleBackupQuartzJob.class)
.usingJobData(jobDataMap())
.build();
CronTrigger trigger = newTrigger()
.withIdentity(triggerKey())
.withSchedule(cronSchedule(new CronExpression(newBackupConfig.getSchedule())))
.build();
quartzScheduler.scheduleJob(jobDetail, trigger);
LOG.info("Initialized backup job with schedule " + newBackupConfig.getSchedule());
clearServerHealthError();
} catch (SchedulerException e) {
LOG.error("Unable to schedule backup job", e);
setServerHealthError("Unable to schedule backup job.", "Check the server log for detailed errors: " + e.getMessage());
} catch (ParseException e) {
LOG.error("Unable to schedule backup job", e);
setServerHealthError("Unable to schedule backup job.", "Invalid cron syntax for backup configuration at offset " + e.getErrorOffset() + ": " + e.getMessage());
private void scheduleJob(Scheduler scheduler, PipelineConfig pipelineConfig) {
TimerConfig timer = pipelineConfig.getTimer();
if (timer != null) {
try {
CronTrigger trigger = newTrigger()
.withIdentity(triggerKey(CaseInsensitiveString.str(pipelineConfig.name()), PIPELINE_TRIGGGER_TIMER_GROUP))
.withSchedule(cronSchedule(new CronExpression(timer.getTimerSpec())))
.build();
JobDetail jobDetail = newJob()
.withIdentity(jobKey(CaseInsensitiveString.str(pipelineConfig.name()), PIPELINE_TRIGGGER_TIMER_GROUP))
.ofType(SchedulePipelineQuartzJob.class)
.usingJobData(jobDataMapFor(pipelineConfig))
.build();
scheduler.scheduleJob(jobDetail, trigger);
LOG.info("Initialized timer for pipeline {} with {}", pipelineConfig.name(), timer.getTimerSpec());
} catch (ParseException e) {
showPipelineError(pipelineConfig, e,
"Bad timer specification for timer in Pipeline: " + pipelineConfig.name(),
"Cannot schedule pipeline using the timer");
} catch (SchedulerException e) {
showPipelineError(pipelineConfig, e,
"Could not register pipeline '" + pipelineConfig.name() + "' with timer",
"");