private static SchedulerServiceException checked(String message, Throwable e) { return new SchedulerServiceException(message, e); }
void assertException(Schedule schedule, String substring) { final SchedulerService schedulerService = getSchedulerService(); try { final Date nextRunTime = schedulerService.calculateNextRunTime(schedule); fail("Got first run time <" + nextRunTime + "> when exception containing <" + substring + "> was expected for <" + schedule + '>'); } catch (SchedulerServiceException sse) { assertThat(sse.getMessage(), containsString(substring)); } } }
@Override @Nonnull public Status scheduleDelayedUpgrades(final int delayMins, final boolean isAllowReindex) { final Schedule schedule = Schedule.runOnce(DateTime.now().plusMinutes(delayMins).toDate()); JobConfig jobConfig = JobConfig.forJobRunnerKey(JOB_RUNNER_KEY) .withSchedule(schedule) .withParameters(ImmutableMap.<String, Serializable>of(REINDEX_ALLOWED_PROPERTY, isAllowReindex)); try { schedulerService.scheduleJob(JOB_ID, jobConfig); } catch (SchedulerServiceException e) { log.error( "Unable to schedule upgrade tasks for future execution :" + e, e); final Collection<String> errors = ImmutableList.of( "Unable to schedule upgrade tasks for future execution: " + e.getMessage() + '\n' + ExceptionUtils.getStackTrace(e)); return new Status(errors); } return Status.OK; }
@Test public void testSchedulerServiceJob() throws Exception { final CountDownLatch latch = new CountDownLatch(1); schedulerService.registerJobRunner(jobRunnerKey, new JobRunner() { @Nullable @Override public JobRunnerResponse runJob(JobRunnerRequest jobRunnerRequest) { latch.countDown(); return null; } }); final JobConfig jobConfig = JobConfig.forJobRunnerKey(jobRunnerKey) .withRunMode(RunMode.RUN_LOCALLY) .withSchedule(Schedule.runOnce(null)); try { schedulerService.scheduleJobWithGeneratedId(jobConfig); } catch (SchedulerServiceException sse) { throw new SchedulerRuntimeException(sse.getMessage(), sse); } assertThat(latch.await(30, TimeUnit.SECONDS), is(true)); }
@Override synchronized public final void start() throws SchedulerServiceException { LOG.debug("{} -> STARTED", state); switch (state) { case STARTED: return; case SHUTDOWN: throw new SchedulerServiceException("The scheduler service has been shut down; it cannot be restarted."); } startImpl(); state = State.STARTED; }
private JobId generateUniqueJobId() throws SchedulerServiceException { for (int i = 0; i < MAX_ATTEMPTS; ++i) { final JobId jobId = JobId.of(UUID.randomUUID().toString()); if (getJobDetails(jobId) == null) { return jobId; } } throw new SchedulerServiceException("Unable to generate a unique job ID"); }
/** * Converts the unchecked {@code SchedulerRuntimeException} to the checked * {@code SchedulerServiceException}. It makes sense to do this in many cases * where the checked exception is declared, as the caller is already having to * handle it. * <p> * The message and cause of the {@code SchedulerServiceException} are taken from * the {@link Throwable#getCause() cause} of the runtime exception. If no cause * was set, then the runtime exception itself is used. * </p> * * @param sre the scheduler runtime exception to convert * @return the converted exception */ protected static SchedulerServiceException checked(SchedulerRuntimeException sre) { Throwable cause = sre.getCause(); if (cause == null) { cause = sre; } return new SchedulerServiceException(cause.toString(), cause); }
throw new SchedulerServiceException("Serialization failed", ioe);
@Override synchronized public final void standby() throws SchedulerServiceException { LOG.debug("{} -> STANDBY", state); switch (state) { case STANDBY: return; case SHUTDOWN: throw new SchedulerServiceException("The scheduler service has been shut down; it cannot be restarted."); } cancelJobs(); standbyImpl(); state = State.STANDBY; }