@Override public String applicationName() { return this.ji.getJD().getApplicationName(); }
@Override public String getApplicationName() { return this.ji.getJD().getApplicationName(); }
@Override public String getApplicationName() { return this.ji.getJD().getApplicationName(); }
@Override public String getApplicationName() { return this.job.getJD().getApplicationName(); }
@Override public String applicationName() { return this.ji.getJD().getApplicationName(); }
/** * Returns true if the libraries should be loaded in cache. Two cases: never loaded and should be reloaded (jar is more recent than * cache) */ private boolean shouldLoad(Node node, JobDef jd) { if (!cache.containsKey(jd.getApplicationName())) { return true; } // If here: cache exists. JobDefLibrary libs = cache.get(jd.getApplicationName()); // Is cache stale? Date lastLoaded = libs.loadTime; File jarFile = new File(FilenameUtils.concat(new File(node.getRepo()).getAbsolutePath(), jd.getJarPath())); File jarDir = jarFile.getParentFile(); File libDir = new File(FilenameUtils.concat(jarDir.getAbsolutePath(), "lib")); if (lastLoaded.before(new Date(jarFile.lastModified())) || lastLoaded.before(new Date(jarDir.lastModified())) || lastLoaded.before(new Date(libDir.lastModified()))) { jqmlogger.info("The cache for application " + jd.getApplicationName() + " will be reloaded"); return true; } // If here, the cache is OK return false; }
/** * * @param n * the JQM Node that holds the binaries (local node) * @param jd * the JobDefinition that should be resolved * @param cnx * a DbConn that will be used only if not in cache, to fetch the Maven repository list from the database. * @throws JqmPayloadException */ synchronized URL[] getLibraries(Node n, JobDef jd) throws JqmPayloadException { if (shouldLoad(n, jd)) { loadCache(n, jd); } return cache.get(jd.getApplicationName()).urls; }
private static Element getQueueElement(Queue q, DbConn cnx) { Element queue = new Element("queue"); Element name = new Element("name"); name.setText(q.getName()); Element description = new Element("description"); description.setText(q.getDescription()); Element timeToLive = new Element("timeToLive"); timeToLive.setText(q.getTimeToLive() + ""); queue.addContent(name); queue.addContent(description); queue.addContent(timeToLive); Element jobs = new Element("jobs"); queue.addContent(jobs); List<JobDef> jds = JobDef.select(cnx, "jd_select_by_queue", q.getId()); for (JobDef j : jds) { Element job = new Element("applicationName"); job.setText(j.getApplicationName()); jobs.addContent(job); } return queue; }
private static Element getQueueElement(Queue q, DbConn cnx) { Element queue = new Element("queue"); Element name = new Element("name"); name.setText(q.getName()); Element description = new Element("description"); description.setText(q.getDescription()); Element timeToLive = new Element("timeToLive"); timeToLive.setText(q.getTimeToLive() + ""); queue.addContent(name); queue.addContent(description); queue.addContent(timeToLive); Element jobs = new Element("jobs"); queue.addContent(jobs); List<JobDef> jds = JobDef.select(cnx, "jd_select_by_queue", q.getId()); for (JobDef j : jds) { Element job = new Element("applicationName"); job.setText(j.getApplicationName()); jobs.addContent(job); } return queue; }
/** * Retrieves the most adequate {@link JobRunner} for a given {@link JobInstance}. Throws {@link JqmRuntimeException} if none was found. * * @param ji * @return */ JobRunner getRunner(JobInstance ji) { if (runnerCache.containsKey(ji.getJdId())) { return runnerCache.get(ji.getJdId()); } for (JobRunner runner : runners) { if (runner.canRun(ji)) { runnerCache.put(ji.getJdId(), runner); return runner; } } throw new JqmRuntimeException("there is no runner able to run job definition " + ji.getJD().getApplicationName()); } }
/** * Retrieves the most adequate {@link JobRunner} for a given {@link JobInstance}. Throws {@link JqmRuntimeException} if none was found. * * @param ji * @return */ JobRunner getRunner(JobInstance ji) { if (runnerCache.containsKey(ji.getJdId())) { return runnerCache.get(ji.getJdId()); } for (JobRunner runner : runners) { if (runner.canRun(ji)) { runnerCache.put(ji.getJdId(), runner); return runner; } } throw new JqmRuntimeException("there is no runner able to run job definition " + ji.getJD().getApplicationName()); } }
@Override public Integer addDeliverable(String path, String fileLabel) { DbConn cnx = Helpers.getNewDbSession(); try { String outputRoot = this.ji.getNode().getDlRepo(); String ext = FilenameUtils.getExtension(path); String relDestPath = ji.getJD().getApplicationName() + "/" + ji.getId() + "/" + UUID.randomUUID() + "." + ext; String absDestPath = FilenameUtils.concat(outputRoot, relDestPath); String fileName = FilenameUtils.getName(path); jqmlogger.debug("A deliverable is added. Stored as " + absDestPath + ". Initial name: " + fileName); FileUtils.moveFile(new File(path), new File(absDestPath)); cnx.commit(); int res = Helpers.createDeliverable(relDestPath, fileName, fileLabel, this.ji.getId(), cnx); cnx.commit(); return res; } catch (IOException e) { throw new JqmClientException(e); } finally { Helpers.closeQuietly(cnx); } }
@Override public Integer addDeliverable(String path, String fileLabel) { DbConn cnx = Helpers.getNewDbSession(); try { String outputRoot = this.ji.getNode().getDlRepo(); String ext = FilenameUtils.getExtension(path); String relDestPath = ji.getJD().getApplicationName() + "/" + ji.getId() + "/" + UUID.randomUUID() + "." + ext; String absDestPath = FilenameUtils.concat(outputRoot, relDestPath); String fileName = FilenameUtils.getName(path); jqmlogger.debug("A deliverable is added. Stored as " + absDestPath + ". Initial name: " + fileName); FileUtils.moveFile(new File(path), new File(absDestPath)); cnx.commit(); int res = Helpers.createDeliverable(relDestPath, fileName, fileLabel, this.ji.getId(), cnx); cnx.commit(); return res; } catch (IOException e) { throw new JqmClientException(e); } finally { Helpers.closeQuietly(cnx); } }
addTextElementToParentElement(jobDefinition, "name", j.getApplicationName()); addTextElementToParentElement(jobDefinition, "queue", j.getQueue(cnx).getName()); addTextElementToParentElement(jobDefinition, "description", j.getDescription() == null ? "" : j.getDescription());
addTextElementToParentElement(jobDefinition, "name", j.getApplicationName()); addTextElementToParentElement(jobDefinition, "queue", j.getQueue(cnx).getName()); addTextElementToParentElement(jobDefinition, "description", j.getDescription() == null ? "" : j.getDescription());
@Test public void testImportThenReimportJobDefWithPrms() { // Init the default queue (don't start the engine!) Helpers.updateConfiguration(cnx); // First import XmlJobDefParser.parse("target/payloads/jqm-test-xml/xmltest.xml", cnx); cnx.commit(); List<JobDef> jd = JobDef.select(cnx, "jd_select_all"); Assert.assertEquals(2, jd.size()); JobDef fibo = JobDef.select_key(cnx, "Fibo"); Assert.assertEquals("Fibo", fibo.getApplicationName()); Assert.assertEquals("1", fibo.getParametersMap(cnx).get("p1")); // Second import - parameters are different, note 3 instead of 1 XmlJobDefParser.parse("target/payloads/jqm-test-xml/xmltest_np.xml", cnx); cnx.commit(); jd = JobDef.select(cnx, "jd_select_all"); fibo = JobDef.select_key(cnx, "Fibo"); Assert.assertEquals(2, jd.size()); Assert.assertNotNull(fibo); Assert.assertEquals("Fibo", fibo.getApplicationName()); Assert.assertEquals("3", fibo.getParametersMap(cnx).get("p1")); }
@Test public void testUpdateJobDef() { // Init the default queue (don't start the engine!) Helpers.updateConfiguration(cnx); XmlJobDefParser.parse("target/payloads/jqm-test-xml/xmltest.xml", cnx); cnx.commit(); // Sanity check List<JobDef> jd = JobDef.select(cnx, "jd_select_all"); JobDef fibo = JobDef.select_key(cnx, "Fibo"); Assert.assertEquals(2, jd.size()); Assert.assertEquals("Fibo", fibo.getApplicationName()); Assert.assertEquals("vdjvkdv", fibo.getKeyword1()); Assert.assertEquals("sgfbgg", fibo.getKeyword2()); Assert.assertEquals("jvhkdfl", fibo.getKeyword3()); // Import and therefore update the job definitions. XmlJobDefParser.parse("target/payloads/jqm-test-xml/xmltest_update.xml", cnx); cnx.commit(); jd = JobDef.select(cnx, "jd_select_all"); fibo = JobDef.select_key(cnx, "Fibo"); Assert.assertEquals(2, jd.size()); Assert.assertEquals("Fibo", fibo.getApplicationName()); Assert.assertEquals("NEWVALUE", fibo.getKeyword1()); Assert.assertEquals("", fibo.getKeyword2() == null ? "" : fibo.getKeyword2()); Assert.assertEquals(null, fibo.getKeyword3()); }
@Test public void testXmlParser() { // Init the default queue (don't start the engine!) Helpers.updateConfiguration(cnx); XmlJobDefParser.parse("target/payloads/jqm-test-xml/xmltest.xml", cnx); cnx.commit(); List<JobDef> jd = JobDef.select(cnx, "jd_select_all"); JobDef fibo = JobDef.select_key(cnx, "Fibo"); Assert.assertEquals(2, jd.size()); Assert.assertEquals("Fibo", fibo.getApplicationName()); Assert.assertEquals(true, fibo.isCanBeRestarted()); Assert.assertEquals("com.enioka.jqm.tests.App", fibo.getJavaClassName()); Assert.assertEquals(TestHelpers.qVip, fibo.getQueue()); Assert.assertEquals("ApplicationTest", fibo.getApplication()); Assert.assertEquals("TestModuleRATONLAVEUR", fibo.getModule()); Assert.assertEquals(false, fibo.isHighlander()); Assert.assertEquals("1", fibo.getParametersMap(cnx).get("p1")); Assert.assertEquals("2", fibo.getParametersMap(cnx).get("p2")); Assert.assertEquals("com.enioka.jqm.tests.App", fibo.getJavaClassName()); Assert.assertEquals("com.enioka.jqm.tests.App", fibo.getJavaClassName()); }
/** * Create an History object from a {@link JobInstance}. * */ public static void create(DbConn cnx, JobInstance ji, State finalState, Calendar endDate) { JobDef jd = ji.getJD(); Node n = ji.getNode(); Queue q = ji.getQ(); if (endDate == null) { cnx.runUpdate("history_insert", ji.getId(), jd.getApplication(), jd.getApplicationName(), ji.getAttributionDate(), ji.getEmail(), ji.getCreationDate(), ji.getExecutionDate(), jd.isHighlander(), ji.getApplication(), ji.getKeyword1(), ji.getKeyword2(), ji.getKeyword3(), ji.getModule(), jd.getKeyword1(), jd.getKeyword2(), jd.getKeyword3(), jd.getModule(), n == null ? null : n.getName(), ji.getParentId(), ji.getProgress(), q == null ? null : q.getName(), 0, ji.getSessionID(), finalState.toString(), ji.getUserName(), ji.getJdId(), n == null ? null : n.getId(), ji.getQueue(), ji.isFromSchedule(), ji.getPriority()); } else { cnx.runUpdate("history_insert_with_end_date", ji.getId(), jd.getApplication(), jd.getApplicationName(), ji.getAttributionDate(), ji.getEmail(), endDate, ji.getCreationDate(), ji.getExecutionDate(), jd.isHighlander(), ji.getApplication(), ji.getKeyword1(), ji.getKeyword2(), ji.getKeyword3(), ji.getModule(), jd.getKeyword1(), jd.getKeyword2(), jd.getKeyword3(), jd.getModule(), n.getName(), ji.getParentId(), ji.getProgress(), q.getName(), 0, ji.getSessionID(), finalState.toString(), ji.getUserName(), ji.getJdId(), ji.getNode().getId(), ji.getQueue(), ji.isFromSchedule(), ji.getPriority()); } }
/** * Create an History object from a {@link JobInstance}. * */ public static void create(DbConn cnx, JobInstance ji, State finalState, Calendar endDate) { JobDef jd = ji.getJD(); Node n = ji.getNode(); Queue q = ji.getQ(); if (endDate == null) { cnx.runUpdate("history_insert", ji.getId(), jd.getApplication(), jd.getApplicationName(), ji.getAttributionDate(), ji.getEmail(), ji.getCreationDate(), ji.getExecutionDate(), jd.isHighlander(), ji.getApplication(), ji.getKeyword1(), ji.getKeyword2(), ji.getKeyword3(), ji.getModule(), jd.getKeyword1(), jd.getKeyword2(), jd.getKeyword3(), jd.getModule(), n == null ? null : n.getName(), ji.getParentId(), ji.getProgress(), q == null ? null : q.getName(), 0, ji.getSessionID(), finalState.toString(), ji.getUserName(), ji.getJdId(), n == null ? null : n.getId(), ji.getQueue(), ji.isFromSchedule(), ji.getPriority()); } else { cnx.runUpdate("history_insert_with_end_date", ji.getId(), jd.getApplication(), jd.getApplicationName(), ji.getAttributionDate(), ji.getEmail(), endDate, ji.getCreationDate(), ji.getExecutionDate(), jd.isHighlander(), ji.getApplication(), ji.getKeyword1(), ji.getKeyword2(), ji.getKeyword3(), ji.getModule(), jd.getKeyword1(), jd.getKeyword2(), jd.getKeyword3(), jd.getModule(), n.getName(), ji.getParentId(), ji.getProgress(), q.getName(), 0, ji.getSessionID(), finalState.toString(), ji.getUserName(), ji.getJdId(), ji.getNode().getId(), ji.getQueue(), ji.isFromSchedule(), ji.getPriority()); } }