@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); } }
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); } }
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("=========================================================================================="); } }
@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); }
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());
@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); } }