private void executeRegisteredJobs(JobParameters jobParameters) throws JobExecutionException { if (this.jobRegistry != null && StringUtils.hasText(this.jobNames)) { String[] jobsToRun = this.jobNames.split(","); for (String jobName : jobsToRun) { try { Job job = this.jobRegistry.getJob(jobName); if (this.jobs.contains(job)) { continue; } execute(job, jobParameters); } catch (NoSuchJobException ex) { logger.debug("No job found in registry for job name: " + jobName); continue; } } } }
@Bean public Job discreteJob() { AbstractJob job = new AbstractJob("discreteRegisteredJob") { @Override public Collection<String> getStepNames() { return Collections.emptySet(); } @Override public Step getStep(String stepName) { return null; } @Override protected void doExecute(JobExecution execution) throws JobExecutionException { execution.setStatus(BatchStatus.COMPLETED); } }; job.setJobRepository(this.jobRepository); return job; }
@Bean public Job discreteJob() { AbstractJob job = new AbstractJob("discreteLocalJob") { @Override public Collection<String> getStepNames() { return Collections.emptySet(); } @Override public Step getStep(String stepName) { return null; } @Override protected void doExecute(JobExecution execution) throws JobExecutionException { execution.setStatus(BatchStatus.COMPLETED); } }; job.setJobRepository(this.jobRepository); return job; }
private void executeRegisteredJobs(JobParameters jobParameters) throws JobExecutionException { if (this.jobRegistry != null && StringUtils.hasText(this.jobNames)) { String[] jobsToRun = this.jobNames.split(","); for (String jobName : jobsToRun) { try { Job job = this.jobRegistry.getJob(jobName); if (this.jobs.contains(job)) { continue; } execute(job, jobParameters); } catch (NoSuchJobException nsje) { logger.debug("No job found in registry for job name: " + jobName); continue; } } } }
/** * @param jsonParser Set the json parser * @param deserializationContext Set the deserialization context * @return a JobExecutionInfo object * @throws IOException if there is a problem */ @Override public final JobExecutionException deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException { try { JsonToken jsonToken = jsonParser.nextToken(); assert jsonParser.getCurrentName() == "errors"; jsonToken = jsonParser.nextToken(); assert jsonToken == JsonToken.START_OBJECT; jsonToken = jsonParser.nextToken(); // error code jsonToken = jsonParser.nextToken(); JobExecutionException jobExecutionException = new JobExecutionException( jsonParser.getText()); jsonToken = jsonParser.nextToken(); while (jsonToken != JsonToken.END_OBJECT) { jsonToken = jsonParser.nextToken(); } return jobExecutionException; } catch (AssertionError ae) { throw new IllegalArgumentException("Cannot convert into JobExecutionException"); } }
@Override public final void setupModule(final SetupContext setupContext) { SimpleKeyDeserializers keyDeserializers = new SimpleKeyDeserializers(); keyDeserializers.addDeserializer(Location.class, new GeographicalRegionKeyDeserializer()); setupContext.addKeyDeserializers(keyDeserializers); SimpleSerializers simpleSerializers = new SimpleSerializers(); simpleSerializers.addSerializer(new JobInstanceSerializer()); simpleSerializers.addSerializer(new JobExecutionSerializer()); setupContext.addSerializers(simpleSerializers); SimpleDeserializers simpleDeserializers = new SimpleDeserializers(); simpleDeserializers.addDeserializer(JobInstance.class, new JobInstanceDeserializer()); simpleDeserializers.addDeserializer(JobExecution.class, new JobExecutionDeserializer(jobInstanceService)); simpleDeserializers.addDeserializer(JobExecutionException.class, new JobExecutionExceptionDeserializer()); setupContext.addDeserializers(simpleDeserializers); }
@SuppressWarnings("unchecked") protected void executeInternal(JobExecutionContext context) { Map<String, Object> jobDataMap = context.getMergedJobDataMap(); String jobName = (String) jobDataMap.get(JOB_NAME); LOGGER.info("Quartz trigger firing with Spring Batch jobName=" + jobName); try { Job job = jobLocator.getJob(jobName); JobParameters previousJobParameters = null; List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, 0, 1); if ((jobInstances != null) && (jobInstances.size() > 0)) { previousJobParameters = jobInstances.get(0).getJobParameters(); } JobParameters jobParameters = getJobParametersFromJobMap(jobDataMap, previousJobParameters); if (job.getJobParametersIncrementer() != null) { jobParameters = job.getJobParametersIncrementer().getNext(jobParameters); } jobLauncher.run(jobLocator.getJob(jobName), jobParameters); } catch (JobExecutionException e) { LOGGER.error("Could not execute job.", e); } }
/** * Invoke job one. * * @return String */ @ResponseBody @GetMapping("/invokejob") public String invokejob() { EXEC.execute(() -> { try { jobLauncher.run(oneJob, new JobParametersBuilder().toJobParameters()); } catch (JobExecutionException e) { LOG.error("Error during job execution", e); } }); return "Batch job has been invoked"; }
private void executeLocalJobs(JobParameters jobParameters) throws JobExecutionException { for (Job job : this.jobs) { if (StringUtils.hasText(this.jobNames)) { String[] jobsToRun = this.jobNames.split(","); if (!PatternMatchUtils.simpleMatch(jobsToRun, job.getName())) { logger.debug("Skipped job: " + job.getName()); continue; } } execute(job, jobParameters); } }
@RequestMapping(value = "/jobs/{jobName}/start", method = RequestMethod.POST) @ResponseBody public JobExecution start(@PathVariable("jobName") final String jobName, @RequestBody final JobParameters parameters) throws JobExecutionException { getJob(jobName); final long executionId = batchOperator.start(jobName, parameters); return execution(executionId); }
@Override public void abandonRunningJobs() { LOG.info("Abandoning running jobs at application startup"); jobExplorer.getJobNames().stream().map(jobExplorer::findRunningJobExecutions).flatMap(Collection::stream) .filter(exec -> ABANDONABLE.contains(exec.getStatus())).forEach(exec -> { try { abandonJob(exec.getId()); } catch (final JobExecutionException e) { LOG.error("Error abandoning job execution #{}: {}", exec.getId(), e, e); } }); }
@Override public void write(List<? extends AgentCountStatistics> items) throws Exception { if (items.size() == 1) { AgentCountStatistics agentCountStatistics = items.get(0); if (agentCountStatistics == null || agentCountStatistics.getAgentCount() < 0) { throw new JobExecutionException("Bad parameter"); } boolean success = agentStatisticsDao.insertAgentCount(agentCountStatistics); if (!success) { throw new JobExecutionException("insert AgentCount failed."); } } else { throw new JobExecutionException("Bad parameter"); } }
@Override public void run(String... args) throws JobExecutionException { logger.info("Running default command line with: " + Arrays.asList(args)); launchJobFromProperties(StringUtils.splitArrayElementsIntoProperties(args, "=")); }
protected void launchJobFromProperties(Properties properties) throws JobExecutionException { JobParameters jobParameters = this.converter.getJobParameters(properties); executeLocalJobs(jobParameters); executeRegisteredJobs(jobParameters); }
@Override public long start(final String jobName, final JobParameters params) throws JobExecutionException { return doStart(jobName, createJobParameters(jobName, params)); }
/** * * @throws Exception * if there is a problem serializing the object */ @Test public void testJobExecutionException() throws Exception { JobExecutionException jobExecutionException = objectMapper.readValue("{\"errors\" : { \"spring.integration.http.handler.error\" : \"A Spring Integration handler raised an exception while handling an HTTP request. The exception is of type class org.springframework.integration.MessageHandlingException and it has a message: (org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={query.string=from Source, attempt=9}. If you want to run this job again, change the parameters.)\" } }", JobExecutionException.class); }
long start(String jobName, JobParameters parameters) throws JobExecutionException;