/** * String representation of the SchedulerJobInstanceHandle. * * @return the handleID as a string */ @Override public String toString() { return getHandleIdString(); }
/** * String representation of the SchedulerJobInstanceHandle. * * @return the handleID as a string */ @Override public String toString() { return getHandleIdString(); }
/** * Gets the SchedulerJobInstanceInfo corresponding instance handle id. * * @param id : Job instance id * @return ShedulerJobInstanceInfo */ public SchedulerJobInstanceInfo getSchedulerJobInstanceInfo(SchedulerJobInstanceHandle id) { try { return store.getJobInstanceInfo(id.getHandleIdString()); } catch (SQLException e) { log.error("Error while getting the job instance info for {}", id.getHandleIdString(), e); return null; } }
public int storeJobInstanceRun(SchedulerJobInstanceRun instanceRun) { try { return store.insertIntoJobInstanceRunTable(instanceRun); } catch (SQLException e) { log.error("Error while storing job instance run for {} with run id {} ", instanceRun.getHandle().getHandleIdString(), instanceRun.getRunId(), e); return 0; } }
/** * Updates the instance status * * @param instanceRun : instance Run object * @return number of rows updated. */ public int updateJobInstanceRun(SchedulerJobInstanceRun instanceRun) { try { return store.updateJobInstanceRun(instanceRun); } catch (SQLException e) { log.error("Error while updating the job instance status for {} and run id {}", instanceRun.getHandle().getHandleIdString(), instanceRun.getRunId(), e); return 0; } }
/** * Inserts the job instance info object into job instance table * * @param instanceInfo * @return number of rows inserted. * @throws SQLException */ public int insertIntoJobInstanceTable(SchedulerJobInstanceInfo instanceInfo) throws SQLException { String insertSQL = "INSERT INTO " + JOB_INSTANCE_TABLE + " VALUES(?,?,?)"; return runner .update(insertSQL, instanceInfo.getId().getHandleIdString(), instanceInfo.getJobId().getHandleIdString(), instanceInfo.getScheduleTime()); }
@Test public void updateInstance() throws Exception { String startDate = Util.modifyDate(Util.getCurrentDate(format), format, Calendar.SECOND, 10); String endDate = Util.modifyDate(startDate, format, Calendar.MINUTE, 3); XJob xJob = scheduleHelper.getXJob("job-update-action", QueryInventory.JDBC_DIM_QUERY, null, startDate, endDate, "0/20 * * * * ?"); String jobHandle = scheduleHelper.submitNScheduleJob(xJob, sessionHandleString); Thread.sleep(20000); List<SchedulerJobInstanceInfo> instanceList = scheduleHelper.getAllInstancesOfJob(jobHandle, "10", sessionHandleString); Thread.sleep(10000); LensAPIResult res = scheduleHelper.updateInstance(instanceList.get(0).getId().getHandleIdString(), "RERUN", sessionHandleString); Assert.assertTrue(res.getData().equals(true)); SchedulerJobInstanceInfo instanceInfo = scheduleHelper.getInstanceDetails(instanceList.get(0).getId() .getHandleIdString(), sessionHandleString).getData(); List<SchedulerJobInstanceRun> runList = instanceInfo.getInstanceRunList(); Assert.assertEquals(runList.size(), 2); Assert.assertEquals(runList.get(1).getRunId(), 2); }
public static QueryEnded mockQueryEnded(SchedulerJobInstanceHandle instanceHandle, QueryStatus.Status status) { QueryContext mockContext = PowerMockito.mock(QueryContext.class); PowerMockito.when(mockContext.getResultSetPath()).thenReturn("/tmp/query1/result"); Configuration conf = new Configuration(); // set the instance handle conf.set("job_instance_key", instanceHandle.getHandleIdString()); PowerMockito.when(mockContext.getConf()).thenReturn(conf); // Get the queryHandle. PowerMockito.when(mockContext.getQueryHandle()).thenReturn(new QueryHandle(UUID.randomUUID())); QueryEnded queryEnded = PowerMockito.mock(QueryEnded.class); PowerMockito.when(queryEnded.getQueryContext()).thenReturn(mockContext); PowerMockito.when(queryEnded.getCurrentValue()).thenReturn(status); return queryEnded; } }
if (runList.size() == 0) { throw new LensException(LensSchedulerErrorCode.JOB_INSTANCE_IS_NOT_YET_RUN.getLensErrorInfo(), null, instanceHandle.getHandleIdString(), instanceInfo.getJobId().getHandleIdString()); } catch (InvalidStateTransitionException e) { throw new LensException(LensSchedulerErrorCode.INVALID_EVENT_FOR_JOB_INSTANCE.getLensErrorInfo(), e, ON_KILL.name(), latestRun.getInstanceState().name(), instanceInfo.getId().getHandleIdString(), instanceInfo.getJobId().getHandleIdString());
log.error("Not able to recover instance {} ", run.getHandle().getHandleIdString(), e); } finally { try {
/** * {@inheritDoc} */ @Override public void rerunInstance(LensSessionHandle sessionHandle, SchedulerJobInstanceHandle instanceHandle) throws LensException { SchedulerJobInstanceInfo instanceInfo = schedulerDAO.getSchedulerJobInstanceInfo(instanceHandle); doesSessionBelongToUser(sessionHandle, schedulerDAO.getUser(instanceInfo.getJobId())); SchedulerJobState currentState = schedulerDAO.getJobState(instanceInfo.getJobId()); if (currentState != SchedulerJobState.SCHEDULED) { throw new LensException(LensSchedulerErrorCode.JOB_IS_NOT_SCHEDULED.getLensErrorInfo(), null, instanceInfo.getJobId().getHandleIdString(), currentState); } // Get the latest run. List<SchedulerJobInstanceRun> runList = instanceInfo.getInstanceRunList(); if (runList.size() == 0) { throw new LensException(LensSchedulerErrorCode.JOB_INSTANCE_IS_NOT_YET_RUN.getLensErrorInfo(), null, instanceHandle.getHandleIdString(), instanceInfo.getJobId().getHandleIdString()); } SchedulerJobInstanceRun latestRun = runList.get(runList.size() - 1); try { latestRun.getInstanceState().nextTransition(ON_RERUN); notifyRerun(instanceInfo); log.info("Rerunning the instance with {} for job {} ", instanceHandle, instanceInfo.getJobId()); } catch (InvalidStateTransitionException e) { throw new LensException(LensSchedulerErrorCode.INVALID_EVENT_FOR_JOB_INSTANCE.getLensErrorInfo(), e, ON_RERUN.name(), latestRun.getInstanceState().name(), instanceInfo.getId().getHandleIdString(), instanceInfo.getJobId().getHandleIdString()); } }
/** * Updates the status of a job instance. * * @param instanceRun * @return number of rows updated. * @throws SQLException */ public int updateJobInstanceRun(SchedulerJobInstanceRun instanceRun) throws SQLException { String updateSQL = "UPDATE " + JOB_INSTANCE_RUN_TABLE + " SET " + COLUMN_END_TIME + "=?, " + COLUMN_RESULT_PATH + "=?, " + COLUMN_QUERY_HANDLE + "=?, " + COLUMN_STATUS + "=?" + " WHERE " + COLUMN_ID + "=? AND " + COLUMN_RUN_ID + "=?"; return runner.update(updateSQL, instanceRun.getEndTime(), instanceRun.getResultPath(), instanceRun.getQueryHandle() == null ? "" : instanceRun.getQueryHandle().getHandleIdString(), instanceRun.getInstanceState().name(), instanceRun.getHandle().getHandleIdString(), instanceRun.getRunId()); }
@Test public void testRunningInstanceOnRestart() throws Exception { String startDate = Util.modifyDate(Util.getCurrentDate(format), format, Calendar.SECOND, 2); String endDate = Util.modifyDate(startDate, format, Calendar.SECOND, 15); XJob xJob = scheduleHelper.getXJob("job-restart", QueryInventory.getSleepQuery("5"), null, startDate, endDate, "0/10 * * * * ?"); String jobHandle = scheduleHelper.submitNScheduleJob(xJob, sessionHandleString); Thread.sleep(10000); List<SchedulerJobInstanceInfo> instanceList = scheduleHelper.getAllInstancesOfJob(jobHandle, "10", sessionHandleString); lens.restart(); SchedulerJobInstanceInfo instanceInfo = scheduleHelper.getInstanceDetails(instanceList.get(0).getId() .getHandleIdString(), sessionHandleString).getData(); SchedulerJobInstanceRun instanceRun = instanceInfo.getInstanceRunList().get(0); qHelper.waitForCompletion(instanceRun.getQueryHandle()); Assert.assertEquals(instanceRun.getInstanceState(), SchedulerJobInstanceState.SUCCEEDED); }
@Test(enabled = false) public void testQueryNotFoundCaseOnRestart() throws Exception { String startDate = Util.modifyDate(Util.getCurrentDate(format), format, Calendar.SECOND, 2); String endDate = Util.modifyDate(startDate, format, Calendar.SECOND, 15); XJob xJob = scheduleHelper.getXJob("job-restart", QueryInventory.getSleepQuery("5"), null, startDate, endDate, "0/10 * * * * ?"); String jobHandle = scheduleHelper.submitNScheduleJob(xJob, sessionHandleString); Thread.sleep(10000); List<SchedulerJobInstanceInfo> instanceList = scheduleHelper.getAllInstancesOfJob(jobHandle, "10", sessionHandleString); lens.stop(); Util.runRemoteCommand("hadoop dfs -rmr /tmp/lensserver/query.*"); lens.start(); Thread.sleep(15000); // wait till instance gets killed and new instance is spawned String firstInstanceHandle = instanceList.get(0).getId().getHandleIdString(); SchedulerJobInstanceInfo instanceInfo = scheduleHelper.getInstanceDetails(firstInstanceHandle, sessionHandleString) .getData(); Assert.assertEquals(instanceInfo.getInstanceRunList().get(0).getInstanceState(), SchedulerJobInstanceState.KILLED); qHelper.waitForCompletion(instanceInfo.getInstanceRunList().get(1).getQueryHandle()); Thread.sleep(3000); instanceInfo = scheduleHelper.getInstanceDetails(firstInstanceHandle, sessionHandleString).getData(); Assert.assertEquals(instanceInfo.getInstanceRunList().get(1).getInstanceState(), SchedulerJobInstanceState.SUCCEEDED); }
public int insertIntoJobInstanceRunTable(SchedulerJobInstanceRun instanceRun) throws SQLException { String insetSQL = "INSERT INTO " + JOB_INSTANCE_RUN_TABLE + " VALUES(?,?,?,?,?,?,?,?)"; return runner.update(insetSQL, instanceRun.getHandle().getHandleIdString(), instanceRun.getRunId(), instanceRun.getSessionHandle() == null ? "" : instanceRun.getSessionHandle().toString(), instanceRun.getStartTime(), instanceRun.getEndTime(), instanceRun.getResultPath(), instanceRun.getQueryHandle() == null ? "" : instanceRun.getQueryHandle().getHandleIdString(), instanceRun.getInstanceState().name()); }