/** * 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 updateJob(LensSessionHandle sessionHandle, SchedulerJobHandle jobHandle, XJob newJobDefinition) throws LensException { SchedulerJobInfo jobInfo = checkAndGetSchedulerJobInfo(jobHandle); doesSessionBelongToUser(sessionHandle, jobInfo.getUserName()); // This will allow only the job definition and configuration change. jobInfo.setJob(newJobDefinition); jobInfo.setModifiedOn(System.currentTimeMillis()); int updated = schedulerDAO.updateJob(jobInfo); if (updated > 0) { return; } throw new LensException(LensSchedulerErrorCode.CANT_UPDATE_RESOURCE_WITH_HANDLE.getLensErrorInfo(), null, "job", jobHandle.getHandleIdString()); }
private void setStateOfJob(SchedulerJobInfo info, SchedulerJobEvent event) throws LensException { SchedulerJobState currentState = info.getJobState(); try { SchedulerJobState nextState = currentState.nextTransition(event); info.setJobState(nextState); info.setModifiedOn(System.currentTimeMillis()); int ret = schedulerDAO.updateJobStatus(info); if (ret == 1) { log.info("Successfully changed the status of job with handle {} from {} to {}", info.getId(), currentState, nextState); } else { throw new LensException(LensSchedulerErrorCode.CANT_UPDATE_RESOURCE_WITH_HANDLE.getLensErrorInfo(), null, "job", info.getId().getHandleIdString()); } } catch (InvalidStateTransitionException e) { throw new LensException(LensSchedulerErrorCode.INVALID_EVENT_FOR_JOB.getLensErrorInfo(), e, event.name(), currentState.name(), info.getId().getHandleIdString()); } }
/** * 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; } }
/** * Updates the job status form the new SchedulerJobInfo * * @param info: Updated info objects * @return number of rows updated. */ public int updateJobStatus(SchedulerJobInfo info) { try { return store.updateJobStatus(info.getId().getHandleIdString(), info.getJobState().name(), info.getModifiedOn()); } catch (SQLException e) { log.error("Error while updating job status for {}", info.getId().getHandleIdString(), e); return 0; } }
@Test(priority = 2) public void testUpdateJob() throws Exception { // Get all the stored jobs. // update one and check if it successful. SchedulerJobInfo jobInfo = schedulerDAO.getSchedulerJobInfo(jobHandle); XJob newJob = getTestJob(); jobInfo.setJob(newJob); schedulerDAO.updateJob(jobInfo); XJob storedJob = schedulerDAO.getJob(jobInfo.getId()); Assert.assertEquals(storedJob, newJob); // Change SchedulerJobInstanceState jobInfo.setJobState(jobInfo.getJobState().nextTransition(SchedulerJobEvent.ON_SCHEDULE)); schedulerDAO.updateJobStatus(jobInfo); Assert.assertEquals(schedulerDAO.getJobState(jobInfo.getId()), SchedulerJobState.SCHEDULED); }
@Test(priority = 1) public void testStoreJob() throws Exception { XJob job = getTestJob(); long currentTime = System.currentTimeMillis(); jobHandle = new SchedulerJobHandle(UUID.randomUUID()); SchedulerJobInfo info = new SchedulerJobInfo(jobHandle, job, "lens", SchedulerJobState.NEW, currentTime, currentTime); // Store the job schedulerDAO.storeJob(info); // Retrive the stored job XJob outJob = schedulerDAO.getJob(info.getId()); Assert.assertEquals(job, outJob); }
public SchedulerJobState getJobStatus(String jobHandle, String sessionHandleString){ SchedulerJobInfo jobInfo = getJobDetails(jobHandle, sessionHandleString).getData(); return jobInfo.getJobState(); }
/** * {@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); }
/** * Gets the Job info object * * @param idStr * @return SchedulerJobInfo object corresponding to the job handle. * @throws SQLException */ public SchedulerJobInfo getSchedulerJobInfo(String idStr) throws SQLException { String fetchSQL = "SELECT * FROM " + JOB_TABLE + " WHERE " + COLUMN_ID + "=?"; List<Object[]> result = runner.query(fetchSQL, multipleRowsHandler, idStr); if (result.size() == 0) { return null; } else { Object[] jobInfo = result.get(0); SchedulerJobHandle id = SchedulerJobHandle.fromString((String) jobInfo[0]); XJob xJob = ToXMLString.valueOf((String) jobInfo[1], ObjectFactory.class); String userName = (String) jobInfo[2]; String status = (String) jobInfo[3]; long createdOn = (Long) jobInfo[4]; long modifiedOn = (Long) jobInfo[5]; SchedulerJobState jobState = SchedulerJobState.valueOf(status); return new SchedulerJobInfo(id, xJob, userName, jobState, createdOn, modifiedOn); } }
/** * Saves the SchedulerJobInfo object into the store. * * @param jobInfo object * @return the number of records stored */ public int storeJob(SchedulerJobInfo jobInfo) { try { return store.insertIntoJobTable(jobInfo); } catch (SQLException e) { log.error("Error while storing the jobInfo for {}", jobInfo.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"); }
/** * {@inheritDoc} */ @Override public void expireJob(LensSessionHandle sessionHandle, SchedulerJobHandle jobHandle) throws LensException { SchedulerJobInfo info = checkAndGetSchedulerJobInfo(jobHandle); doesSessionBelongToUser(sessionHandle, info.getUserName()); if (alarmService.checkExists(jobHandle)) { alarmService.unSchedule(jobHandle); log.info("Successfully unscheduled the job with handle {} in AlarmService ", jobHandle); } setStateOfJob(info, SchedulerJobEvent.ON_EXPIRE); }
public SchedulerJobState getJobStatus(String jobHandle){ SchedulerJobInfo jobInfo = getJobDetails(jobHandle, sessionHandleString).getData(); return jobInfo.getJobState(); }
/** * {@inheritDoc} */ @Override public SchedulerJobHandle submitJob(LensSessionHandle sessionHandle, XJob job) throws LensException { LensSessionImpl session = getSession(sessionHandle); // Validate XJob validateJob(session, job); SchedulerJobHandle handle = UtilityMethods.generateSchedulerJobHandle(); long createdOn = System.currentTimeMillis(); SchedulerJobInfo info = new SchedulerJobInfo(handle, job, session.getLoggedInUser(), SchedulerJobState.NEW, createdOn, createdOn); if (schedulerDAO.storeJob(info) == 1) { log.info("Successfully submitted job with handle {}", handle); return handle; } else { throw new LensException(LensSchedulerErrorCode.CANT_SUBMIT_JOB.getLensErrorInfo(), null, job.getName()); } }
/** * {@inheritDoc} */ @Override public void deleteJob(LensSessionHandle sessionHandle, SchedulerJobHandle jobHandle) throws LensException { SchedulerJobInfo info = checkAndGetSchedulerJobInfo(jobHandle); doesSessionBelongToUser(sessionHandle, info.getUserName()); if (alarmService.checkExists(jobHandle)) { alarmService.unSchedule(jobHandle); log.info("Successfully unscheduled the job with handle {} ", jobHandle); } setStateOfJob(info, SchedulerJobEvent.ON_DELETE); }
@Test(priority = 3) public void testSearchStoreJob() throws Exception { // Store more jobs with the one user and search XJob job = getTestJob(); long currentTime = System.currentTimeMillis(); SchedulerJobInfo info = new SchedulerJobInfo(SchedulerJobHandle.fromString(UUID.randomUUID().toString()), job, "lens", SchedulerJobState.NEW, currentTime, currentTime); // Store the job schedulerDAO.storeJob(info); info = new SchedulerJobInfo(SchedulerJobHandle.fromString(UUID.randomUUID().toString()), job, "lens", SchedulerJobState.NEW, currentTime, currentTime); schedulerDAO.storeJob(info); // There should be 3 jobs till now. Assert.assertEquals(schedulerDAO.getJobs("lens", null, null, SchedulerJobState.values()).size(), 3); //Assert.assertEquals(schedulerDAO.getJobs("lens", 1L, System.currentTimeMillis(), SchedulerJobState.NEW).size(), 2); Assert.assertEquals(schedulerDAO.getJobs("Alice", null, null, SchedulerJobState.NEW).size(), 0); } }
/** * {@inheritDoc} */ @Override public void resumeJob(LensSessionHandle sessionHandle, SchedulerJobHandle jobHandle) throws LensException { SchedulerJobInfo info = checkAndGetSchedulerJobInfo(jobHandle); doesSessionBelongToUser(sessionHandle, info.getUserName()); alarmService.resumeJob(jobHandle); setStateOfJob(info, SchedulerJobEvent.ON_RESUME); }
/** * {@inheritDoc} */ @Override public void suspendJob(LensSessionHandle sessionHandle, SchedulerJobHandle jobHandle) throws LensException { SchedulerJobInfo info = checkAndGetSchedulerJobInfo(jobHandle); doesSessionBelongToUser(sessionHandle, info.getUserName()); alarmService.pauseJob(jobHandle); setStateOfJob(info, SchedulerJobEvent.ON_SUSPEND); }