List of usage examples for org.springframework.batch.core StepExecution getId
public Long getId()
From source file:org.seedstack.monitoring.batch.internal.rest.stepexecution.StepExecutionDetailsRepresentation.java
/** * Constructor that substitutes in null for the execution id. * * @param stepExecution the step execution *///from ww w . j a va2 s. co m public StepExecutionDetailsRepresentation(StepExecution stepExecution) { Assert.notNull(stepExecution.getId(), "The entity Id must be provided to re-hydrate an existing StepExecution"); this.stepName = stepExecution.getStepName(); this.commitCount = stepExecution.getCommitCount(); this.endTime = stepExecution.getEndTime() == null ? "" : timeFormat.format(stepExecution.getEndTime()); this.executionContext = stepExecution.getExecutionContext(); this.statusExitCode = stepExecution.getExitStatus() != null ? stepExecution.getExitStatus().getExitCode() : ""; this.statusExitDescription = stepExecution.getExitStatus() != null ? stepExecution.getExitStatus().getExitDescription() : ""; this.failureExceptions = stepExecution.getFailureExceptions(); this.filterCount = stepExecution.getFilterCount(); this.lastUpdated = stepExecution.getLastUpdated() == null ? "" : dateFormat.format(stepExecution.getLastUpdated()); this.processSkipCount = stepExecution.getProcessSkipCount(); this.readCount = stepExecution.getReadCount(); this.readSkipCount = stepExecution.getReadSkipCount(); this.rollbackCount = stepExecution.getRollbackCount(); this.startTime = timeFormat.format(stepExecution.getStartTime()); this.status = stepExecution.getStatus(); this.stepName = stepExecution.getStepName(); this.terminateOnly = stepExecution.isTerminateOnly(); this.writeCount = stepExecution.getWriteCount(); this.writeSkipCount = stepExecution.getWriteSkipCount(); }
From source file:admin.jmx.SimpleJobExecutionMetrics.java
private StepExecution getLatestStepExecution(JobExecution jobExecution) { Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions(); StepExecution stepExecution = null;/*from w w w . j a v a 2 s.c o m*/ if (!stepExecutions.isEmpty()) { Date latest = new Date(0L); for (StepExecution candidate : stepExecutions) { Date stepDate = candidate.getEndTime(); stepDate = stepDate == null ? new Date() : stepDate; if (stepDate.after(latest)) { latest = stepDate; stepExecution = candidate; } else if (stepExecution != null && stepDate.equals(latest) && candidate.getId() > stepExecution.getId()) { // Tie breaker using ID stepExecution = candidate; } } } return stepExecution; }
From source file:org.trpr.platform.batch.impl.spring.admin.SimpleJobService.java
/** * Interface method implementation/*from w w w . j a va2 s . c om*/ * @see org.springframework.batch.admin.service.JobService#getStepExecution(java.lang.Long, java.lang.Long) */ public StepExecution getStepExecution(Long jobExecutionId, Long stepExecutionId) throws NoSuchStepExecutionException, NoSuchJobExecutionException { for (String jobName : this.jobRegistry.getJobNames()) { for (JobInstance jobInstance : this.jobExplorer.getJobInstances(jobName, 0, Integer.MAX_VALUE)) { for (JobExecution jobExecution : this.jobExplorer.getJobExecutions(jobInstance)) { if (jobExecution.getId() == jobExecutionId) { for (StepExecution step : jobExecution.getStepExecutions()) { if (step.getId() == stepExecutionId) { return step; } } } } } } return null; }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java
@Override public void updateStepExecution(StepExecution stepExecution) { Assert.notNull(stepExecution.getJobExecutionId()); //If the job execution data doesn't exist, can't update if (!executionsByJobExecutionId.containsKey(stepExecution.getJobExecutionId())) { return;//from w w w . j a v a 2 s .com } 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); } }
From source file:org.springframework.batch.admin.jmx.StepExecutionServiceLevelMonitor.java
public void invoke(ProceedingJoinPoint joinPoint, final StepExecution stepExecution, Step step) throws Throwable { final AtomicBoolean finished = new AtomicBoolean(false); final StopWatch timer = new StopWatch(stepExecution.getStepName() + ":execution"); try {/*from w w w . j a v a 2 s . c o m*/ if (timeout > 0) { if (notificationPublisher != null) { Notification notification = new Notification("INFO", this, sequence++, "Starting:" + stepExecution); notificationPublisher.sendNotification(notification); } timer.start("StepExecution.Id:" + stepExecution.getId()); final long threshold = (long) (timeout * (1 - warningMargin)); Date warningTime = new Date(System.currentTimeMillis() + threshold); logger.debug("Scheduling warning after (ms) " + threshold); taskScheduler.schedule(new Runnable() { public void run() { if (!finished.get()) { logger.debug("Sending warning (step not complete after " + threshold + " ms): " + stepExecution); if (notificationPublisher != null) { Notification notification = new Notification("WARN", StepExecutionServiceLevelMonitor.this, sequence++, "Warning:" + stepExecution); notificationPublisher.sendNotification(notification); } } else { logger.debug("No warning necessary for " + stepExecution); } } }, warningTime); } joinPoint.proceed(); } finally { finished.set(true); if (timeout > 0) { timer.stop(); Executors.newSingleThreadScheduledExecutor().shutdown(); if (timer.getLastTaskTimeMillis() > timeout) { overruns++; logger.debug("Notifying overrun " + stepExecution); if (notificationPublisher != null) { Notification notification = new Notification("ERROR", this, sequence++, "Overrun:" + stepExecution); notificationPublisher.sendNotification(notification); } } } } }
From source file:org.springframework.batch.core.explore.support.SimpleJobExplorerIntegrationTests.java
@Test public void testGetStepExecution() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobInterruptedException, UnexpectedJobExecutionException { // Prepare the jobRepository for the test JobExecution jobExecution = jobRepository.createJobExecution("myJob", new JobParameters()); StepExecution stepExecution = jobExecution.createStepExecution("flowStep"); jobRepository.add(stepExecution);//from w w w. j av a 2s . c o m // Executed on the remote end in remote partitioning use case StepExecution jobExplorerStepExecution = jobExplorer.getStepExecution(jobExecution.getId(), stepExecution.getId()); flowStep.execute(jobExplorerStepExecution); assertEquals(BatchStatus.COMPLETED, jobExplorerStepExecution.getStatus()); }
From source file:org.springframework.batch.core.launch.support.SimpleJobOperator.java
@Override public Map<Long, String> getStepExecutionSummaries(long executionId) throws NoSuchJobExecutionException { JobExecution jobExecution = findExecutionById(executionId); Map<Long, String> map = new LinkedHashMap<Long, String>(); for (StepExecution stepExecution : jobExecution.getStepExecutions()) { map.put(stepExecution.getId(), stepExecution.toString()); }//from w w w. j a v a 2 s. c om return map; }
From source file:org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.java
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<Object[]>(); 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; }
From source file:org.springframework.batch.core.repository.dao.JdbcStepExecutionDao.java
@Override public void updateStepExecution(StepExecution stepExecution) { validateStepExecution(stepExecution); Assert.notNull(stepExecution.getId(), "StepExecution Id cannot be null. StepExecution must saved" + " before it can be updated."); // Do not check for existence of step execution considering // it is saved at every commit point. String exitDescription = truncateExitDescription(stepExecution.getExitStatus().getExitDescription()); // Attempt to prevent concurrent modification errors by blocking here if // someone is already trying to do it. synchronized (stepExecution) { Integer version = stepExecution.getVersion() + 1; Object[] parameters = new Object[] { stepExecution.getStartTime(), stepExecution.getEndTime(), stepExecution.getStatus().toString(), stepExecution.getCommitCount(), stepExecution.getReadCount(), stepExecution.getFilterCount(), stepExecution.getWriteCount(), stepExecution.getExitStatus().getExitCode(), exitDescription, version, stepExecution.getReadSkipCount(), stepExecution.getProcessSkipCount(), stepExecution.getWriteSkipCount(), stepExecution.getRollbackCount(), stepExecution.getLastUpdated(), stepExecution.getId(), stepExecution.getVersion() }; int count = getJdbcTemplate().update(getQuery(UPDATE_STEP_EXECUTION), parameters, new int[] { 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.INTEGER, Types.TIMESTAMP, Types.BIGINT, Types.INTEGER }); // Avoid concurrent modifications... if (count == 0) { int curentVersion = getJdbcTemplate().queryForObject(getQuery(CURRENT_VERSION_STEP_EXECUTION), new Object[] { stepExecution.getId() }, Integer.class); throw new OptimisticLockingFailureException( "Attempt to update step execution id=" + stepExecution.getId() + " with wrong version (" + stepExecution.getVersion() + "), where current version is " + curentVersion); }/*from w w w . j a v a 2s . c o m*/ stepExecution.incrementVersion(); } }
From source file:org.springframework.batch.core.repository.support.SimpleJobRepository.java
@Override public void update(StepExecution stepExecution) { validateStepExecution(stepExecution); Assert.notNull(stepExecution.getId(), "StepExecution must already be saved (have an id assigned)"); stepExecution.setLastUpdated(new Date(System.currentTimeMillis())); stepExecutionDao.updateStepExecution(stepExecution); checkForInterruption(stepExecution); }