@Override int doWork() { jqmlogger.info("Will enqueue application named " + applicationName + " without parameter overloads"); jqmlogger.info("Request ID is: " + JqmClientFactory.getClient().enqueue(applicationName, "CommandLineUser")); return 0; } }
@Override int doWork() { jqmlogger.info("Status is: " + JqmClientFactory.getClient().getJob(id).getState()); return 0; } }
"Message", null, "Franquin", "ModuleMachin", "other", "other", false, cnx); List<JobDef> jds = JqmClientFactory.getClient().getJobDefinitions(); Assert.assertEquals(3, jds.size()); jds = JqmClientFactory.getClient().getJobDefinitions("AppTag"); Assert.assertEquals(1, jds.size()); JqmClientFactory.getClient().enqueueFromHistory(i); TestHelpers.waitFor(2, 5000, cnx); JqmClientFactory.getClient().removeRecurrence(idRec); Assert.assertEquals(0, MetaService.getJobDef(cnx, idJobDef1).getSchedules().size()); TestHelpers.waitFor(3, 5000, cnx); Assert.assertEquals(1, TestHelpers.getNonOkCount(cnx)); JqmClientFactory.getClient().restartCrashedJob(i); TestHelpers.waitFor(3, 5000, cnx); Assert.assertEquals(1, TestHelpers.getNonOkCount(cnx)); Assert.assertEquals(3, JqmClientFactory.getClient().getJobs().size()); Assert.assertEquals(0, JqmClientFactory.getClient().getActiveJobs().size()); Assert.assertEquals(0, JqmClientFactory.getClient().getUserActiveJobs("TestUser").size()); Assert.assertEquals(1, JqmClientFactory.getClient().getJobMessages(i).size()); JqmClientFactory.getClient().dispose();
cnx.commit(); int i1 = JqmClientFactory.getClient().enqueue("jqm-test-kill", "test"); int i2 = JqmClientFactory.getClient().enqueue("jqm-test-kill", "test"); int i3 = JqmClientFactory.getClient().enqueue("jqm-test-kill", "test"); int i4 = JqmClientFactory.getClient().enqueue("jqm-test-kill", "test"); int i5 = JqmClientFactory.getClient().enqueue("jqm-test-kill", "test"); .addStatusFilter(com.enioka.jqm.api.State.SUBMITTED).run().size()); JqmClientFactory.getClient().killJob(i1); JqmClientFactory.getClient().killJob(i2); .addStatusFilter(com.enioka.jqm.api.State.SUBMITTED).run().size()); JqmClientFactory.getClient().killJob(i3); JqmClientFactory.getClient().killJob(i4); JqmClientFactory.getClient().killJob(i5);
Assert.assertEquals(null, JqmClientFactory.getClient().getJob(i).getPriority()); JqmClientFactory.getClient().setJobPriority(i, 5); Assert.assertEquals(5, (int) JqmClientFactory.getClient().getJob(i).getPriority()); JqmClientFactory.getClient().setJobRunAfter(i2, after); Assert.assertTrue(com.enioka.jqm.model.JobInstance.select_id(cnx, i2).getNotBefore().before(Calendar.getInstance())); JqmClientFactory.getClient().setJobRunAfter(i4, after); Assert.assertTrue(com.enioka.jqm.model.JobInstance.select_id(cnx, i4).getNotBefore().before(Calendar.getInstance())); Assert.assertEquals(null, jd.getSchedules().get(0).getQueue()); JobDef jd_client = JqmClientFactory.getClient().getJobDefinition("MarsuApplication"); Assert.assertEquals(idJobDef, (int) jd_client.getId()); Assert.assertEquals(1, jd_client.getSchedules().size()); JqmClientFactory.getClient().setScheduleRecurrence(i3, "1 * * * *"); jd = MetaService.getJobDef(cnx, idJobDef); Assert.assertEquals("1 * * * *", jd.getSchedules().get(0).getCronExpression()); JqmClientFactory.getClient().setScheduleQueue(i3, TestHelpers.qSlow); jd = MetaService.getJobDef(cnx, idJobDef); Assert.assertEquals(TestHelpers.qSlow, jd.getSchedules().get(0).getQueue()); JqmClientFactory.getClient().setSchedulePriority(i3, 4); jd = MetaService.getJobDef(cnx, idJobDef); Assert.assertEquals(4, (int) jd.getSchedules().get(0).getPriority());
/** * The end of the fluent Query API. It simply executes the query and returns the results. */ public List<JobInstance> run() { return JqmClientFactory.getClient().getJobs(this); }
@Override public void killThroughClientApi() { Properties props = new Properties(); props.put("com.enioka.jqm.jdbc.contextobject", Helpers.getDb()); JqmClientFactory.getClient("uncached", props, false).killJob(this.ji.getId()); }
@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); }
@Test public void testCancelJob() 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", false, cnx); int i = JobRequest.create("MarsuApplication", "TestUser").submit(); JqmClientFactory.getClient().cancelJob(i); JobRequest.create("MarsuApplication", "TestUser").submit(); addAndStartEngine(); TestHelpers.waitFor(2, 5000, cnx); List<JobInstance> res = Query.create().addSortAsc(Sort.DATEENQUEUE).run(); Assert.assertEquals(2, res.size()); Assert.assertEquals(State.CANCELLED, res.get(0).getState()); Assert.assertEquals(State.ENDED, res.get(1).getState()); }
"Franquin", "WithoutH", "other", "other", false, cnx); int i1 = JqmClientFactory.getClient().enqueue(new JobRequest("WithH", "TestUser")); int i2 = JqmClientFactory.getClient().enqueue(new JobRequest("WithH", "TestUser")); sleep(2); int i3 = JqmClientFactory.getClient().enqueue(new JobRequest("WithoutH", "TestUser")); Assert.assertEquals(true, res.get(0).isHighlander()); JqmClientFactory.getClient().killJob(i2); JqmClientFactory.getClient().killJob(i1); JqmClientFactory.getClient().killJob(i3); TestHelpers.waitFor(2, 20000, cnx);
@Override public void waitChild(int id) { JqmClient c = getJqmClient(); Query q = Query.create().setQueryHistoryInstances(false).setQueryLiveInstances(true).setJobInstanceId(id); while (!c.getJobs(q).isEmpty()) { try { Thread.sleep(1000); handleInstructions(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } }
@Override public void killThroughClientApi() { Properties props = new Properties(); props.put("com.enioka.jqm.jdbc.contextobject", Helpers.getDb()); JqmClientFactory.getClient("uncached", props, false).killJob(this.ji.getId()); }
private static void enqueue(String applicationName) { jqmlogger.info("Will enqueue application named " + applicationName + " without parameter overloads"); jqmlogger.info("Request ID is: " + JqmClientFactory.getClient().enqueue(applicationName, "CommandLineUser")); }
"Franquin", "ModuleMachin", "other", "other", false, cnx); JqmClientFactory.getClient().enqueue("jqm-test-kill", "test"); JqmClientFactory.getClient().enqueue("jqm-test-kill", "test"); JqmClientFactory.getClient().enqueue("jqm-test-kill", "test"); JqmClientFactory.getClient().enqueue("jqm-test-kill", "test"); 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());
private static void getStatus(int id) { jqmlogger.info("Status is: " + JqmClientFactory.getClient().getJob(id).getState()); }
@Override public void waitChild(int id) { JqmClient c = getJqmClient(); Query q = Query.create().setQueryHistoryInstances(false).setQueryLiveInstances(true).setJobInstanceId(id); while (!c.getJobs(q).isEmpty()) { try { Thread.sleep(1000); handleInstructions(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } }
JqmClientFactory.getClient().killJob(jobId);
@Override public void resetClient(String name) { if (name != null) { synchronized (clients) { if (clients.containsKey(name)) { jqmlogger.trace("resetting client " + name); clients.get(name).dispose(); clients.remove(name); } } } else { synchronized (clients) { if (defaultClient != null) { jqmlogger.trace("resetting default client"); defaultClient.dispose(); defaultClient = null; } } } }
/** * Shortcut to submit the request to the JQM cluster. Equivalent to doing<br> * <code>JqmClientFactory.getClient().enqueue(this)</code><br> * See {@link JqmClient#enqueue(JobRequest)} for details on exceptions. * * @return the ID of the job instance. */ public Integer submit() { return JqmClientFactory.getClient().enqueue(this); }