org.springframework.batch.core.launch.NoSuchJobException Java Examples

The following examples show how to use org.springframework.batch.core.launch.NoSuchJobException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResponseExceptionHandler.java    From spring-batch-rest with Apache License 2.0 6 votes vote down vote up
@ExceptionHandler(BatchRuntimeException.class)
protected ResponseEntity<Object> handleBatchRuntimeException(BatchRuntimeException e, WebRequest request) {
    log.error("Request {} failed with {}", request, e);
    Throwable cause = e.getCause();
    HttpStatus status = HttpStatus.INTERNAL_SERVER_ERROR;
    if (cause instanceof DuplicateJobException
            || cause instanceof JobExecutionAlreadyRunningException
            || cause instanceof JobInstanceAlreadyCompleteException)
        status = HttpStatus.CONFLICT;
    else if (cause instanceof JobParametersInvalidException
        || cause instanceof JobParametersNotFoundException)
        status = HttpStatus.BAD_REQUEST;
    else if (cause instanceof NoSuchJobException
        || cause instanceof NoSuchJobExecutionException
        || cause instanceof NoSuchJobInstanceException)
        status = HttpStatus.NOT_FOUND;

    ApiError apiError = new ApiError(status.toString(), cause.getMessage(), cause.getClass().getSimpleName(), e.getMessage());
    return handleExceptionInternal(e, apiError, new HttpHeaders(), status, request);
}
 
Example #2
Source File: PersonJobTest.java    From spring-batch-rest with Apache License 2.0 6 votes vote down vote up
@Test
public void canStartJob() throws NoSuchJobException {
    Job job = jobRegistry.getJob(PersonJobConfig.JOB_NAME);
    assertThat(job).isNotNull();

    cacheItemWriter.clear();
    startJob(Optional.empty(), Optional.empty());
    assertThat(cacheItemWriter.getItems()).hasSize(5);
    cacheItemWriter.getItems().forEach(p -> assertThat(p.getFirstName()).isEqualTo(p.getFirstName().toLowerCase()));

    cacheItemWriter.clear();
    startJob(Optional.of("D"), Optional.of(true));
    assertThat(cacheItemWriter.getItems()).hasSize(2);
    cacheItemWriter.getItems().forEach(p -> assertThat(p.getFirstName()).isEqualTo(p.getFirstName().toUpperCase()));

    cacheItemWriter.clear();
    startJob(Optional.of("To"), Optional.of(false));
    assertThat(cacheItemWriter.getItems()).hasSize(3);
    cacheItemWriter.getItems().forEach(p -> assertThat(p.getFirstName()).isEqualTo(p.getFirstName().toLowerCase()));
}
 
Example #3
Source File: MapLightminJobExecutionDao.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@Override
public List<JobExecution> getJobExecutions(final String jobName, final int start, final int count) {
    final List<JobExecution> jobExecutions = new LinkedList<>();

    int jobInstanceCount;
    try {
        jobInstanceCount = this.jobExplorer.getJobInstanceCount(jobName);
    } catch (final NoSuchJobException e) {
        jobInstanceCount = 0;
    }
    final List<JobInstance> jobInstances = this.jobExplorer.getJobInstances(jobName, 0, jobInstanceCount);
    for (final JobInstance jobInstance : jobInstances) {
        final List<JobExecution> jobExecutionsByInstance = this.jobExplorer.getJobExecutions(jobInstance);
        jobExecutions.addAll(jobExecutionsByInstance);
    }
    this.sortDescending(jobExecutions);
    return this.subset(jobExecutions, start, count);
}
 
Example #4
Source File: RestControllerAdvice.java    From spring-cloud-dashboard with Apache License 2.0 6 votes vote down vote up
/**
 * Log the exception message at warn level and stack trace as trace level.
 * Return response status HttpStatus.NOT_FOUND
 */
@ExceptionHandler({NoSuchAppRegistrationException.class,
		NoSuchTaskDefinitionException.class,
		NoSuchTaskExecutionException.class,
		NoSuchJobExecutionException.class,
		NoSuchJobInstanceException.class,
		NoSuchJobException.class,
		NoSuchStepExecutionException.class,
		MetricsMvcEndpoint.NoSuchMetricException.class})
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody
public VndErrors onNotFoundException(Exception e) {
	String logref = logWarnLevelExceptionMessage(e);
	if (logger.isTraceEnabled()) {
		logTraceLevelStrackTrace(e);
	}
	String msg = getExceptionMessage(e);
	return new VndErrors(logref, msg);
}
 
Example #5
Source File: RestControllerAdvice.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * Log the exception message at warn level and stack trace as trace level. Return
 * response status HttpStatus.NOT_FOUND
 *
 * @param e one of the exceptions, {@link NoSuchAuditRecordException},
 * {@link NoSuchStreamDefinitionException},
 * {@link NoSuchAppRegistrationException}, {@link NoSuchTaskDefinitionException},
 * {@link NoSuchTaskExecutionException}, {@link NoSuchJobExecutionException},
 * {@link NoSuchJobInstanceException}, {@link NoSuchJobException},
 * {@link NoSuchStepExecutionException},
 * {@link NoSuchAppException}, or
 * {@link NoSuchAppInstanceException}
 * @return the error response in JSON format with media type
 * application/vnd.error+json
 */
@ExceptionHandler({ NoSuchAuditRecordException.class,
		NoSuchStreamDefinitionException.class, NoSuchAppRegistrationException.class,
		NoSuchTaskDefinitionException.class, NoSuchTaskExecutionException.class, NoSuchJobExecutionException.class,
		NoSuchJobInstanceException.class, NoSuchJobException.class, NoSuchStepExecutionException.class,
		NoSuchTaskBatchException.class, NoSuchAppException.class, NoSuchAppInstanceException.class,
		NoSuchScheduleException.class })
@ResponseStatus(HttpStatus.NOT_FOUND)
@ResponseBody
public VndErrors onNotFoundException(Exception e) {
	String logref = logWarnLevelExceptionMessage(e);
	if (logger.isTraceEnabled()) {
		logTraceLevelStrackTrace(e);
	}
	String msg = getExceptionMessage(e);
	return new VndErrors(logref, msg);
}
 
Example #6
Source File: DefaultListenerServiceTest.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegisterListenerForJob() throws NoSuchJobException {
    final JobListenerConfiguration jobListenerConfiguration = DomainTestHelper.createJobListenerConfiguration
            ("src/test/", "*.txt", JobListenerType.LOCAL_FOLDER_LISTENER);
    jobListenerConfiguration.setBeanName("testBean");
    final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobListenerConfiguration);
    this.listenerService.registerListenerForJob(jobConfiguration);
    verify(this.jobRegistry, times(1)).getJob(anyString());
    verify(this.beanRegistrar, times(1)).registerBean(
            eq(FolderListener.class),
            eq("testBean"),
            anySet(),
            eq(null),
            eq(null),
            eq(null),
            eq(null));
}
 
Example #7
Source File: JobExecutionController.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve all task job executions with the task name specified
 *
 * @param jobName name of the job. SQL server specific wildcards are enabled (eg.: myJob%,
 *     m_Job, ...)
 * @param pageable page-able collection of {@code TaskJobExecution}s.
 * @param assembler for the {@link TaskJobExecution}s
 * @return list task/job executions with the specified jobName.
 * @throws NoSuchJobException if the job with the given name does not exist.
 */
@RequestMapping(value = "", method = RequestMethod.GET, produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public PagedModel<JobExecutionResource> retrieveJobsByParameters(
		@RequestParam(value = "name", required = false) String jobName,
		@RequestParam(value = "status", required = false) BatchStatus status,
		Pageable pageable, PagedResourcesAssembler<TaskJobExecution> assembler) throws NoSuchJobException, NoSuchJobExecutionException {
	List<TaskJobExecution> jobExecutions;
	Page<TaskJobExecution> page;

	if (jobName == null && status == null) {
		jobExecutions = taskJobService.listJobExecutions(pageable);
		page = new PageImpl<>(jobExecutions, pageable, taskJobService.countJobExecutions());
	} else {
		jobExecutions = taskJobService.listJobExecutionsForJob(pageable, jobName, status);
		page = new PageImpl<>(jobExecutions, pageable,
				taskJobService.countJobExecutionsForJob(jobName, status));
	}

	return assembler.toModel(page, jobAssembler);
}
 
Example #8
Source File: SimpleJobService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private int countJobExecutions(String jobName, BatchStatus status) throws NoSuchJobException {
	if (StringUtils.isEmpty(jobName)) {
		if (status != null) {
			return jobExecutionDao.countJobExecutions(status);
		}
	}
	else {
		if (status != null) {
			return jobExecutionDao.countJobExecutions(jobName, status);
		}
	}

	checkJobExists(jobName);
	return jobExecutionDao.countJobExecutions(jobName);
}
 
Example #9
Source File: QuartzController.java    From spring-batch-quartz-admin with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Displays the details page for each of the quartz jobs
 * </p>
 *
 * @param model
 * @param quartzJobName
 * @param errors
 * @param startJobInstance
 * @param pageSize
 * @return String
 */
@RequestMapping(value = "/quartz/{quartzJobName}", method = RequestMethod.GET)
public String quartzJobDetails(ModelMap model, @ModelAttribute("quartzJobName") String quartzJobName, Errors errors, @RequestParam(defaultValue = "0") int startJobInstance,
                               @RequestParam(defaultValue = "20") int pageSize) {

    boolean launchable = jobService.isLaunchable(quartzJobName);

    try {

        Collection<JobInstance> result = jobService.listJobInstances(quartzJobName, startJobInstance, pageSize);
        Collection<JobInstanceInfo> jobInstances = new ArrayList<JobInstanceInfo>();
        model.addAttribute("quartzJobParameters", jobParametersExtractor.fromJobParameters(jobService.getLastJobParameters(quartzJobName)));

        for (JobInstance jobInstance : result) {
            Collection<JobExecution> jobExecutions = jobService.getJobExecutionsForJobInstance(quartzJobName, jobInstance.getId());
            jobInstances.add(new JobInstanceInfo(jobInstance, jobExecutions, timeZone));
        }

        model.addAttribute("quartzJobInstances", jobInstances);
        int total = jobService.countJobInstances(quartzJobName);
        TableUtils.addPagination(model, total, startJobInstance, pageSize, "QuartzJobInstance");
        int count = jobService.countJobExecutionsForJob(quartzJobName);
        model.addAttribute("quartzJobInfo", new JobInfo(quartzJobName, count, launchable, jobService.isIncrementable(quartzJobName)));
        model.addAttribute("jobMessageStatus", quartzService.getScheduledJobStatus(quartzJobName));
        model.addAttribute("jobMessageDescription", quartzService.getScheduledJobDescription(quartzJobName));

    } catch (NoSuchJobException e) {
        errors.reject("no.such.job", new Object[]{quartzJobName}, "There is no such job (" + HtmlUtils.htmlEscape(quartzJobName) + ")");
    }

    return "quartz/job";
}
 
Example #10
Source File: SimpleJobService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<JobExecution> getJobExecutionsForJobInstance(String name, Long jobInstanceId)
		throws NoSuchJobException {
	checkJobExists(name);
	List<JobExecution> jobExecutions = jobExecutionDao.findJobExecutions(jobInstanceDao
			.getJobInstance(jobInstanceId));
	for (JobExecution jobExecution : jobExecutions) {
		stepExecutionDao.addStepExecutions(jobExecution);
	}
	return jobExecutions;
}
 
Example #11
Source File: SimpleJobService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<JobExecutionWithStepCount> listJobExecutionsForJobWithStepCount(String jobName, int start,
		int count)
		throws NoSuchJobException {
	checkJobExists(jobName);
	return jobExecutionDao.getJobExecutionsWithStepCount(jobName, start, count);
}
 
Example #12
Source File: SimpleJobService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<String> getStepNamesForJob(String jobName) throws NoSuchJobException {
	Collection<String> stepNames = new LinkedHashSet<>();
	for (JobExecution jobExecution : listJobExecutionsForJob(jobName, null, 0, 100)) {
		for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
			stepNames.add(stepExecution.getStepName());
		}
	}
	return Collections.unmodifiableList(new ArrayList<>(stepNames));
}
 
Example #13
Source File: SimpleJobService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
private void checkJobExists(String jobName) throws NoSuchJobException {
	if (getJsrJobNames().stream().anyMatch(e -> e.contains(jobName)) ||
			jobInstanceDao.countJobInstances(jobName) > 0) {
		return;
	}
	throw new NoSuchJobException("No Job with that name either current or historic: [" + jobName + "]");
}
 
Example #14
Source File: DefaultJobService.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Override
public int getJobInstanceCount(final String jobName) {
    int jobInstanceCount = 0;
    try {
        jobInstanceCount = this.jobExplorer.getJobInstanceCount(jobName);
    } catch (final NoSuchJobException e) {
        log.info(e.getMessage(), e);
    }
    return jobInstanceCount;
}
 
Example #15
Source File: DefaultJobService.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Override
public Job getJobByName(final String jobName) {
    Job job;
    try {
        job = this.jobRegistry.getJob(jobName);
    } catch (final NoSuchJobException e) {
        log.info("Could not find job with jobName: " + jobName);
        job = null;
    }
    return job;
}
 
Example #16
Source File: DefaultJobServiceTest.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Test
public void getJobInstanceCountTest() throws NoSuchJobException {
    final Integer expectedInstanceCount = 10;
    when(this.jobExplorer.getJobInstanceCount(JOB_NAME)).thenReturn(expectedInstanceCount);
    final Integer instanceCount = this.jobService.getJobInstanceCount(JOB_NAME);
    assertThat(instanceCount).isEqualTo(expectedInstanceCount);
}
 
Example #17
Source File: DefaultJobServiceTest.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Test
public void getJobInstanceCountNoSuchJobExceptionTest() throws NoSuchJobException {
    final Integer expectedInstanceCount = 0;
    when(this.jobExplorer.getJobInstanceCount(JOB_NAME)).thenThrow(new NoSuchJobException("TEST"));
    final Integer instanceCount = this.jobService.getJobInstanceCount(JOB_NAME);
    assertThat(instanceCount).isEqualTo(expectedInstanceCount);
}
 
Example #18
Source File: DefaultJobServiceTest.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Test
public void getJobByNameTest() throws NoSuchJobException {
    final Job expectedJob = DomainTestHelper.createJob(JOB_NAME);
    when(this.jobRegistry.getJob(JOB_NAME)).thenReturn(expectedJob);
    final Job job = this.jobService.getJobByName(JOB_NAME);
    assertThat(job).isEqualTo(expectedJob);
}
 
Example #19
Source File: DefaultJobServiceTest.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected = SpringBatchLightminApplicationException.class)
public void restartJobExecutionExceptionTest() throws JobParametersInvalidException, JobRestartException,
        JobInstanceAlreadyCompleteException, NoSuchJobExecutionException, NoSuchJobException {
    final Long jobExecutionId = 10L;
    when(this.jobOperator.restart(jobExecutionId)).thenThrow(NoSuchJobExecutionException.class);
    this.jobService.restartJobExecution(jobExecutionId);
}
 
Example #20
Source File: DefaultJobServiceTest.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Test(expected = SpringBatchLightminApplicationException.class)
public void stopJobExecutionExceptionTest() throws JobParametersInvalidException, JobRestartException,
        JobInstanceAlreadyCompleteException, NoSuchJobExecutionException, NoSuchJobException,
        JobExecutionNotRunningException {
    final Long jobExecutionId = 10L;
    when(this.jobOperator.stop(jobExecutionId)).thenThrow(NoSuchJobExecutionException.class);
    this.jobService.stopJobExecution(jobExecutionId);
}
 
Example #21
Source File: DefaultSchedulerServiceTest.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Test
public void registerSchedulerForJobPeriodTest() throws NoSuchJobException {
    when(this.jobRegistry.getJob("sampleJob")).thenReturn(this.sampleJob);

    final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration(null,
            10L, 10L, JobSchedulerType.PERIOD);
    final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration);
    jobConfiguration.setJobConfigurationId(1L);
    final String beanName = this.schedulerService.registerSchedulerForJob(jobConfiguration);
    assertThat(beanName).startsWith("sampleJob-PERIOD");
}
 
Example #22
Source File: DefaultSchedulerServiceTest.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Test
public void registerSchedulerForJobCronTest() throws NoSuchJobException {
    when(this.jobRegistry.getJob("sampleJob")).thenReturn(this.sampleJob);
    final JobSchedulerConfiguration jobSchedulerConfiguration = DomainTestHelper.createJobSchedulerConfiguration("* * *" +
                    " * * *",
            null, null, JobSchedulerType.CRON);

    final JobConfiguration jobConfiguration = DomainTestHelper.createJobConfiguration(jobSchedulerConfiguration);
    jobConfiguration.setJobConfigurationId(1L);
    final String beanName = this.schedulerService.registerSchedulerForJob(jobConfiguration);
    assertThat(beanName).startsWith("sampleJob-CRON");
}
 
Example #23
Source File: BatchWebAutoConfiguration.java    From spring-boot-starter-batch-web with Apache License 2.0 5 votes vote down vote up
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
	baseConfig.jobRegistry().getJobNames().forEach(jobName -> {
		try {
			AbstractJob job = (AbstractJob) baseConfig.jobRegistry().getJob(jobName);
			this.addListenerToJobService().addListenerToJob(job);
		} catch (NoSuchJobException e) {
			throw new IllegalStateException(e);
		}
	});
}
 
Example #24
Source File: JobInstanceController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Return a page-able list of {@link JobInstanceResource} defined jobs.
 *
 * @param jobName the name of the job
 * @param pageable page-able collection of {@link JobInstance}s.
 * @param assembler for the {@link JobInstance}s
 * @return a list of Job Instance
 * @throws NoSuchJobException if the job for jobName specified does not exist.
 */
@RequestMapping(value = "", method = RequestMethod.GET, params = "name")
@ResponseStatus(HttpStatus.OK)
public PagedModel<JobInstanceResource> list(@RequestParam("name") String jobName, Pageable pageable,
		PagedResourcesAssembler<JobInstanceExecutions> assembler) throws NoSuchJobException {
	List<JobInstanceExecutions> jobInstances = taskJobService.listTaskJobInstancesForJobName(pageable, jobName);
	Page<JobInstanceExecutions> page = new PageImpl<>(jobInstances, pageable,
			taskJobService.countJobInstances(jobName));
	return assembler.toModel(page, jobAssembler);
}
 
Example #25
Source File: JobExecutionThinController.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve all task job executions with the task name specified
 *
 * @param jobName name of the job
 * @param pageable page-able collection of {@code TaskJobExecution}s.
 * @param assembler for the {@link TaskJobExecution}s
 * @return list task/job executions with the specified jobName.
 * @throws NoSuchJobException if the job with the given name does not exist.
 */
@RequestMapping(value = "", method = RequestMethod.GET, params = "name", produces = "application/json")
@ResponseStatus(HttpStatus.OK)
public PagedModel<JobExecutionThinResource> retrieveJobsByName(@RequestParam("name") String jobName,
		Pageable pageable, PagedResourcesAssembler<TaskJobExecution> assembler) throws NoSuchJobException {
	List<TaskJobExecution> jobExecutions = taskJobService.listJobExecutionsForJobWithStepCount(pageable, jobName);
	Page<TaskJobExecution> page = new PageImpl<>(jobExecutions, pageable,
			taskJobService.countJobExecutionsForJob(jobName, null));
	return assembler.toModel(page, jobAssembler);
}
 
Example #26
Source File: CustomerReportJobConfig.java    From spring-batch-article with MIT License 5 votes vote down vote up
@PreDestroy
public void destroy() throws NoSuchJobException {
    jobs.getJobNames().forEach(name -> log.info("job name: {}", name));
    jobs.getJobInstances(JOB_NAME, 0, jobs.getJobInstanceCount(JOB_NAME)).forEach(
        jobInstance -> {
            log.info("job instance id {}", jobInstance.getInstanceId());
        }
    );

}
 
Example #27
Source File: DefaultTaskJobService.java    From spring-cloud-dataflow with Apache License 2.0 5 votes vote down vote up
@Override
public List<JobInstanceExecutions> listTaskJobInstancesForJobName(Pageable pageable, String jobName)
		throws NoSuchJobException {
	Assert.notNull(pageable, "pageable must not be null");
	Assert.notNull(jobName, "jobName must not be null");
	List<JobInstanceExecutions> taskJobInstances = new ArrayList<>();
	for (JobInstance jobInstance : jobService.listJobInstances(jobName, getPageOffset(pageable),
			pageable.getPageSize())) {
		taskJobInstances.add(getJobInstanceExecution(jobInstance));
	}
	return taskJobInstances;
}
 
Example #28
Source File: AdHocStarter.java    From spring-batch-rest with Apache License 2.0 5 votes vote down vote up
public JobExecution start(Job job, Boolean async, Map<String, Object> properties) {
  	Job existingJob = null;
try {
	existingJob = jobRegistry.getJob(job.getName());
} catch (NoSuchJobException e) {
	log.info("Registering new job: " + job.getName());
}
JobConfig jobConfig = JobConfig.builder()
		.asynchronous(async)
		.properties(properties == null ? new HashMap<>() : properties)
		.name(job.getName()).build();
JobBuilder.registerJob(jobRegistry, existingJob == null ? job : existingJob);
return this.start(jobConfig);
  }
 
Example #29
Source File: JobExecutionControllerTest.java    From spring-batch-rest with Apache License 2.0 4 votes vote down vote up
@Test
public void jobFailsWithNoSuchJobException() throws Exception {
    assertJobExecutionExceptionToStatusMapping(new NoSuchJobException("causeMsg"), HttpStatus.NOT_FOUND);
}
 
Example #30
Source File: DefaultTaskJobService.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Override
public List<TaskJobExecution> listJobExecutionsForJob(Pageable pageable, String jobName, BatchStatus status) throws NoSuchJobException {
	Assert.notNull(pageable, "pageable must not be null");
	return getTaskJobExecutionsForList(
			jobService.listJobExecutionsForJob(jobName, status, getPageOffset(pageable), pageable.getPageSize()));
}