/** * 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; } }
/** * 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; } }
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()); } }
@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); }
@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); }
/** * 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()); }