private boolean isSameJobExecution(StepExecution stepExecution, StepExecution lastStepExecution) { if (stepExecution.getJobExecutionId()==null) { return lastStepExecution.getJobExecutionId()==null; } return stepExecution.getJobExecutionId().equals(lastStepExecution.getJobExecutionId()); }
/** * Detect whether a step execution belongs to this job execution. * @param jobExecution the current job execution * @param stepExecution an existing step execution * @return true if the {@link org.springframework.batch.core.StepExecution} is part of the {@link org.springframework.batch.core.JobExecution} */ private boolean stepExecutionPartOfExistingJobExecution(JobExecution jobExecution, StepExecution stepExecution) { return stepExecution != null && stepExecution.getJobExecutionId() != null && stepExecution.getJobExecutionId().equals(jobExecution.getId()); }
private void validateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution, "StepExecution cannot be null."); Assert.notNull(stepExecution.getStepName(), "StepExecution's step name cannot be null."); Assert.notNull(stepExecution.getJobExecutionId(), "StepExecution must belong to persisted JobExecution"); }
@Override public int hashCode() { Object jobExecutionId = getJobExecutionId(); Long id = getId(); return super.hashCode() + 31 * (stepName != null ? stepName.hashCode() : 0) + 91 * (jobExecutionId != null ? jobExecutionId.hashCode() : 0) + 59 * (id != null ? id.hashCode() : 0); }
@Override public boolean equals(Object obj) { Object jobExecutionId = getJobExecutionId(); if (jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) { return super.equals(obj); } StepExecution other = (StepExecution) obj; return stepName.equals(other.getStepName()) && (jobExecutionId.equals(other.getJobExecutionId())) && getId().equals(other.getId()); }
@Override public void saveStepExecution(StepExecution stepExecution) { Assert.isTrue(stepExecution.getId() == null, "stepExecution id was not null"); Assert.isTrue(stepExecution.getVersion() == null, "stepExecution version was not null"); Assert.notNull(stepExecution.getJobExecutionId(), "JobExecution must be saved already."); Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); if (executions == null) { executions = new ConcurrentHashMap<>(); executionsByJobExecutionId.put(stepExecution.getJobExecutionId(), executions); } stepExecution.setId(currentId.incrementAndGet()); stepExecution.incrementVersion(); StepExecution copy = copy(stepExecution); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); }
@Override public Collection<StepExecution> call() throws Exception { for(Iterator<StepExecution> stepExecutionIterator = split.iterator(); stepExecutionIterator.hasNext(); ) { StepExecution curStepExecution = stepExecutionIterator.next(); if(!result.contains(curStepExecution)) { StepExecution partitionStepExecution = jobExplorer.getStepExecution(masterStepExecution.getJobExecutionId(), curStepExecution.getId()); if(!partitionStepExecution.getStatus().isRunning()) { result.add(partitionStepExecution); } } } if(logger.isDebugEnabled()) { logger.debug(String.format("Currently waiting on %s partitions to finish", split.size())); } if(result.size() == split.size()) { return result; } else { return null; } } };
/** * Aggregates the input executions into the result {@link StepExecution} * delegating to the delegate aggregator once the input has been refreshed * from the {@link JobExplorer}. * * @see StepExecutionAggregator #aggregate(StepExecution, Collection) */ @Override public void aggregate(StepExecution result, Collection<StepExecution> executions) { Assert.notNull(result, "To aggregate into a result it must be non-null."); if (executions == null) { return; } Collection<StepExecution> updates = new ArrayList<>(); for (StepExecution stepExecution : executions) { Long id = stepExecution.getId(); Assert.state(id != null, "StepExecution has null id. It must be saved first: " + stepExecution); StepExecution update = jobExplorer.getStepExecution(stepExecution.getJobExecutionId(), id); Assert.state(update != null, "Could not reload StepExecution from JobRepository: " + stepExecution); updates.add(update); } delegate.aggregate(result, updates); }
@Override public void updateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution.getJobExecutionId(), "jobExecution id is null"); Map<Long, StepExecution> executions = executionsByJobExecutionId.get(stepExecution.getJobExecutionId()); Assert.notNull(executions, "step executions for given job execution are expected to be already saved"); final StepExecution persistedExecution = executionsByStepExecutionId.get(stepExecution.getId()); Assert.notNull(persistedExecution, "step execution is expected to be already saved"); synchronized (stepExecution) { if (!persistedExecution.getVersion().equals(stepExecution.getVersion())) { throw new OptimisticLockingFailureException("Attempt to update step execution id=" + stepExecution.getId() + " with wrong version (" + stepExecution.getVersion() + "), where current version is " + persistedExecution.getVersion()); } stepExecution.incrementVersion(); StepExecution copy = new StepExecution(stepExecution.getStepName(), stepExecution.getJobExecution()); copy(stepExecution, copy); executions.put(stepExecution.getId(), copy); executionsByStepExecutionId.put(stepExecution.getId(), copy); } }
/** * Test method for * {@link org.springframework.batch.core.JobExecution#getJobId()}. */ @Test public void testGetJobId() { assertEquals(23, execution.getJobExecutionId().longValue()); }
/** * Sends {@link StepExecutionRequest} objects to the request channel of the {@link MessagingTemplate}, and then * receives the result back as a list of {@link StepExecution} on a reply channel. Use the {@link #aggregate(List)} * method as an aggregator of the individual remote replies. The receive timeout needs to be set realistically in * the {@link MessagingTemplate} <b>and</b> the aggregator, so that there is a good chance of all work being done. * * @see PartitionHandler#handle(StepExecutionSplitter, StepExecution) */ public Collection<StepExecution> handle(StepExecutionSplitter stepExecutionSplitter, final StepExecution masterStepExecution) throws Exception { final Set<StepExecution> split = stepExecutionSplitter.split(masterStepExecution, gridSize); if(CollectionUtils.isEmpty(split)) { return split; } int count = 0; for (StepExecution stepExecution : split) { Message<StepExecutionRequest> request = createMessage(count++, split.size(), new StepExecutionRequest( stepName, stepExecution.getJobExecutionId(), stepExecution.getId()), replyChannel); if (logger.isDebugEnabled()) { logger.debug("Sending request: " + request); } messagingGateway.send(request); } if(!pollRepositoryForResults) { return receiveReplies(replyChannel); } else { return pollReplies(masterStepExecution, split); } }
jobExplorer.getJobExecution(chunkContext.getStepContext().getStepExecution().getJobExecutionId());
@Test public void testEqualsWithNullStepId() throws Exception { Step step = new StepSupport("name"); execution = newStepExecution(step, new Long(31)); assertEquals("name", execution.getStepName()); StepExecution stepExecution = newStepExecution(step, new Long(31)); assertEquals(stepExecution.getJobExecutionId(), execution.getJobExecutionId()); assertTrue(execution.equals(stepExecution)); }
private List<Object[]> buildStepExecutionParameters(StepExecution stepExecution) { Assert.isNull(stepExecution.getId(), "to-be-saved (not updated) StepExecution can't already have an id assigned"); Assert.isNull(stepExecution.getVersion(), "to-be-saved (not updated) StepExecution can't already have a version assigned"); validateStepExecution(stepExecution); stepExecution.setId(stepExecutionIncrementer.nextLongValue()); stepExecution.incrementVersion(); //Should be 0 List<Object[]> parameters = new ArrayList<>(); String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription()); Object[] parameterValues = new Object[] { stepExecution.getId(), stepExecution.getVersion(), stepExecution.getStepName(), stepExecution.getJobExecutionId(), stepExecution.getStartTime(), stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(), stepExecution.getExitStatus().getExitCode(), exitDescription, stepExecution.getReadSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getProcessSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated() }; Integer[] parameterTypes = new Integer[] { Types.BIGINT, Types.INTEGER, Types.VARCHAR, Types.BIGINT, Types.TIMESTAMP, Types.TIMESTAMP, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.INTEGER, Types.TIMESTAMP }; parameters.add(0, Arrays.copyOf(parameterValues,parameterValues.length)); parameters.add(1, Arrays.copyOf(parameterTypes,parameterTypes.length)); return parameters; }
private void assertStepExecutionsAreEqual(StepExecution expected, StepExecution actual) { assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getStartTime(), actual.getStartTime()); assertEquals(expected.getEndTime(), actual.getEndTime()); assertEquals(expected.getSkipCount(), actual.getSkipCount()); assertEquals(expected.getCommitCount(), actual.getCommitCount()); assertEquals(expected.getReadCount(), actual.getReadCount()); assertEquals(expected.getWriteCount(), actual.getWriteCount()); assertEquals(expected.getFilterCount(), actual.getFilterCount()); assertEquals(expected.getWriteSkipCount(), actual.getWriteSkipCount()); assertEquals(expected.getReadSkipCount(), actual.getReadSkipCount()); assertEquals(expected.getProcessSkipCount(), actual.getProcessSkipCount()); assertEquals(expected.getRollbackCount(), actual.getRollbackCount()); assertEquals(expected.getExitStatus(), actual.getExitStatus()); assertEquals(expected.getLastUpdated(), actual.getLastUpdated()); assertEquals(expected.getExitStatus(), actual.getExitStatus()); assertEquals(expected.getJobExecutionId(), actual.getJobExecutionId()); }
private void assertStepExecutionsAreEqual(StepExecution expected, StepExecution actual) { assertEquals(expected.getId(), actual.getId()); assertEquals(expected.getStartTime(), actual.getStartTime()); assertEquals(expected.getEndTime(), actual.getEndTime()); assertEquals(expected.getSkipCount(), actual.getSkipCount()); assertEquals(expected.getCommitCount(), actual.getCommitCount()); assertEquals(expected.getReadCount(), actual.getReadCount()); assertEquals(expected.getWriteCount(), actual.getWriteCount()); assertEquals(expected.getFilterCount(), actual.getFilterCount()); assertEquals(expected.getWriteSkipCount(), actual.getWriteSkipCount()); assertEquals(expected.getReadSkipCount(), actual.getReadSkipCount()); assertEquals(expected.getProcessSkipCount(), actual.getProcessSkipCount()); assertEquals(expected.getRollbackCount(), actual.getRollbackCount()); assertEquals(expected.getExitStatus(), actual.getExitStatus()); assertEquals(expected.getLastUpdated(), actual.getLastUpdated()); assertEquals(expected.getExitStatus(), actual.getExitStatus()); assertEquals(expected.getJobExecutionId(), actual.getJobExecutionId()); } }
/** * Detect whether a step execution belongs to this job execution. * @param jobExecution the current job execution * @param stepExecution an existing step execution * @return true if the {@link org.springframework.batch.core.StepExecution} is part of the {@link org.springframework.batch.core.JobExecution} */ private boolean stepExecutionPartOfExistingJobExecution(JobExecution jobExecution, StepExecution stepExecution) { return stepExecution != null && stepExecution.getJobExecutionId() != null && stepExecution.getJobExecutionId().equals(jobExecution.getId()); }
@Override public int hashCode() { Object jobExecutionId = getJobExecutionId(); Long id = getId(); return super.hashCode() + 31 * (stepName != null ? stepName.hashCode() : 0) + 91 * (jobExecutionId != null ? jobExecutionId.hashCode() : 0) + 59 * (id != null ? id.hashCode() : 0); }
@Override public boolean equals(Object obj) { Object jobExecutionId = getJobExecutionId(); if (jobExecutionId == null || !(obj instanceof StepExecution) || getId() == null) { return super.equals(obj); } StepExecution other = (StepExecution) obj; return stepName.equals(other.getStepName()) && (jobExecutionId.equals(other.getJobExecutionId())) && getId().equals(other.getId()); }
@Override public StepExecutionProgressInfoResource toResource(StepExecutionProgressInfo entity) { return createResourceWithId(entity.getStepExecutionId(), entity, entity.getStepExecution().getJobExecutionId()); }