/** * Inserts the Job info object into job table * * @param jobInfo * @return number of rows inserted. * @throws SQLException */ public int insertIntoJobTable(SchedulerJobInfo jobInfo) throws SQLException { String insertSQL = "INSERT INTO " + JOB_TABLE + " VALUES(?,?,?,?,?,?,?)"; JAXBElement<XJob> xmlJob = jobFactory.createJob(jobInfo.getJob()); return runner.update(insertSQL, jobInfo.getId().toString(), ToXMLString.toString(xmlJob), jobInfo.getUserName(), jobInfo.getJobState().name(), jobInfo.getCreatedOn(), jobInfo.getModifiedOn(), jobInfo.getJob().getName()); }
/** * {@inheritDoc} */ @Override public void scheduleJob(LensSessionHandle sessionHandle, SchedulerJobHandle jobHandle) throws LensException { SchedulerJobInfo jobInfo = checkAndGetSchedulerJobInfo(jobHandle); doesSessionBelongToUser(sessionHandle, jobInfo.getUserName()); XJob job = jobInfo.getJob(); DateTime start = new DateTime(job.getStartTime().toGregorianCalendar().getTime()); DateTime end = new DateTime(job.getEndTime().toGregorianCalendar().getTime()); XFrequency frequency = job.getTrigger().getFrequency(); // check query checkQuery(sessionHandle, job); alarmService.schedule(start, end, frequency, jobHandle.getHandleIdString()); log.info("Successfully scheduled job with handle {} in AlarmService", jobHandle); setStateOfJob(jobInfo, SchedulerJobEvent.ON_SCHEDULE); }
/** * Updates the job definition from the new SchedulerJobInfo * * @param info: Updated info object. * @return number of rows updated. */ public int updateJob(SchedulerJobInfo info) { try { return store.updateJob(info.getId().getHandleIdString(), info.getJob(), info.getModifiedOn()); } catch (SQLException e) { log.error("Error while updating job for {}", info.getId().getHandleIdString(), e); return 0; } }
@Test public void submitNScheduleQuery() throws Exception { String startDate = Util.modifyDate(currentDate, format, Calendar.DATE, -1); String endDate = Util.modifyDate(currentDate, format, Calendar.DATE, 3); XJob xJob = scheduleHelper.getXJob("job-submit-schedule", QueryInventory.JDBC_CUBE_QUERY, null, startDate, endDate, XFrequencyEnum.DAILY); String jobHandle = scheduleHelper.submitNScheduleJob(xJob, sessionHandleString); Assert.assertNotNull(jobHandle); Assert.assertEquals(scheduleHelper.getJobStatus(jobHandle), SchedulerJobState.SCHEDULED); SchedulerJobInfo jobInfo = scheduleHelper.getJobDetails(jobHandle, sessionHandleString).getData(); Assert.assertNotNull(jobInfo); Assert.assertEquals(jobInfo.getJob().getName(), "job-submit-schedule"); }