@Test public void testLaunchBadJob() throws Exception { assertEquals(0, errors.size()); assertTrue(isConnected()); try { launcher.start("foo", "time=" + (new Date().getTime())); fail("Expected RuntimeException"); } catch (RuntimeException e) { String message = e.getMessage(); assertTrue("Wrong message: " + message, message.contains("NoSuchJobException")); } }
@Test public void testPauseJob() throws Exception { final int SLEEP_INTERVAL = 600; assertTrue(isConnected()); assertTrue(launcher.getJobNames().contains("loopJob")); long executionId = launcher.start("loopJob", ""); // sleep long enough to avoid race conditions (serializable tx isolation // doesn't work with HSQL) Thread.sleep(SLEEP_INTERVAL); launcher.stop(executionId); Thread.sleep(SLEEP_INTERVAL); logger.debug(launcher.getSummary(executionId)); long resumedId = launcher.restart(executionId); assertNotSame("Picked up the same execution after pause and resume", executionId, resumedId); Thread.sleep(SLEEP_INTERVAL); launcher.stop(resumedId); Thread.sleep(SLEEP_INTERVAL); logger.debug(launcher.getSummary(resumedId)); long resumeId2 = launcher.restart(resumedId); assertNotSame("Picked up the same execution after pause and resume", executionId, resumeId2); Thread.sleep(SLEEP_INTERVAL); launcher.stop(resumeId2); }
@Test public void testStartStopResumeJob() throws Exception { String params = new JobParametersBuilder().addLong("jobOperatorTestParam", 7L).toJobParameters().toString(); long executionId = operator.start(job.getName(), params); assertEquals(params, operator.getParameters(executionId)); stopAndCheckStatus(executionId); long resumedExecutionId = operator.restart(executionId); assertEquals(params, operator.getParameters(resumedExecutionId)); stopAndCheckStatus(resumedExecutionId); List<Long> instances = operator.getJobInstances(job.getName(), 0, 1); assertEquals(1, instances.size()); long instanceId = instances.get(0); List<Long> executions = operator.getExecutions(instanceId); assertEquals(2, executions.size()); // latest execution is the first in the returned list assertEquals(resumedExecutionId, executions.get(0).longValue()); assertEquals(executionId, executions.get(1).longValue()); }
/** * * @param jobName * @param parameters the parameters of type key-value separated by comma * @return * @throws JobExecutionAlreadyRunningException * @throws JobRestartException * @throws JobInstanceAlreadyCompleteException */ public String startJobWithParameters(String jobName, String parameters) throws JobParametersInvalidException, JobInstanceAlreadyExistsException, NoSuchJobException { String jobId = jobName+"_"+System.currentTimeMillis(); if (log.isInfoEnabled()) log.info("Starting job: "+jobName+", job id: "+jobId); jobOperator.start(jobName, "MIJobId=" + jobId+(parameters != null ? ","+parameters:"")); return jobId; }
@RequestMapping(value = "/", method = RequestMethod.POST) @ResponseStatus(HttpStatus.ACCEPTED) public long launch(@RequestParam("name") String name) throws Exception { return this.jobOperator.start("job", String.format("name=%s", name)); }
@RequestMapping(value = "/", method = RequestMethod.POST) @ResponseStatus(HttpStatus.ACCEPTED) public void launch(@RequestParam("name") String name) throws Exception { // JobParameters jobParameters = // new JobParametersBuilder() // .addString("name", name) // .toJobParameters(); // this.jobLauncher.run(job, jobParameters); this.jobOperator.start("job", String.format("name=%s", name)); } }
/** * This method will start a job having a specific name and no job parameters. It will return the generated job id of the job that have been started * @param jobName * @throws JobInstanceAlreadyCompleteException * @throws JobParametersInvalidException * @throws JobRestartException * @throws JobExecutionAlreadyRunningException */ public String startJob(String jobName) throws JobInstanceAlreadyCompleteException, JobParametersInvalidException, JobRestartException, JobExecutionAlreadyRunningException, JobInstanceAlreadyExistsException, NoSuchJobException { String jobId = jobName+"_"+System.currentTimeMillis(); if (log.isInfoEnabled()) log.info("Starting job: "+jobName+", job id: "+jobId); jobOperator.start(jobName, "MIJobId=" + jobId); return jobId; }