public JobNode getTree(long id, String parent) { JobSpec aJob = getJob(id); JobNode toRet = new JobNode(aJob.getName(), parent); for (JobSpec child : getChildren(id)) { JobNode jn = getTree(child.getId(), aJob.getName()); toRet.getChildren().add(jn); } return toRet; } }
public void setReplacedCode() { Long id = plannedJob.getJobSpec().getId(); JobSpec currJob = dao.getJob(id); this.replacedCode = QueryReplaceUtil.replaceDateValues( currJob.getCode(), plannedJob.getReplaceTime()); }
public static String getJobReportDir(String rootPath, PlannedJob plannedJob) { String job = String.valueOf(plannedJob.getJobSpec().getId()); return rootPath + File.separator + job; }
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())); } }
@Test public void testBasicDependent() { JobSpec expected = TestAgent.getTestJob("Mrs Dalloway", dao); JobSpec childJob = TestAgent.getTestJob("A child", dao); try { dao.createJob(expected); childJob.setParent(expected.getId()); dao.createJob(childJob); } catch (Exception ex) { ex.printStackTrace(); } JobSpec actual = dao.getJob(expected.getId()); assertEquals(expected, actual); }
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()); } }
public void begin() { String jobName = plannedJob.getJobSpec().getName(); reporting.mark("chronos.query." + jobName + "." + "launched"); start.set(System.currentTimeMillis()); dao.updateJobRun(this); }
public static JobSpec getTestScript(String aName, JobDao dao) { JobSpec aJob = getTestJob(aName, dao); aJob.setType(JobType.Script); aJob.setCode("echo 'beep';"); aJob.setResultTable(null); return aJob; }
@Test public void testReplacedReportQuery() { JobSpec aJob = TestAgent.getTestJob("Mark Rothko", dao); aJob.setResultQuery("select * from blah where dt=${YYYMMDDHH}"); dao.createJob(aJob); PlannedJob pj = new PlannedJob(aJob, Utils.getCurrentTime()); CallableQuery cq = new CallableQuery(pj, dao, null, "example.com", null, null, null, null, 1); String expected = "select * from blah where dt=1970010100"; Assert.assertEquals(expected, cq.getReplacedReportQuery()); }
private Connection getConnectionForJobSpec(JobSpec jobSpec) { try { Class.forName(driver.getDriverName()); return DriverManager.getConnection(driver.getConnectionUrl(), jobSpec.getUser(), jobSpec.getPassword()); } catch (ClassNotFoundException | SQLException e) { throw new RuntimeException(e); } }
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()); } }
@Override public void close() throws IOException { super.close(); if (dao != null) { dao.close(); } }
public static String genErrorMessage(JobSpec aJob, String error) { String jobName = aJob.getName(); String aMessage = String.format("Error when running script %s: %s", jobName, error); return aMessage; }
@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; }
@Override public void init() throws BackendException { initBackend(); LOG.info("Backend initalized"); }
public static String getJobReportPath(String reportJobPath, PlannedJob plannedJob) { String dt = COMPLETED_DT_FMT.print(plannedJob.getReplaceTime()); return reportJobPath + File.separator + dt + ".tsv"; }
public static ArrayList<SupportedDriver> createDriverForTesting() { ArrayList<SupportedDriver> drivers = new ArrayList<>(); SupportedDriver d = new SupportedDriver(H2_NAME, H2_DRIVER, H2_QUERY, H2_URL); drivers.add(d); return drivers; }
@After public void cleanup() throws Exception { dao.close(); }
@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; }