Java Code Examples for org.springframework.batch.core.JobExecution#setJobInstance()

The following examples show how to use org.springframework.batch.core.JobExecution#setJobInstance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleJobService.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Override
public JobExecution getJobExecution(Long jobExecutionId) throws NoSuchJobExecutionException {
	JobExecution jobExecution = jobExecutionDao.getJobExecution(jobExecutionId);
	if (jobExecution == null) {
		throw new NoSuchJobExecutionException("There is no JobExecution with id=" + jobExecutionId);
	}
	jobExecution.setJobInstance(jobInstanceDao.getJobInstance(jobExecution));
	try {
		jobExecution.setExecutionContext(executionContextDao.getExecutionContext(jobExecution));
	}
	catch (Exception e) {
		logger.info("Cannot load execution context for job execution: " + jobExecution);
	}
	stepExecutionDao.addStepExecutions(jobExecution);
	return jobExecution;
}
 
Example 2
Source File: MapLightminJobExecutionDaoTest.java    From spring-batch-lightmin with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
    final MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean = new MapJobRepositoryFactoryBean();
    mapJobRepositoryFactoryBean.getObject();
    this.jobExecutionDao = mapJobRepositoryFactoryBean.getJobExecutionDao();
    this.jobInstanceDao = mapJobRepositoryFactoryBean.getJobInstanceDao();
    final MapJobExplorerFactoryBean mapJobExplorerFactoryBean = new MapJobExplorerFactoryBean(
            mapJobRepositoryFactoryBean);
    this.jobExplorer = mapJobExplorerFactoryBean.getObject();
    this.mapLightminJobExecutionDao = new MapLightminJobExecutionDao(this.jobExplorer);
    this.jobInstance = this.jobInstanceDao.createJobInstance("someJob", new JobParametersBuilder().toJobParameters());
    final List<JobExecution> jobExecutions = DomainTestHelper.createJobExecutions(JOB_EXECUTION_COUNT);
    for (final JobExecution jobExecution : jobExecutions) {
        jobExecution.setId(null);
        jobExecution.setJobInstance(this.jobInstance);
        this.jobExecutionDao.saveJobExecution(jobExecution);
    }
}
 
Example 3
Source File: ProtocolListenerTest.java    From spring-boot-starter-batch-web with Apache License 2.0 6 votes vote down vote up
@Test
public void createProtocol() throws Exception {
	// Given
	JobExecution jobExecution = new JobExecution(1L,
			new JobParametersBuilder().addString("test", "value").toJobParameters());
	jobExecution.setJobInstance(new JobInstance(1L, "test-job"));
	jobExecution.setCreateTime(new Date());
	jobExecution.setStartTime(new Date());
	jobExecution.setEndTime(new Date());
	jobExecution.setExitStatus(new ExitStatus("COMPLETED_WITH_ERRORS", "This is a default exit message"));
	jobExecution.getExecutionContext().put("jobCounter", 1);
	StepExecution stepExecution = jobExecution.createStepExecution("test-step-1");
	stepExecution.getExecutionContext().put("stepCounter", 1);
	ProtocolListener protocolListener = new ProtocolListener();
	// When
	protocolListener.afterJob(jobExecution);
	// Then
	String output = this.outputCapture.toString();
	assertThat(output, containsString("Protocol for test-job"));
	assertThat(output, containsString("COMPLETED_WITH_ERRORS"));
}
 
Example 4
Source File: DefaultJobService.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Override
public void attachJobInstance(final JobExecution jobExecution) {
    if (jobExecution != null) {
        if (jobExecution.getJobInstance() != null) {
            final JobInstance jobInstance = this.jobExplorer.getJobInstance(jobExecution.getJobInstance().getId());
            jobExecution.setJobInstance(jobInstance);
        } else {
            throw new SpringBatchLightminApplicationException("JobInstance of JobExecution with id:" + jobExecution.getJobId() + "is null, cannot provide information");
        }
    } else {
        throw new SpringBatchLightminApplicationException("jobExecution is null, cannot provide information");
    }
}
 
Example 5
Source File: OnJobExecutionFinishedEventListenerTest.java    From spring-batch-lightmin with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnApplicationEventJobExecution() {
    final JobInstance instance = new JobInstance(1L, "testJob");
    final JobExecution jobExecution = new JobExecution(1L);
    jobExecution.setJobInstance(instance);
    jobExecution.setExitStatus(ExitStatus.COMPLETED);
    final JobExecutionEvent jobExecutionEvent = new JobExecutionEvent(jobExecution, "testApplication");

    this.onJobExecutionFinishedEventListener.onApplicationEvent(jobExecutionEvent);
    Mockito.verify(this.jobExecutionEventPublisher, Mockito.times(1))
            .publishEvent(any(JobExecutionEventInfo.class));
}
 
Example 6
Source File: DeployerPartitionHandlerTests.java    From spring-cloud-task with Apache License 2.0 3 votes vote down vote up
private StepExecution createMasterStepExecution() {

		JobExecution jobExecution = new JobExecution(1L);
		jobExecution.setJobInstance(new JobInstance(2L, "partitionedJob"));

		StepExecution masterStepExecution = new StepExecution("masterStep", jobExecution);
		masterStepExecution.setId(3L);

		return masterStepExecution;
	}