public static PlannedJob parsePlannedJob(ResultSet rs) throws SQLException { DateTime replaceTime = new DateTime(rs.getTimestamp("replaceTime")) .withZone(DateTimeZone.UTC); return new PlannedJob(parseJob(rs), replaceTime); }
public int cancelJob(PlannedJob pj) { try { int cancelled = deleteFromQueue(pj); LOG.debug("Canceled job: " + pj.getJobSpec().getId() + " with replace time: " + pj.getReplaceTime()); return cancelled; } catch (BackendException e) { throw new RuntimeException("Exception when canceling job: " + e.getMessage()); } }
synchronized public CallableJob getLatestMatching(PlannedJob pj, int limit) { Map<Long, CallableJob> toRet = new TreeMap<>(); Map<Long, CallableJob> runs = dao.getJobRuns(null, limit); for (Entry<Long, CallableJob> entry : runs.entrySet()) { Long key = entry.getKey(); CallableJob value = entry.getValue(); if (value.getPlannedJob().equals(pj)) { toRet.put(key, value); } } List<CallableJob> queries = new ArrayList<>(toRet.values()); if (queries.size() == 0) { return null; } Collections.reverse(queries); return queries.get(0); }
protected void end() { String jobName = plannedJob.getJobSpec().getName(); finish.set(System.currentTimeMillis()); reporting.histogram("chronos.query." + jobName + "." + "querytime", finish.get() - start.get()); dao.updateJobRun(this); final Long jobId = plannedJob.getJobSpec().getId(); List<JobSpec> children = dao.getChildren(jobId); for (JobSpec aChild : children) { dao.addToQueue(new PlannedJob(aChild, plannedJob.getReplaceTime())); } }
public static String getJobReportDir(String rootPath, PlannedJob plannedJob) { String job = String.valueOf(plannedJob.getJobSpec().getId()); return rootPath + File.separator + job; }
@Test public void testQueueJob() throws Exception { JobSpec job = TestAgent.getTestJob("blah", dao); long id = dao.createJob(job); job = dao.getJob(id); PlannedJob aJob = new PlannedJob(job, Utils.getCurrentTime()); List<PlannedJob> expected = new ArrayList<>(); expected.add(aJob); try { dao.addToQueue(aJob); } catch (Exception ex) { ex.printStackTrace(); } List<PlannedJob> actual = dao.getQueue(aJob.getJobSpec().getId()); assertEquals(expected, actual); PlannedJob actualPJ = null; try { actualPJ = dao.removeFromQueue(); } catch (Exception ex) { ex.printStackTrace(); } assertEquals(aJob, actualPJ); expected = new ArrayList<>(); actual = dao.getQueue(null); assertEquals(expected, actual); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + attemptNumber; result = prime * result + ((finish == null) ? 0 : finish.hashCode()); result = prime * result + (int)jobId; result = prime * result + ((plannedJob == null) ? 0 : plannedJob.hashCode()); result = prime * result + ((start == null) ? 0 : start.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode()); return result; }
public static String getJobReportPath(String reportJobPath, PlannedJob plannedJob) { String dt = COMPLETED_DT_FMT.print(plannedJob.getReplaceTime()); return reportJobPath + File.separator + dt + ".tsv"; }
public void begin() { String jobName = plannedJob.getJobSpec().getName(); reporting.mark("chronos.query." + jobName + "." + "launched"); start.set(System.currentTimeMillis()); dao.updateJobRun(this); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + attemptNumber; result = prime * result + ((finish == null) ? 0 : finish.hashCode()); result = prime * result + (int)jobId; result = prime * result + ((plannedJob == null) ? 0 : plannedJob.hashCode()); result = prime * result + ((start == null) ? 0 : start.hashCode()); result = prime * result + ((status == null) ? 0 : status.hashCode()); return result; }
attachmentPart.setDataHandler(new DataHandler(attachment)); String fileName = String.format("%s-%s.tsv", currJob.getName(), DT_FMT.print(plannedJob.getReplaceTime())); attachmentPart.setFileName(fileName); multipart.addBodyPart(attachmentPart);
public void doRun() { DateTime now = Utils.getCurrentTime(); List<JobSpec> jobs = dao.getJobs(); for (JobSpec aJob : jobs) { if (shouldJobRun(aJob, now)) { LOG.info("Adding job to queue:" + aJob); dao.addToQueue(new PlannedJob(aJob, now)); } } try { LOG.info(String.format("Sleeping for %d seconds...", (SLEEP_FOR / 1000))); Thread.sleep(SLEEP_FOR); } catch (InterruptedException e) { e.printStackTrace(); } }
public void setReplacedCode() { Long id = plannedJob.getJobSpec().getId(); JobSpec currJob = dao.getJob(id); this.replacedCode = QueryReplaceUtil.replaceDateValues( currJob.getCode(), plannedJob.getReplaceTime()); }
public void addToQueue(PlannedJob aJob) { try { super.addToQueue(aJob); LOG.info("Queued job:" + aJob.getJobSpec().getName()); } catch (BackendException e) { throw new RuntimeException("Exception when queueing job:" + e.getMessage()); } }
return false; } else if (!plannedJob.equals(other.plannedJob)) { return false;
public void run() { for (int i = 0; i < size; i++) { JobSpec job = TestAgent.getTestJob(UUID.randomUUID().toString(), dao); long id = dao.createJob(job); job = dao.getJob(id); PlannedJob aJob = new PlannedJob(job, Utils.getCurrentTime()); try { dao.addToQueue(aJob); } catch (Exception ex) { ex.printStackTrace(); } expected.add(aJob); } } };
public void addToQueue(PlannedJob aJob) throws BackendException { Connection conn = null; PreparedStatement stat = null; try { conn = newConnection(); stat = conn.prepareStatement( String.format("INSERT INTO %s " + "(job_id, job_lastModified, replaceTime) " + "VALUES (?, ?, ?)", queueTableName), Statement.RETURN_GENERATED_KEYS); int i = 1; stat.setLong(i++, aJob.getJobSpec().getId()); Timestamp lm = new Timestamp(aJob.getJobSpec().getLastModified().getMillis()); stat.setTimestamp(i++, lm); Timestamp rt = new Timestamp(aJob.getReplaceTime().getMillis()); stat.setTimestamp(i++, rt); int rows = stat.executeUpdate(); LOG.info(String.format("Rows updated: %d", rows)); } catch (SQLException ex) { throw new BackendException(ex); } finally { closeConnections(conn, stat); } }
public CallableJob assembleCallableJob(PlannedJob plannedJob, int attemptNumber) { switch(plannedJob.getJobSpec().getType()) { case Query: { SupportedDriver driver = SupportedDriver.getSupportedDriverFromString( plannedJob.getJobSpec().getDriver(), drivers); return new CallableQuery(plannedJob, dao, reporter, hostname, mailInfo, session, driver, reportRootPath, attemptNumber); } case Script: return new CallableScript(plannedJob, dao, reporter, -1L, hostname, mailInfo, session, attemptNumber); default: throw new UnsupportedOperationException( String.format("Unknown jobtype...%s", plannedJob.getJobSpec().getType())); } }
return false; } else if (!plannedJob.equals(other.plannedJob)) { return false;
JobSpec jobSpec = getTestJob("ajob", new JobDaoImpl()); DateTime dateTime = new DateTime(); PlannedJob plannedJob = new PlannedJob(jobSpec, dateTime); String jobId = String.valueOf(jobSpec.getId());