protected void displayAllHistoryTable() { java.text.SimpleDateFormat format = new java.text.SimpleDateFormat("HH:mm:ss.SSS"); jqmlogger.debug("=========================================================================================="); for (JobInstance h : Query.create().run()) { jqmlogger.debug("JobInstance Id: " + h.getId() + " | " + h.getState() + " | JD: " + h.getApplicationName() + " | " + h.getQueueName() + " | enqueue: " + format.format(h.getEnqueueDate().getTime()) + " | exec: " + (h.getBeganRunningDate() != null ? format.format(h.getBeganRunningDate().getTime()) : null) + " | end: " + (h.getEndDate() != null ? format.format(h.getEndDate().getTime()) : null)); } jqmlogger.debug("=========================================================================================="); } }
@Override public List<String> getJobMessages(int idJob) { return getJob(idJob).getMessages(); }
@Override public int enqueueFromHistory(int jobIdToCopy) { JobInstance h = getJob(jobIdToCopy); JobRequest jd = new JobRequest(); jd.setApplication(h.getApplication()); jd.setApplicationName(h.getApplicationName()); jd.setEmail(h.getEmail()); jd.setKeyword1(h.getKeyword1()); jd.setKeyword2(h.getKeyword2()); jd.setKeyword3(h.getKeyword3()); jd.setModule(h.getModule()); jd.setParentID(h.getParent()); jd.setSessionID(h.getSessionID()); jd.setUser(h.getUser()); for (Map.Entry<String, String> p : h.getParameters().entrySet()) { jd.addParameter(p.getKey(), p.getValue()); } return enqueue(jd); }
@Test public void testHistoryFields() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other2", true, cnx); int i = JobRequest.create("MarsuApplication", "TestUser").setSessionID("session42").setKeyword1("k1").setKeyword2("k2").submit(); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); Assert.assertEquals(1, TestHelpers.getOkCount(cnx)); JobInstance h = JqmClientFactory.getClient().getJob(i); SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm"); jqmlogger.debug("enqueueDate: " + df.format(h.getEnqueueDate().getTime())); jqmlogger.debug("ExecutionDate: " + df.format(h.getBeganRunningDate().getTime())); jqmlogger.debug("EndDate: " + df.format(h.getEndDate().getTime())); Assert.assertTrue(h.getEnqueueDate() != null); Assert.assertTrue(h.getUser() != null); Assert.assertTrue(h.getEndDate() != null); Assert.assertTrue(h.getBeganRunningDate() != null); Assert.assertTrue(h.getSessionID() != null); Assert.assertEquals("session42", h.getSessionID()); JobInstance ji = Query.create().setApplicationName("MarsuApplication").run().get(0); Assert.assertEquals("ModuleMachin", ji.getDefinitionKeyword1()); Assert.assertEquals("other", ji.getDefinitionKeyword2()); Assert.assertEquals("other2", ji.getDefinitionKeyword3()); Assert.assertEquals("k1", ji.getKeyword1()); Assert.assertEquals("k2", ji.getKeyword2()); Assert.assertEquals(null, ji.getKeyword3()); }
@Test public void testTags() throws Exception { CreationTools.createJobDef(null, true, "pyl.EngineApiTags", null, "jqm-tests/jqm-test-pyl/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "keyword1", null, "keyword3", false, cnx); JobRequest.create("MarsuApplication", "TestUser").setKeyword1("Houba").setKeyword3("Meuh").submit(); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); Assert.assertEquals(1, TestHelpers.getOkCount(cnx)); List<JobInstance> res = Query.create().run(); Assert.assertEquals(1, res.size()); JobInstance h = res.get(0); Assert.assertEquals("Houba", h.getKeyword1()); Assert.assertEquals(null, h.getKeyword2()); Assert.assertEquals("Meuh", h.getKeyword3()); Assert.assertEquals("keyword1", h.getDefinitionKeyword1()); Assert.assertEquals(null, h.getDefinitionKeyword2()); Assert.assertEquals("keyword3", h.getDefinitionKeyword3()); }
res.put(tmp.getId(), tmp); ids.add(currentList); currentList.add(ji.getId()); i++; while (run.next()) res.get(run.getInt(2)).getParameters().put(run.getString(3), run.getString(4)); while (msg.next()) res.get(msg.getInt(2)).getMessages().add(msg.getString(3));
@Test public void testEnqueueSynchronously() throws Exception { JqmSimpleTest.create(cnx, "pyl.StressFiboSync").addRuntimeParameter("p1", "34").addRuntimeParameter("p2", "55").expectOk(4) .run(this); List<JobInstance> res = Query.create().addSortAsc(Sort.ID).run(); JobInstance h1, h2 = null; for (JobInstance h : res) { h1 = h2; h2 = h; if (h1 == null) { continue; } Assert.assertEquals(h2.getParent(), h1.getId()); Assert.assertTrue(h2.getEndDate().compareTo(h1.getEndDate()) <= 0); Assert.assertTrue(h2.getEndDate().compareTo(h1.getBeganRunningDate()) > 0); } }
@Override public int getJobProgress(int idJob) { return getJob(idJob).getProgress(); }
@Test public void testMainTypeInjectWithFullApi() throws Exception { // Here, engine API + full API mix. int i = JqmSimpleTest.create(cnx, "pyl.EngineApiInject", "jqm-test-pyl-hibapi").setSessionId("123X").expectOk(3).run(this); Assert.assertEquals(1, JqmClientFactory.getClient().getJob(i).getMessages().size()); // 1 message per run created by payload Assert.assertEquals(100, (int) JqmClientFactory.getClient().getJob(i).getProgress()); } }
@Test public void testHighlanderEngineRunning() throws Exception { // This test launches an infinite loop as Highlander, checks if no other job can launch. Job is killed at the end - which allows a // second one to run, which also has to be killed. CreationTools.createJobDef(null, true, "pyl.KillMe", null, "jqm-tests/jqm-test-pyl/target/test.jar", TestHelpers.qVip, 42, "kill", null, "Franquin", "ModuleMachin", "other", "other", true, cnx); addAndStartEngine(); int firstJob = JobRequest.create("kill", "TestUser").submit(); for (int i = 0; i < 100; i++) { JobRequest.create("kill", "TestUser").submit(); } Thread.sleep(3000); Calendar killTime1 = Calendar.getInstance(); JqmClientFactory.getClient().killJob(firstJob); Thread.sleep(3000); JqmClientFactory.getClient().killJob(JqmClientFactory.getClient().getUserActiveJobs("TestUser").get(0).getId()); TestHelpers.waitFor(2, 10000, cnx); List<com.enioka.jqm.api.JobInstance> res = Query.create().addSortAsc(Sort.ID).run(); Assert.assertEquals(2, res.size()); Assert.assertEquals(State.CRASHED, res.get(0).getState()); Assert.assertEquals(State.CRASHED, res.get(1).getState()); Assert.assertTrue(killTime1.compareTo(res.get(1).getBeganRunningDate()) <= 0); }
@Override public int enqueue(JobRequest jd) { try { return target.path("ji").request().post(Entity.entity(jd, MediaType.APPLICATION_XML), JobInstance.class).getId(); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
Assert.assertEquals(com.enioka.jqm.api.State.ENDED, ji.getState()); Assert.assertEquals(2, ji.getParameters().size()); Assert.assertEquals("newvalue2", ji.getParameters().get("arg2")); Assert.assertEquals("overridevalue", ji.getParameters().get("arg"));
/** * Version of {@link JqmClient#getDeliverableContent(Deliverable)} which does not require the web service APIs to be enabled to work. * Also, returned files do not self-destruct on stream close.<br> * See the javadoc of the original method for details. * * @throws FileNotFoundException */ public InputStream getDeliverableContent(Deliverable file) throws FileNotFoundException { List<com.enioka.jqm.model.Deliverable> dd = com.enioka.jqm.model.Deliverable.select(cnx, "deliverable_select_by_id", file.getId()); if (dd.isEmpty()) { throw new JqmInvalidRequestException("no deliverable with this ID"); } com.enioka.jqm.model.Deliverable d = dd.get(0); JobInstance ji = Query.create().setJobInstanceId(d.getJobId()).run().get(0); String nodeName = ji.getNodeName(); Node n = nodes.get(nodeName); return new FileInputStream(FilenameUtils.concat(n.getDlRepo(), file.getFilePath())); } }
@Test public void testRestartJob() throws Exception { CreationTools.createJobDef(null, true, "App", null, "jqm-tests/jqm-test-datetimemaven/target/test.jar", TestHelpers.qVip, 42, "MarsuApplication", null, "Franquin", "ModuleMachin", "other", "other", true, cnx); int i = JobRequest.create("MarsuApplication", "TestUser").submit(); addAndStartEngine(); TestHelpers.waitFor(1, 10000, cnx); JqmClientFactory.getClient().enqueueFromHistory(i); TestHelpers.waitFor(2, 10000, cnx); Assert.assertEquals(2, TestHelpers.getOkCount(cnx)); Assert.assertEquals(0, TestHelpers.getNonOkCount(cnx)); List<JobInstance> res = Query.create().addSortAsc(Sort.DATEENQUEUE).run(); Assert.assertEquals(2, res.size()); Assert.assertEquals("MarsuApplication", res.get(0).getApplicationName()); Assert.assertEquals("MarsuApplication", res.get(1).getApplicationName()); }
@Override public int getJobProgress(int idJob) { try { return getJob(idJob).getProgress(); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
public int restartCrashedJob(int idJob) { try { return target.path("ji/crashed/" + idJob).request().delete(JobInstance.class).getId(); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
/** * Version of {@link JqmClient#getDeliverableContent(Deliverable)} which does not require the web service APIs to be enabled to work. * Also, returned files do not self-destruct on stream close.<br> * See the javadoc of the original method for details. * * @throws FileNotFoundException */ public InputStream getDeliverableContent(Deliverable file) throws FileNotFoundException { List<com.enioka.jqm.model.Deliverable> dd = com.enioka.jqm.model.Deliverable.select(cnx, "deliverable_select_by_id", file.getId()); if (dd.isEmpty()) { throw new JqmInvalidRequestException("no deliverable with this ID"); } com.enioka.jqm.model.Deliverable d = dd.get(0); JobInstance ji = Query.create().setJobInstanceId(d.getJobId()).run().get(0); String nodeName = ji.getNodeName(); Node n = nodes.get(nodeName); return new FileInputStream(FilenameUtils.concat(n.getDlRepo(), file.getFilePath())); } }
@Test public void testSendProgress() throws Exception { JqmSimpleTest.create(cnx, "pyl.EngineApiProgress").addWaitMargin(10000).run(this); List<JobInstance> res = Query.create().run(); Assert.assertEquals((Integer) 50, res.get(0).getProgress()); }
@Override public List<String> getJobMessages(int idJob) { try { return getJob(idJob).getMessages(); } catch (BadRequestException e) { throw new JqmInvalidRequestException(e.getResponse().readEntity(String.class), e); } catch (Exception e) { throw new JqmClientException(e); } }
JqmClientFactory.getClient().killJob(running.get(0).getId()); TestHelpers.waitFor(1, 10000, cnx); TestHelpers.waitForRunning(3, 10000, cnx); JqmClientFactory.getClient().killJob(running.get(0).getId()); JqmClientFactory.getClient().killJob(running.get(1).getId()); JqmClientFactory.getClient().killJob(running.get(2).getId());