private void prepareServiceWithMultipleJobExecutions() throws Exception { jobService.listJobExecutionsForJob("job", 0, 100); EasyMock.expectLastCall().andReturn(Arrays.asList(jobExecution, earlierExecution)); jobService.listJobExecutionsForJob("job", 100, 100); EasyMock.expectLastCall().andReturn(Arrays.asList()); EasyMock.replay(jobService); }
@Test public void testGetJobExecutionCount() throws Exception { jobService.countJobExecutionsForJob("job"); EasyMock.expectLastCall().andReturn(10); EasyMock.replay(jobService); assertEquals(10, metrics.getExecutionCount()); }
@RequestMapping(value = "/jobs", method = RequestMethod.GET) public void jobs( ModelMap model, @RequestParam(defaultValue = "0") int startJob, @RequestParam(defaultValue = "20") int pageSize) { int total = jobService.countJobs(); TableUtils.addPagination(model, total, startJob, pageSize, "Job"); Collection<String> names = jobService.listJobs(startJob, pageSize); List<JobInfo> jobs = new ArrayList<JobInfo>(); for (String name : names) { int count = 0; try { count = jobService.countJobExecutionsForJob(name); } catch (NoSuchJobException e) { // shouldn't happen } boolean launchable = jobService.isLaunchable(name); boolean incrementable = jobService.isIncrementable(name); jobs.add(new JobInfo(name, count, null, launchable, incrementable)); } model.addAttribute("jobs", jobs); }
@RequestMapping(value = "/jobs/{jobName}", method = RequestMethod.POST) public String launch( ModelMap model, @ModelAttribute("jobName") String jobName, @ModelAttribute("launchRequest") LaunchRequest launchRequest, Errors errors, @RequestParam(defaultValue = "execution") String origin) { launchRequest.setJobName(jobName); String params = launchRequest.jobParameters; JobParameters jobParameters = jobParametersExtractor.fromString(params); try { JobExecution jobExecution = jobService.launch(jobName, jobParameters); model.addAttribute(new JobExecutionInfo(jobExecution, timeZone)); } catch (NoSuchJobException e) { errors.reject("no.such.job", new Object[] {jobName}, "No such job: " + jobName); } catch (JobExecutionAlreadyRunningException e) { errors.reject( "job.already.running", "A job with this name and parameters is already running."); } catch (JobRestartException e) { errors.reject("job.could.not.restart", "The job was not able to restart."); } catch (JobInstanceAlreadyCompleteException e) { errors.reject( "job.already.complete", "A job with this name and parameters already completed successfully."); } catch (JobParametersInvalidException e) { errors.reject( "job.parameters.invalid", "The job parameters are invalid according to the configuration."); } if (!"job".equals(origin)) { // if the origin is not specified we are probably not a UI client return "jobs/execution"; } else { // In the UI we show the same page again... return details(model, jobName, errors, 0, 20); } // Not a redirect because normally it is requested by an Ajax call so // there's less of a pressing need for one (the browser history won't // contain the request). }
@RequestMapping(value = "/jobs/{jobName}", method = RequestMethod.GET) public String details( ModelMap model, @ModelAttribute("jobName") String jobName, Errors errors, @RequestParam(defaultValue = "0") int startJobInstance, @RequestParam(defaultValue = "20") int pageSize) { boolean launchable = jobService.isLaunchable(jobName); try { Collection<JobInstance> result = jobService.listJobInstances(jobName, startJobInstance, pageSize); Collection<JobInstanceInfo> jobInstances = new ArrayList<JobInstanceInfo>(); model.addAttribute( "jobParameters", jobParametersExtractor.fromJobParameters(jobService.getLastJobParameters(jobName))); for (JobInstance jobInstance : result) { Collection<JobExecution> jobExecutions = jobService.getJobExecutionsForJobInstance(jobName, jobInstance.getId()); jobInstances.add(new JobInstanceInfo(jobInstance, jobExecutions, timeZone)); } model.addAttribute("jobInstances", jobInstances); int total = jobService.countJobInstances(jobName); TableUtils.addPagination(model, total, startJobInstance, pageSize, "JobInstance"); int count = jobService.countJobExecutionsForJob(jobName); model.addAttribute( "jobInfo", new JobInfo(jobName, count, launchable, jobService.isIncrementable(jobName))); } catch (NoSuchJobException e) { errors.reject( "no.such.job", new Object[] {jobName}, "There is no such job (" + HtmlUtils.htmlEscape(jobName) + ")"); } return "jobs/job"; }
private void prepareServiceWithSingleJobExecution() throws Exception { jobService.listJobExecutionsForJob("job", 0, 4); EasyMock.expectLastCall().andReturn(Arrays.asList(jobExecution)); EasyMock.replay(jobService); }