List of usage examples for org.springframework.batch.core StepExecution getStatus
public BatchStatus getStatus()
From source file:com.vmware.bdd.manager.TestClusteringJobs.java
public static String stepsToString(Collection<StepExecution> ses) { StringBuilder sb = new StringBuilder(); for (StepExecution se : ses) { if (sb.length() > 0) { sb.append(", "); }/*from www. j a va 2s . c o m*/ sb.append(se.getStepName()).append(":").append(se.getStatus()).append("-") .append(se.getExecutionContext()); } return sb.toString(); }
From source file:io.spring.batch.integration.ExecutionToTweetTransformer.java
private BatchStatus endingBatchStatus(JobExecution execution) { BatchStatus status = execution.getStatus(); Collection<StepExecution> stepExecutions = execution.getStepExecutions(); if (stepExecutions.size() > 0) { for (StepExecution stepExecution : stepExecutions) { if (stepExecution.getStatus().equals(BatchStatus.FAILED)) { status = BatchStatus.FAILED; break; } else { status = BatchStatus.COMPLETED; }//from w w w . j ava 2 s . c om } } return status; }
From source file:fr.acxio.tools.agia.admin.StaleRunningJobsService.java
public void forceRunningJobsToFail() { if (logger.isInfoEnabled()) { logger.info("Reseting jobs..."); }// w ww . j a v a 2 s .com List<String> aJobNames = jobExplorer.getJobNames(); for (String aJobName : aJobNames) { Set<JobExecution> aJobExecutions = jobExplorer.findRunningJobExecutions(aJobName); for (JobExecution aJobExecution : aJobExecutions) { if (logger.isInfoEnabled()) { logger.info(" " + aJobName + " (" + aJobExecution.getId() + ")"); } aJobExecution.setEndTime(new Date()); aJobExecution.setStatus(BatchStatus.FAILED); aJobExecution.setExitStatus(ExitStatus.FAILED); jobRepository.update(aJobExecution); for (StepExecution aStepExecution : aJobExecution.getStepExecutions()) { if (aStepExecution.getStatus().isGreaterThan(BatchStatus.COMPLETED)) { if (logger.isInfoEnabled()) { logger.info(" " + aStepExecution.getStepName()); } aStepExecution.setEndTime(new Date()); aStepExecution.setStatus(BatchStatus.FAILED); aStepExecution.setExitStatus(ExitStatus.FAILED); jobRepository.update(aStepExecution); } } } } if (logger.isInfoEnabled()) { logger.info("Done."); } }
From source file:admin.jmx.SimpleStepExecutionMetrics.java
public int getFailureCount() { int count = 0; int start = 0; int pageSize = 100; Collection<StepExecution> stepExecutions; do {//from www .j a va 2s.c o m stepExecutions = jobService.listStepExecutionsForStep(jobName, stepName, start, pageSize); start += pageSize; for (StepExecution stepExecution : stepExecutions) { if (stepExecution.getStatus().isUnsuccessful()) { count++; } } } while (!stepExecutions.isEmpty()); return count; }
From source file:admin.jmx.SimpleStepExecutionMetrics.java
public String getLatestStatus() { StepExecution stepExecution = getLatestStepExecution(stepName); return stepExecution == null ? "NON" : stepExecution.getStatus().toString(); }
From source file:org.trpr.platform.batch.impl.spring.admin.repository.MapStepExecutionDao.java
/** * Returns a copy of {@link StepExecution}, by adding new Objects for every field(no references are passed) * /*from w ww .j ava 2s .c om*/ * @param original StepExecution to be copied * @return StepExecution copy */ private static StepExecution copy(StepExecution original) { StepExecution copy = new StepExecution(original.getStepName(), original.getJobExecution()); copy.setCommitCount(original.getCommitCount()); if (original.getEndTime() != null) { copy.setEndTime((Date) original.getEndTime().clone()); } //Warning: no deep copy if (original.getExitStatus() != null) { copy.setExitStatus(new ExitStatus(original.getExitStatus().getExitCode(), original.getExitStatus().getExitDescription())); } copy.setFilterCount(original.getFilterCount()); copy.setId(original.getId()); if (original.getLastUpdated() != null) { copy.setLastUpdated((Date) original.getLastUpdated().clone()); } copy.setProcessSkipCount(original.getProcessSkipCount()); copy.setReadCount(original.getReadCount()); copy.setReadSkipCount(original.getReadSkipCount()); copy.setRollbackCount(original.getRollbackCount()); if (original.getStartTime() != null) { copy.setStartTime((Date) original.getStartTime().clone()); } if (original.getStatus() != null) { copy.setStatus(BatchStatus.valueOf(original.getStatus().name())); } if (original.isTerminateOnly()) { copy.setTerminateOnly(); } copy.setVersion(original.getVersion()); copy.setWriteCount(original.getWriteCount()); copy.setWriteSkipCount(original.getWriteSkipCount()); return copy; }
From source file:es.fcs.batch.integration.chunk.MyChunkMessageChannelItemWriter.java
@Override public ExitStatus afterStep(StepExecution stepExecution) { if (!(stepExecution.getStatus() == BatchStatus.COMPLETED)) { return ExitStatus.EXECUTING; }/* w w w. ja v a 2s . com*/ long expecting = localState.getExpecting(); boolean timedOut; try { logger.debug("Waiting for results in step listener..."); timedOut = !waitForResults(); logger.debug("Finished waiting for results in step listener."); } catch (RuntimeException e) { logger.debug("Detected failure waiting for results in step listener.", e); stepExecution.setStatus(BatchStatus.FAILED); return ExitStatus.FAILED.addExitDescription(e.getClass().getName() + ": " + e.getMessage()); } finally { for (StepContribution contribution : getStepContributions()) { stepExecution.apply(contribution); } } if (timedOut) { stepExecution.setStatus(BatchStatus.FAILED); throw new ItemStreamException("Timed out waiting for back log at end of step"); } return ExitStatus.COMPLETED.addExitDescription("Waited for " + expecting + " results."); }
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 *//* w ww. j a v a2 s . c o 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: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);// w w w. j a v a2 s. 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.job.SimpleStepHandler.java
@Override public StepExecution handleStep(Step step, JobExecution execution) throws JobInterruptedException, JobRestartException, StartLimitExceededException { if (execution.isStopping()) { throw new JobInterruptedException("JobExecution interrupted."); }//w w w . j a va 2 s. c o m JobInstance jobInstance = execution.getJobInstance(); StepExecution lastStepExecution = jobRepository.getLastStepExecution(jobInstance, step.getName()); if (stepExecutionPartOfExistingJobExecution(execution, lastStepExecution)) { // If the last execution of this step was in the same job, it's // probably intentional so we want to run it again... logger.info(String.format( "Duplicate step [%s] detected in execution of job=[%s]. " + "If either step fails, both will be executed again on restart.", step.getName(), jobInstance.getJobName())); lastStepExecution = null; } StepExecution currentStepExecution = lastStepExecution; if (shouldStart(lastStepExecution, execution, step)) { currentStepExecution = execution.createStepExecution(step.getName()); boolean isRestart = (lastStepExecution != null && !lastStepExecution.getStatus().equals(BatchStatus.COMPLETED)); if (isRestart) { currentStepExecution.setExecutionContext(lastStepExecution.getExecutionContext()); if (lastStepExecution.getExecutionContext().containsKey("batch.executed")) { currentStepExecution.getExecutionContext().remove("batch.executed"); } } else { currentStepExecution.setExecutionContext(new ExecutionContext(executionContext)); } jobRepository.add(currentStepExecution); logger.info("Executing step: [" + step.getName() + "]"); try { step.execute(currentStepExecution); currentStepExecution.getExecutionContext().put("batch.executed", true); } catch (JobInterruptedException e) { // Ensure that the job gets the message that it is stopping // and can pass it on to other steps that are executing // concurrently. execution.setStatus(BatchStatus.STOPPING); throw e; } jobRepository.updateExecutionContext(execution); if (currentStepExecution.getStatus() == BatchStatus.STOPPING || currentStepExecution.getStatus() == BatchStatus.STOPPED) { // Ensure that the job gets the message that it is stopping execution.setStatus(BatchStatus.STOPPING); throw new JobInterruptedException("Job interrupted by step execution"); } } return currentStepExecution; }