List of usage examples for org.springframework.batch.core JobExecution JobExecution
public JobExecution(Long id)
From source file:org.springframework.batch.core.scope.StepScopePerformanceTests.java
@Before public void start() throws Exception { int count = doTest("vanilla", "warmup"); logger.info("Item count: " + count); StepSynchronizationManager.close();//from w w w .j ava2s . c o m StepSynchronizationManager.register(new StepExecution("step", new JobExecution(0L), 1L)); }
From source file:org.springframework.batch.core.step.tasklet.SystemCommandTaskletIntegrationTests.java
@Test public void testStopped() throws Exception { initializeTasklet();/*from ww w .j a va 2 s . c o m*/ tasklet.setJobExplorer(jobExplorer); tasklet.afterPropertiesSet(); tasklet.beforeStep(stepExecution); JobExecution stoppedJobExecution = new JobExecution(stepExecution.getJobExecution()); stoppedJobExecution.setStatus(BatchStatus.STOPPING); when(jobExplorer.getJobExecution(1L)).thenReturn(stepExecution.getJobExecution(), stepExecution.getJobExecution(), stoppedJobExecution); String command = System.getProperty("os.name").toLowerCase().contains("win") ? "ping 1.1.1.1 -n 1 -w 5000" : "sleep 15"; tasklet.setCommand(command); tasklet.setTerminationCheckInterval(10); tasklet.afterPropertiesSet(); StepContribution contribution = stepExecution.createStepContribution(); StepContext stepContext = new StepContext(stepExecution); ChunkContext chunkContext = new ChunkContext(stepContext); tasklet.execute(contribution, chunkContext); assertEquals(contribution.getExitStatus().getExitCode(), ExitStatus.STOPPED.getExitCode()); }
From source file:org.springframework.cloud.dataflow.server.batch.SimpleJobService.java
@Override public JobExecution restart(Long jobExecutionId, JobParameters params) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, NoSuchJobException, JobParametersInvalidException { JobExecution jobExecution = null;// w w w .j a v a2s . c om JobExecution target = getJobExecution(jobExecutionId); JobInstance lastInstance = target.getJobInstance(); if (jobLocator.getJobNames().contains(lastInstance.getJobName())) { Job job = jobLocator.getJob(lastInstance.getJobName()); jobExecution = jobLauncher.run(job, target.getJobParameters()); if (jobExecution.isRunning()) { activeExecutions.add(jobExecution); } } else { if (jsrJobOperator != null) { if (params != null) { jobExecution = new JobExecution(jsrJobOperator.restart(jobExecutionId, params.toProperties())); } else { jobExecution = new JobExecution(jsrJobOperator.restart(jobExecutionId, new Properties())); } } else { throw new NoSuchJobException( String.format("Can't find job associated with job execution id %s to restart", String.valueOf(jobExecutionId))); } } return jobExecution; }
From source file:org.springframework.cloud.dataflow.server.batch.SimpleJobService.java
@Override public JobExecution launch(String jobName, JobParameters jobParameters) throws NoSuchJobException, JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException { JobExecution jobExecution = null;//from w ww . jav a 2s . c o m if (jobLocator.getJobNames().contains(jobName)) { Job job = jobLocator.getJob(jobName); JobExecution lastJobExecution = jobRepository.getLastJobExecution(jobName, jobParameters); boolean restart = false; if (lastJobExecution != null) { BatchStatus status = lastJobExecution.getStatus(); if (status.isUnsuccessful() && status != BatchStatus.ABANDONED) { restart = true; } } if (job.getJobParametersIncrementer() != null && !restart) { jobParameters = job.getJobParametersIncrementer().getNext(jobParameters); } jobExecution = jobLauncher.run(job, jobParameters); if (jobExecution.isRunning()) { activeExecutions.add(jobExecution); } } else { if (jsrJobOperator != null) { jobExecution = new JobExecution(jsrJobOperator.start(jobName, jobParameters.toProperties())); } else { throw new NoSuchJobException( String.format("Unable to find job %s to launch", String.valueOf(jobName))); } } return jobExecution; }