org.springframework.batch.core.JobParametersInvalidException Java Examples
The following examples show how to use
org.springframework.batch.core.JobParametersInvalidException.
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 |
@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: BatchJobConfiguration.java From patient-batch-loader with GNU General Public License v3.0 | 6 votes |
@Bean public JobParametersValidator validator() { return new JobParametersValidator() { @Override public void validate(JobParameters parameters) throws JobParametersInvalidException { String fileName = parameters.getString(Constants.JOB_PARAM_FILE_NAME); if (StringUtils.isBlank(fileName)) { throw new JobParametersInvalidException( "The patient-batch-loader.fileName parameter is required."); } try { Path file = Paths.get(applicationProperties.getBatch().getInputPath() + File.separator + fileName); if (Files.notExists(file) || !Files.isReadable(file)) { throw new Exception("File did not exist or was not readable"); } } catch (Exception e) { throw new JobParametersInvalidException( "The input path + patient-batch-loader.fileName parameter needs to " + "be a valid file location."); } } }; }
Example #3
Source File: CapitalizeNamesJobScheduler.java From spring-batch with MIT License | 5 votes |
@Scheduled(cron = "0/10 * * * * ?") public void runBatchJob() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException { LOGGER.info("start runBatchJob"); if (enabled) { jobLauncher.run(capitalizeNamesJob, new JobParametersBuilder() .addDate("date", new Date()).toJobParameters()); } }
Example #4
Source File: TaxCalculatorJobService.java From batchers with Apache License 2.0 | 5 votes |
protected void startJobs(long year, long month) { try { JobParameters jobParameters = new JobParametersBuilder() .addLong("month", month) .addLong("year", year) .toJobParameters(); LOG.info("Running job in jobservice"); jobLauncher.run(employeeJob, jobParameters); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException e) { LOG.error("Job running failed", e); //TODO shouldn't we handle this differently? } }
Example #5
Source File: TaxCalculatorJobServiceTest.java From batchers with Apache License 2.0 | 5 votes |
@Test public void whenStarJobs_withGivenYearAndMonth_runJobWithParameters() throws JobParametersInvalidException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException { taxCalculatorJobService.runTaxCalculatorJob(new JobStartParams(YEAR, MONTH)); verify(jobLauncherMock).run(any(Job.class), jobParametersArgumentCaptor.capture()); JobParameters jobParameters = jobParametersArgumentCaptor.getValue(); assertThat(jobParameters.getLong("year")).isEqualTo(YEAR); assertThat(jobParameters.getLong("month")).isEqualTo(MONTH); }
Example #6
Source File: JdbcBatchTest.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Test public void jobTest() { JobParametersBuilder builder = new JobParametersBuilder(); try { JobExecution execution = jobLauncher.run(validJob, builder.toJobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException e) { e.printStackTrace(); } }
Example #7
Source File: JpaBatchTest.java From spring4-sandbox with Apache License 2.0 | 5 votes |
@Test public void jobTest() { try { JobExecution execution = jobLauncher.run(javaJob, new JobParameters()); assertEquals(BatchStatus.COMPLETED, execution.getStatus()); } catch (JobExecutionAlreadyRunningException | JobRestartException | JobInstanceAlreadyCompleteException | JobParametersInvalidException e) { e.printStackTrace(); } Conference conf = conferenceDao.findById(1L); log.debug("conf@" + conf); }
Example #8
Source File: JobExecutionControllerTest.java From spring-batch-rest with Apache License 2.0 | 4 votes |
@Test public void jobFailsWithJobParametersInvalidException() throws Exception { assertJobExecutionExceptionToStatusMapping(new JobParametersInvalidException("causeMsg"), HttpStatus.BAD_REQUEST); }
Example #9
Source File: AdHocSchedulerParamsTest.java From spring-batch-rest with Apache License 2.0 | 4 votes |
@Test @DirtiesContext(methodMode = MethodMode.BEFORE_METHOD) public void paramsAddedToScheduledJobWorks() throws InterruptedException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException, SchedulerException { Job job1 = job("j1"); Job job2 = job("j2"); jobBuilder.registerJob(job1); jobBuilder.registerJob(job2); Map<String, Object> params = new HashMap<String, Object>(); params.put("testParamKey", "testParamValue"); JobParameters expectedParams = JobParamUtil.convertRawToJobParams(params); JobConfig job1Config = JobConfig.builder().name("j1").properties(params).build(); JobConfig job2Config = JobConfig.builder().name("j2").properties(params).build(); Date now = Date.from(Instant.now().plusMillis(2000)); scheduler.start(); when(jobLauncher.run(job1, expectedParams)) .thenReturn(new JobExecution(new Random().nextLong(), expectedParams)); when(jobLauncher.run(job2, expectedParams)) .thenReturn(new JobExecution(new Random().nextLong(), expectedParams)); scheduler.schedule(job1Config, now); scheduler.schedule(job2Config, TRIGGER_EVERY_SECOND); ArgumentCaptor<Job> jobCaptor = ArgumentCaptor.forClass(Job.class); ArgumentCaptor<JobParameters> jobParamCaptor = ArgumentCaptor.forClass(JobParameters.class); verify(jobLauncher, timeout(8000).times(2)).run(jobCaptor.capture(), jobParamCaptor.capture()); List<JobParameters> paramsListAfterCall = jobParamCaptor.getAllValues(); Assertions.assertEquals(paramsListAfterCall.size(), 2); for (JobParameters jobParams : paramsListAfterCall) { Assertions.assertEquals(jobParams.getString("testParamKey"), "testParamValue"); } scheduler.pause(); }
Example #10
Source File: SingleJobLauncher.java From CogStack-Pipeline with Apache License 2.0 | 4 votes |
private void startNextInstance() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException, JobParametersNotFoundException, NoSuchJobException { jobOperator.startNextInstance(job.getName()); }
Example #11
Source File: TaskJobLauncherCommandLineRunner.java From spring-cloud-task with Apache License 2.0 | 4 votes |
protected void execute(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException { String jobName = job.getName(); JobParameters parameters = jobParameters; boolean jobInstanceExists = this.taskJobRepository.isJobInstanceExists(jobName, parameters); if (jobInstanceExists) { JobExecution lastJobExecution = this.taskJobRepository .getLastJobExecution(jobName, jobParameters); if (lastJobExecution != null && isStoppedOrFailed(lastJobExecution) && job.isRestartable()) { // Retry a failed or stopped execution with previous parameters JobParameters previousParameters = lastJobExecution.getJobParameters(); /* * remove Non-identifying parameters from the previous execution's * parameters since there is no way to remove them programmatically. If * they are required (or need to be modified) on a restart, they need to * be (re)specified. */ JobParameters previousIdentifyingParameters = removeNonIdentifying( previousParameters); // merge additional parameters with previous ones (overriding those with // the same key) parameters = merge(previousIdentifyingParameters, jobParameters); } } else { JobParametersIncrementer incrementer = job.getJobParametersIncrementer(); if (incrementer != null) { JobParameters nextParameters = new JobParametersBuilder(jobParameters, this.taskJobExplorer).getNextJobParameters(job).toJobParameters(); parameters = merge(nextParameters, jobParameters); } } JobExecution execution = this.taskJobLauncher.run(job, parameters); if (this.taskApplicationEventPublisher != null) { this.taskApplicationEventPublisher .publishEvent(new JobExecutionEvent(execution)); } this.jobExecutionList.add(execution); if (execution.getStatus().equals(BatchStatus.FAILED)) { throwJobFailedException(Collections.singletonList(execution)); } }
Example #12
Source File: JobOperationsController.java From spring-boot-starter-batch-web with Apache License 2.0 | 4 votes |
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) @ExceptionHandler(JobParametersInvalidException.class) public String handleParametersInvalid(Exception ex) { LOG.warn("Job parameters are invalid.", ex); return ex.getMessage(); }
Example #13
Source File: HelloWorldBatchTest.java From blog with MIT License | 4 votes |
@Test(expected = JobParametersInvalidException.class) public void test_That_args_validation_Should_throw_error_When_empty_args() throws Exception { jobLauncherTestUtils.launchJob(new JobParametersBuilder() .toJobParameters()); }
Example #14
Source File: JobService.java From spring-cloud-dataflow with Apache License 2.0 | 2 votes |
/** * Launch a job with the parameters provided. If an instance with the parameters provided * has already failed (and is not abandoned) it will be restarted. * * @param jobName the job name * @param params the {@link JobParameters} * @return the resulting {@link JobExecution} if successful * * @throws NoSuchJobException thrown if job specified does not exist * @throws JobExecutionAlreadyRunningException thrown if job is already executing * @throws JobRestartException thrown if job failed to restart * @throws JobInstanceAlreadyCompleteException thrown if job was already complete * @throws JobParametersInvalidException thrown if job parameters are invalid */ JobExecution launch(String jobName, JobParameters params) throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException;
Example #15
Source File: JobService.java From spring-cloud-dataflow with Apache License 2.0 | 2 votes |
/** * Launch a job with the parameters provided. * * @param jobExecutionId the job execution to restart * @return the resulting {@link JobExecution} if successful * * @throws NoSuchJobExecutionException thrown if job execution specified does not exist * @throws NoSuchJobException thrown if job specified does not exist * @throws JobExecutionAlreadyRunningException thrown if job is already executing * @throws JobRestartException thrown if job failed to restart * @throws JobInstanceAlreadyCompleteException thrown if job was already complete * @throws JobParametersInvalidException thrown if job parameters are invalid */ JobExecution restart(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException;
Example #16
Source File: JobService.java From spring-cloud-dataflow with Apache License 2.0 | 2 votes |
/** * Launch a job with the parameters provided. JSR-352 supports restarting of jobs with a * new set of parameters. This method exposes this functionality * * @param jobExecutionId the job execution to restart * @param params the job parameters to use in the restart * @return the resulting {@link JobExecution} if successful * * @throws NoSuchJobExecutionException thrown if job execution specified does not exist * @throws NoSuchJobException thrown if job specified does not exist * @throws JobExecutionAlreadyRunningException thrown if job is already executing * @throws JobRestartException thrown if job failed to restart * @throws JobInstanceAlreadyCompleteException thrown if job was already complete * @throws JobParametersInvalidException thrown if job parameters are invalid */ JobExecution restart(Long jobExecutionId, JobParameters params) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException;