@Override public Job getJob(String name) throws NoSuchJobException { JobFactory factory = map.get(name); if (factory == null) { throw new NoSuchJobException("No job configuration with the name [" + name + "] was registered"); } else { return factory.createJob(); } }
@Override public int getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { int count = 0; for (Map.Entry<String, JobInstance> instanceEntry : jobInstances.entrySet()) { String key = instanceEntry.getKey(); String curJobName = key.substring(0, key.lastIndexOf("|")); if(curJobName.equals(jobName)) { count++; } } if(count == 0) { throw new NoSuchJobException("No job instances for job name " + jobName + " were found"); } else { return count; } }
@Override public Exception getException(String msg) throws Exception { return new NoSuchJobException(msg); }
@Override public Exception getException(String msg, Throwable t) throws Exception { return new NoSuchJobException(msg, t); }
@Override public Step getStep(String jobName, String stepName) throws NoSuchJobException { Assert.notNull(jobName, "The job name cannot be null."); Assert.notNull(stepName, "The step name cannot be null."); if (!map.containsKey(jobName)) { throw new NoSuchJobException("No job configuration with the name [" + jobName + "] was registered"); } else { final Map<String, Step> jobSteps = map.get(jobName); if (jobSteps.containsKey(stepName)) { return jobSteps.get(stepName); } else { throw new NoSuchStepException("The step called [" + stepName + "] does not exist in the job [" + jobName + "]"); } } }
@Override public Set<Long> getRunningExecutions(String jobName) throws NoSuchJobException { Set<Long> set = new LinkedHashSet<>(); for (JobExecution jobExecution : jobExplorer.findRunningJobExecutions(jobName)) { set.add(jobExecution.getId()); } if (set.isEmpty() && !jobRegistry.getJobNames().contains(jobName)) { throw new NoSuchJobException("No such job (either in registry or in historical data): " + jobName); } return set; }
@Override public List<Long> getJobInstances(String jobName, int start, int count) throws NoSuchJobException { List<Long> list = new ArrayList<>(); List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, start, count); for (JobInstance jobInstance : jobInstances) { list.add(jobInstance.getId()); } if (list.isEmpty() && !jobRegistry.getJobNames().contains(jobName)) { throw new NoSuchJobException("No such job (either in registry or in historical data): " + jobName); } return list; }
@Override public Job getJob(String name) throws NoSuchJobException { if (name.equals("foo")) { return job; } throw new NoSuchJobException("foo"); }
@Override public int getJobInstanceCount(@Nullable String jobName) throws NoSuchJobException { try { return getJdbcTemplate().queryForObject( getQuery(COUNT_JOBS_WITH_NAME), Integer.class, jobName); } catch (EmptyResultDataAccessException e) { throw new NoSuchJobException("No job instances were found for job name " + jobName); } }
@Override public int getJobInstanceCount(String jobName) throws NoSuchJobException { int count = 0; for (JobInstance jobInstance : jobInstances) { if(jobInstance.getJobName().equals(jobName)) { count++; } } if(count == 0) { throw new NoSuchJobException("Unable to find job instances for " + jobName); } else { return count; } }
@Test(expected=NoSuchJobException.class) public void testGetJobInstanceCountNoSuchJob() throws Exception { when(jobExplorer.getJobInstanceCount("myJob")).thenThrow(new org.springframework.batch.core.launch.NoSuchJobException("expected")); jsrJobOperator.getJobInstanceCount("myJob"); }
@Test(expected=NoSuchJobException.class) public void testGetJobInstanceCountException() throws Exception { when(jobInstanceDao.getJobInstanceCount("throwException")).thenThrow(new NoSuchJobException("expected")); jobExplorer.getJobInstanceCount("throwException"); } }
@Test public void testStopTaskletWhenJobNotRegistered() throws Exception { JobInstance jobInstance = new JobInstance(123L, job.getName()); JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters, null); StoppableTasklet tasklet = mock(StoppableTasklet.class); JobRegistry jobRegistry = mock(JobRegistry.class); TaskletStep step = mock(TaskletStep.class); when(step.getTasklet()).thenReturn(tasklet); when(jobRegistry.getJob(job.getName())).thenThrow(new NoSuchJobException("Unable to find job")); when(jobExplorer.getJobExecution(111L)).thenReturn(jobExecution); jobOperator.setJobRegistry(jobRegistry); jobOperator.stop(111L); assertEquals(BatchStatus.STOPPING, jobExecution.getStatus()); verify(tasklet, never()).stop(); }
return job; throw new NoSuchJobException("foo");
public Job getJob(String name) throws NoSuchJobException { Job job = (Job) applicationContext.getBean(name); if (job == null) { throw new NoSuchJobException("IntactContext is not aware of this job: "+name); } return job; }
private List<Long> getJobInstances(String jobName, int start, int count) throws NoSuchJobException { List<Long> list = new ArrayList<Long>(); for (JobInstance jobInstance : jobExplorer.getJobInstances(jobName, start, count)) { list.add(jobInstance.getId()); } if (list.isEmpty() && !jobRegistry.getJobNames().contains(jobName)) { throw new NoSuchJobException("No such job (either in registry or in historical data): " + jobName); } return list; }
public Set<Long> getRunningExecutions(String jobName) throws NoSuchJobException { Set<Long> set = new LinkedHashSet<Long>(); for (JobExecution jobExecution : jobExplorer.findRunningJobExecutions(jobName)) { set.add(jobExecution.getId()); } if (set.isEmpty() && !jobRegistry.getJobNames().contains(jobName)) { throw new NoSuchJobException("No such job (either in registry or in historical data): " + jobName); } return set; }
@Override public Set<Long> getRunningExecutions(String jobName) throws NoSuchJobException { Set<Long> set = new LinkedHashSet<Long>(); for (JobExecution jobExecution : jobExplorer.findRunningJobExecutions(jobName)) { set.add(jobExecution.getId()); } if (set.isEmpty() && !jobRegistry.getJobNames().contains(jobName)) { throw new NoSuchJobException("No such job (either in registry or in historical data): " + jobName); } return set; }
private Set<Long> getRunningExecutions(String jobName) throws NoSuchJobException { Set<Long> set = new LinkedHashSet<Long>(); for (JobExecution jobExecution : jobExplorer.findRunningJobExecutions(jobName)) { set.add(jobExecution.getId()); } if (set.isEmpty() && !jobRegistry.getJobNames().contains(jobName)) { throw new NoSuchJobException("No such job (either in registry or in historical data): " + jobName); } return set; }
@Override public List<Long> getJobInstances(String jobName, int start, int count) throws NoSuchJobException { List<Long> list = new ArrayList<Long>(); List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, start, count); for (JobInstance jobInstance : jobInstances) { list.add(jobInstance.getId()); } if (list.isEmpty() && !jobRegistry.getJobNames().contains(jobName)) { throw new NoSuchJobException("No such job (either in registry or in historical data): " + jobName); } return list; }