/** * Convenience method to get the current job parameters. * * @return the {@link JobParameters} from the enclosing job, or empty if * that is null */ public JobParameters getJobParameters() { if (jobExecution == null) { return new JobParameters(); } return jobExecution.getJobParameters(); }
@Override public Properties getJobParameters() { Properties properties = parametersConverter.getProperties(this.execution.getJobParameters()); properties.remove(JsrJobParametersConverter.JOB_RUN_ID); return properties; } }
/** * @return a map containing the items from the {@link JobParameters} */ public Map<String, Object> getJobParameters() { Map<String, Object> result = new HashMap<>(); for (Entry<String, JobParameter> entry : jobExecution.getJobParameters().getParameters() .entrySet()) { result.put(entry.getKey(), entry.getValue().getValue()); } return Collections.unmodifiableMap(result); }
protected Properties getJobRestartProperties(Properties params, org.springframework.batch.core.JobExecution previousJobExecution) { Properties jobRestartProperties = new Properties(); if (previousJobExecution != null) { JobParameters previousJobParameters = previousJobExecution.getJobParameters(); if (previousJobParameters != null && !previousJobParameters.isEmpty()) { jobRestartProperties.putAll(previousJobParameters.toProperties()); } } if (params != null) { Enumeration<?> propertyNames = params.propertyNames(); while(propertyNames.hasMoreElements()) { String curName = (String) propertyNames.nextElement(); jobRestartProperties.setProperty(curName, params.getProperty(curName)); } } return jobRestartProperties; }
@Override public Properties getParameters(long executionId) throws NoSuchJobExecutionException, JobSecurityException { org.springframework.batch.core.JobExecution execution = jobExplorer.getJobExecution(executionId); if(execution == null) { throw new NoSuchJobExecutionException("Unable to find the JobExecution for id " + executionId); } Properties properties = jobParametersConverter.getProperties(execution.getJobParameters()); properties.remove(JsrJobParametersConverter.JOB_RUN_ID); return properties; }
@Override public String getParameters(long executionId) throws NoSuchJobExecutionException { JobExecution jobExecution = findExecutionById(executionId); return PropertiesConverter.propertiesToString(jobParametersConverter.getProperties(jobExecution .getJobParameters())); }
@Override public Long restart(long executionId) throws JobInstanceAlreadyCompleteException, NoSuchJobExecutionException, NoSuchJobException, JobRestartException, JobParametersInvalidException { logger.info("Checking status of job execution with id=" + executionId); JobExecution jobExecution = findExecutionById(executionId); String jobName = jobExecution.getJobInstance().getJobName(); Job job = jobRegistry.getJob(jobName); JobParameters parameters = jobExecution.getJobParameters(); logger.info(String.format("Attempting to resume job with name=%s and parameters=%s", jobName, parameters)); try { return jobLauncher.run(job, parameters).getId(); } catch (JobExecutionAlreadyRunningException e) { throw new UnexpectedJobExecutionException(String.format(ILLEGAL_STATE_MSG, "job execution already running", jobName, parameters), e); } }
nextParameters = incrementer.getNext(previousExecution.getJobParameters());
@Test public void testJobParameters() { JobParameters params = new JobParametersBuilder() .addString("key1", "value1") .toJobParameters(); when(execution.getJobParameters()).thenReturn(params); assertEquals("value1", execution.getJobParameters().getString("key1")); }
@Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { assertEquals(1, execution.getJobParameters().getParameters().size()); execution.setStatus(BatchStatus.FAILED); execution.setEndTime(new Date()); jobRepository.update(execution); throw new RuntimeException("FOO"); } @Override
@Override public void execute(JobExecution execution) { assertEquals(1, execution.getJobParameters().getParameters().size()); execution.setStatus(BatchStatus.STOPPED); execution.setEndTime(new Date()); jobRepository.update(execution); } @Override
@Transactional @Test public void testGetLastJobExecution() { JobExecution lastExecution = new JobExecution(jobInstance, jobParameters); lastExecution.setStatus(BatchStatus.STARTED); int JUMP_INTO_FUTURE = 1000; // makes sure start time is 'greatest' lastExecution.setCreateTime(new Date(System.currentTimeMillis() + JUMP_INTO_FUTURE)); jobExecutionDao.saveJobExecution(lastExecution); assertEquals(lastExecution, jobExecutionDao.getLastJobExecution(jobInstance)); assertNotNull(lastExecution.getJobParameters()); assertEquals("jobKey", lastExecution.getJobParameters().getString("job.key")); }
+ jobIdentifier); jobParameters = jobExecution.getJobParameters(); jobName = jobExecution.getJobInstance().getJobName();
jobParametersValidator.validate(execution.getJobParameters());
+ "so it may be dangerous to proceed. Manual intervention is probably necessary."); if (execution.getJobParameters().getParameters().size() > 0 && (status == BatchStatus.COMPLETED || status == BatchStatus.ABANDONED)) { throw new JobInstanceAlreadyCompleteException( "A job instance already exists and is complete for parameters=" + jobParameters
private JobExecution launch(boolean start, long jobExecutionId) throws Exception { if (start) { Calendar c = Calendar.getInstance(); JobParametersBuilder builder = new JobParametersBuilder(); builder.addDate("TIMESTAMP", c.getTime()); JobParameters jobParameters = builder.toJobParameters(); return jobLauncher.run(job, jobParameters); } else { JdbcJobExecutionDao dao = new JdbcJobExecutionDao(); dao.setJdbcTemplate(jdbcTemplate); JobExecution execution = dao.getJobExecution(jobExecutionId); if (execution != null) { return jobLauncher.run(job, execution.getJobParameters()); } return null; } }
@Test public void testCreateJobExecutionsWithIncrementer() throws Exception { utils = new JobRepositoryTestUtils(jobRepository, dataSource); utils.setJobParametersIncrementer(new JobParametersIncrementer() { @Override public JobParameters getNext(JobParameters parameters) { return new JobParametersBuilder().addString("foo","bar").toJobParameters(); } }); List<JobExecution> list = utils.createJobExecutions(1); assertEquals(1, list.size()); assertEquals("bar", list.get(0).getJobParameters().getString("foo")); utils.removeJobExecutions(list); assertEquals(beforeJobs, JdbcTestUtils.countRowsInTable(jdbcTemplate, "BATCH_JOB_EXECUTION")); } }
public JobExecution(JobExecution original) { this.jobParameters = original.getJobParameters(); this.jobInstance = original.getJobInstance(); this.stepExecutions = original.getStepExecutions(); this.status = original.getStatus(); this.startTime = original.getStartTime(); this.createTime = original.getCreateTime(); this.endTime = original.getEndTime(); this.lastUpdated = original.getLastUpdated(); this.exitStatus = original.getExitStatus(); this.executionContext = original.getExecutionContext(); this.failureExceptions = original.getFailureExceptions(); this.jobConfigurationName = original.getJobConfigurationName(); this.setId(original.getId()); this.setVersion(original.getVersion()); }
private StepExecution update(Set<StepExecution> split, StepExecution stepExecution, BatchStatus status, boolean sameJobExecution) throws Exception { ExecutionContext executionContext = stepExecution.getExecutionContext(); for (StepExecution child : split) { child.setEndTime(new Date()); child.setStatus(status); jobRepository.update(child); } stepExecution.setEndTime(new Date()); stepExecution.setStatus(status); jobRepository.update(stepExecution); JobExecution jobExecution = stepExecution.getJobExecution(); if (!sameJobExecution) { jobExecution.setStatus(BatchStatus.FAILED); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); JobInstance jobInstance = jobExecution.getJobInstance(); jobExecution = jobRepository.createJobExecution(jobInstance.getJobName(), jobExecution.getJobParameters()); } stepExecution = jobExecution.createStepExecution(stepExecution.getStepName()); stepExecution.setExecutionContext(executionContext); jobRepository.add(stepExecution); return stepExecution; }
/** * * SQL implementation using Sequences via the Spring incrementer * abstraction. Once a new id has been obtained, the JobExecution is saved * via a SQL INSERT statement. * * @see JobExecutionDao#saveJobExecution(JobExecution) * @throws IllegalArgumentException if jobExecution is null, as well as any * of it's fields to be persisted. */ @Override public void saveJobExecution(JobExecution jobExecution) { validateJobExecution(jobExecution); jobExecution.incrementVersion(); jobExecution.setId(jobExecutionIncrementer.nextLongValue()); Object[] parameters = new Object[] { jobExecution.getId(), jobExecution.getJobId(), jobExecution.getStartTime(), jobExecution.getEndTime(), jobExecution.getStatus().toString(), jobExecution.getExitStatus().getExitCode(), jobExecution.getExitStatus().getExitDescription(), jobExecution.getVersion(), jobExecution.getCreateTime(), jobExecution.getLastUpdated(), jobExecution.getJobConfigurationName() }; getJdbcTemplate().update( getQuery(SAVE_JOB_EXECUTION), parameters, new int[] { Types.BIGINT, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR }); insertJobParameters(jobExecution.getId(), jobExecution.getJobParameters()); }