public Long getJobId() { return stepExecution.getJobExecution().getJobId(); }
/** * Validate JobExecution. At a minimum, JobId, StartTime, EndTime, and * Status cannot be null. * * @param jobExecution * @throws IllegalArgumentException */ private void validateJobExecution(JobExecution jobExecution) { Assert.notNull(jobExecution, "jobExecution cannot be null"); Assert.notNull(jobExecution.getJobId(), "JobExecution Job-Id cannot be null."); Assert.notNull(jobExecution.getStatus(), "JobExecution status cannot be null."); Assert.notNull(jobExecution.getCreateTime(), "JobExecution create time cannot be null"); }
@Override public void setValues(PreparedStatement ps, int i) throws SQLException { Assert.state(itemIterator.nextIndex() == i, "Item ordering must be preserved in batch sql update"); ps.setLong(1, incrementer.nextLongValue()); ps.setLong(2, stepExecution.getJobExecution().getJobId()); ps.setBytes(3, SerializationUtils.serialize(itemIterator.next())); ps.setString(4, NEW); } });
@Override public void update(JobExecution jobExecution) { Assert.notNull(jobExecution, "JobExecution cannot be null."); Assert.notNull(jobExecution.getJobId(), "JobExecution must have a Job ID set."); Assert.notNull(jobExecution.getId(), "JobExecution must be already saved (have an id assigned)."); jobExecution.setLastUpdated(new Date(System.currentTimeMillis())); jobExecutionDao.synchronizeStatus(jobExecution); jobExecutionDao.updateJobExecution(jobExecution); }
private List<Long> retrieveKeys() { synchronized (lock) { return jdbcTemplate.query( "SELECT ID FROM BATCH_STAGING WHERE JOB_ID=? AND PROCESSED=? ORDER BY ID", new RowMapper<Long>() { @Override public Long mapRow(ResultSet rs, int rowNum) throws SQLException { return rs.getLong(1); } }, stepExecution.getJobExecution().getJobId(), StagingItemWriter.NEW); } }
private void cacheJobIds(JobExecution execution) { if (execution == null) { return; } jobExecutionIds.add(execution.getId()); jobIds.add(execution.getJobId()); }
/** * Test method for * {@link org.springframework.batch.core.JobExecution#getJobId()}. */ @Test public void testGetJobId() { assertEquals(11, execution.getJobId().longValue()); execution = new JobExecution(new JobInstance(new Long(23), "testJob"), null, new JobParameters(), null); assertEquals(23, execution.getJobId().longValue()); }
/** * Test method for * {@link org.springframework.batch.core.JobExecution#getJobId()}. */ @Test public void testGetJobIdForNullJob() { execution = new JobExecution((JobInstance) null, (JobParameters) null); assertEquals(null, execution.getJobId()); }
@Test public void testSimulatedRestart() throws Exception { factory.setItemReader(new ListItemReader<>(Arrays.asList(StringUtils .commaDelimitedListToStringArray("1,2,3,4,5,6")))); Step step = factory.getObject(); StepExecution stepExecution = getStepExecution(step); // Set up context with two messages (chunks) in the backlog stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.EXPECTED, 6); stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.ACTUAL, 4); // And make the back log real requests.send(getSimpleMessage("foo", stepExecution.getJobExecution().getJobId())); requests.send(getSimpleMessage("bar", stepExecution.getJobExecution().getJobId())); step.execute(stepExecution); waitForResults(8, 10); assertEquals(8, TestItemWriter.count); assertEquals(6, stepExecution.getReadCount()); }
private void checkRepository(BatchStatus status, ExitStatus exitStatus) { // because map dao stores in memory, it can be checked directly JobInstance jobInstance = jobExecution.getJobInstance(); JobExecution other = jobExecutionDao.findJobExecutions(jobInstance).get(0); assertEquals(jobInstance.getId(), other.getJobId()); assertEquals(status, other.getStatus()); if (exitStatus != null) { assertEquals(exitStatus.getExitCode(), other.getExitStatus().getExitCode()); } }
private void checkRepository(BatchStatus status, ExitStatus exitStatus) { // because map DAO stores in memory, it can be checked directly JobInstance jobInstance = jobExecution.getJobInstance(); JobExecution other = jobExecutionDao.findJobExecutions(jobInstance).get(0); assertEquals(jobInstance.getId(), other.getJobId()); assertEquals(status, other.getStatus()); if (exitStatus != null) { assertEquals(exitStatus.getExitCode(), other.getExitStatus().getExitCode()); } }
private void checkRepository(BatchStatus status, ExitStatus exitStatus) { assertEquals(jobInstance, jobInstanceDao.getJobInstance(job.getName(), jobParameters)); // because map DAO stores in memory, it can be checked directly JobExecution jobExecution = jobExecutionDao.findJobExecutions(jobInstance).get(0); assertEquals(jobInstance.getId(), jobExecution.getJobId()); assertEquals(status, jobExecution.getStatus()); if (exitStatus != null) { assertEquals(exitStatus.getExitCode(), jobExecution.getExitStatus().getExitCode()); } }
@Transactional @Test public void testSaveAndGetExecutions() { List<StepExecution> stepExecutions = new ArrayList<>(); for (int i = 0; i < 3; i++) { StepExecution se = new StepExecution("step" + i, jobExecution); se.setStatus(BatchStatus.STARTED); se.setReadSkipCount(i); se.setProcessSkipCount(i); se.setWriteSkipCount(i); se.setProcessSkipCount(i); se.setRollbackCount(i); se.setLastUpdated(new Date(System.currentTimeMillis())); se.setReadCount(i); se.setFilterCount(i); se.setWriteCount(i); stepExecutions.add(se); } dao.saveStepExecutions(stepExecutions); for (int i = 0; i < 3; i++) { StepExecution retrieved = dao.getStepExecution(jobExecution, stepExecutions.get(i).getId()); assertStepExecutionsAreEqual(stepExecutions.get(i), retrieved); assertNotNull(retrieved.getVersion()); assertNotNull(retrieved.getJobExecution()); assertNotNull(retrieved.getJobExecution().getId()); assertNotNull(retrieved.getJobExecution().getJobId()); assertNotNull(retrieved.getJobExecution().getJobInstance()); } }
@Transactional @Test public void testSaveAndGetExecution() { stepExecution.setStatus(BatchStatus.STARTED); stepExecution.setReadSkipCount(7); stepExecution.setProcessSkipCount(2); stepExecution.setWriteSkipCount(5); stepExecution.setProcessSkipCount(11); stepExecution.setRollbackCount(3); stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); stepExecution.setReadCount(17); stepExecution.setFilterCount(15); stepExecution.setWriteCount(13); dao.saveStepExecution(stepExecution); StepExecution retrieved = dao.getStepExecution(jobExecution, stepExecution.getId()); assertStepExecutionsAreEqual(stepExecution, retrieved); assertNotNull(retrieved.getVersion()); assertNotNull(retrieved.getJobExecution()); assertNotNull(retrieved.getJobExecution().getId()); assertNotNull(retrieved.getJobExecution().getJobId()); assertNotNull(retrieved.getJobExecution().getJobInstance()); }
/** * * 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()); }
@Override public void beforeJob(JobExecution jobExecution) { Date date = jobExecution.getJobParameters().getDate("date"); MDC.put(JOB_EXECUTION_ID, jobExecution.getId().toString()); MDC.put(JOB_INSTANCE_ID, jobExecution.getJobId().toString()); MDC.put(DATE_PARAMETER, new SimpleDateFormat("yyyy-MM-dd").format(date)); }
private void throwJobFailedException(List<JobExecution> failedJobExecutions) { StringBuilder message = new StringBuilder("The following Jobs have failed: \n"); for (JobExecution failedJobExecution : failedJobExecutions) { message.append(String.format("Job %s failed during " + "execution for job instance id %s with jobExecutionId of %s \n", failedJobExecution.getJobInstance().getJobName(), failedJobExecution.getJobId(), failedJobExecution.getId())); } logger.error(message); throw new TaskException(message.toString()); } private JobParameters removeNonIdentifying(JobParameters parameters) {
private void throwJobFailedException(List<JobExecution> failedJobExecutions) { StringBuilder message = new StringBuilder("The following Jobs have failed: \n"); for (JobExecution failedJobExecution : failedJobExecutions) { message.append(String.format("Job %s failed during " + "execution for job instance id %s with jobExecutionId of %s \n", failedJobExecution.getJobInstance().getJobName(), failedJobExecution.getJobId(), failedJobExecution.getId())); } logger.error(message); throw new TaskException(message.toString()); } private JobParameters removeNonIdentifying(JobParameters parameters) {