org.springframework.cloud.task.repository.dao.TaskExecutionDao Java Examples

The following examples show how to use org.springframework.cloud.task.repository.dao.TaskExecutionDao. 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: JobExecutionUtils.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
static MockMvc createBaseJobExecutionMockMvc(JobRepository jobRepository, TaskBatchDao taskBatchDao,
		TaskExecutionDao taskExecutionDao, WebApplicationContext wac, RequestMappingHandlerAdapter adapter) {
	MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(wac)
			.defaultRequest(get("/").accept(MediaType.APPLICATION_JSON)).build();
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_ORIG, 1);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_FOO, 1);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_FOOBAR, 2);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_COMPLETED, 1, BatchStatus.COMPLETED);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_STARTED, 1, BatchStatus.STARTED);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_STOPPED, 1, BatchStatus.STOPPED);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_FAILED1, 1, BatchStatus.FAILED);
	JobExecutionUtils.createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, JOB_NAME_FAILED2, 1, BatchStatus.FAILED);
	for (HttpMessageConverter<?> converter : adapter.getMessageConverters()) {
		if (converter instanceof MappingJackson2HttpMessageConverter) {
			final MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
			jacksonConverter.getObjectMapper().addMixIn(StepExecution.class, StepExecutionJacksonMixIn.class);
			jacksonConverter.getObjectMapper().addMixIn(ExecutionContext.class, ExecutionContextJacksonMixIn.class);
			jacksonConverter.getObjectMapper().setDateFormat(new ISO8601DateFormatWithMilliSeconds());
		}
	}
	return mockMvc;
}
 
Example #2
Source File: JobExecutionUtils.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
private static void createSampleJob(JobRepository jobRepository, TaskBatchDao taskBatchDao,
		TaskExecutionDao taskExecutionDao, String jobName,
		int jobExecutionCount, BatchStatus status) {
	JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters());
	TaskExecution taskExecution = taskExecutionDao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null);
	JobExecution jobExecution;

	for (int i = 0; i < jobExecutionCount; i++) {
		jobExecution = jobRepository.createJobExecution(instance, new JobParameters(), null);
		StepExecution stepExecution = new StepExecution("foo", jobExecution, 1L);
		stepExecution.setId(null);
		jobRepository.add(stepExecution);
		taskBatchDao.saveRelationship(taskExecution, jobExecution);
		jobExecution.setStatus(status);
		jobExecution.setStartTime(new Date());
		if (BatchStatus.STOPPED.equals(status)) {
			jobExecution.setEndTime(new Date());
		}
		jobRepository.update(jobExecution);
	}
}
 
Example #3
Source File: DefaultTaskJobServiceTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
private void createSampleJob(JobRepository jobRepository, TaskBatchDao taskBatchDao,
		TaskExecutionDao taskExecutionDao, String jobName,
		int jobExecutionCount, BatchStatus status) {
	JobInstance instance = jobRepository.createJobInstance(jobName, new JobParameters());
	TaskExecution taskExecution = taskExecutionDao.createTaskExecution(jobName, new Date(), new ArrayList<>(), null);
	JobExecution jobExecution;

	for (int i = 0; i < jobExecutionCount; i++) {
		jobExecution = jobRepository.createJobExecution(instance,
				this.jobParameters, null);
		StepExecution stepExecution = new StepExecution("foo", jobExecution, 1L);
		stepExecution.setId(null);
		jobRepository.add(stepExecution);
		taskBatchDao.saveRelationship(taskExecution, jobExecution);
		jobExecution.setStatus(status);
		jobExecution.setStartTime(new Date());
		jobRepository.update(jobExecution);
	}
}
 
Example #4
Source File: SimpleTaskRepository.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
public SimpleTaskRepository(FactoryBean<TaskExecutionDao> taskExecutionDaoFactoryBean,
		Integer maxExitMessageSize, Integer maxTaskNameSize,
		Integer maxErrorMessageSize) {
	Assert.notNull(taskExecutionDaoFactoryBean,
			"A FactoryBean that provides a TaskExecutionDao is required");
	if (maxTaskNameSize != null) {
		this.maxTaskNameSize = maxTaskNameSize;
	}
	if (maxExitMessageSize != null) {
		this.maxExitMessageSize = maxExitMessageSize;
	}
	if (maxErrorMessageSize != null) {
		this.maxErrorMessageSize = maxErrorMessageSize;
	}
	this.taskExecutionDaoFactoryBean = taskExecutionDaoFactoryBean;
}
 
Example #5
Source File: TaskExecutionDaoFactoryBeanTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultDataSourceConfiguration() throws Exception {
	this.context = new AnnotationConfigApplicationContext(
			DefaultDataSourceConfiguration.class);

	DataSource dataSource = this.context.getBean(DataSource.class);

	TaskExecutionDaoFactoryBean factoryBean = new TaskExecutionDaoFactoryBean(
			dataSource);
	TaskExecutionDao taskExecutionDao = factoryBean.getObject();

	assertThat(taskExecutionDao instanceof JdbcTaskExecutionDao).isTrue();

	TaskExecutionDao taskExecutionDao2 = factoryBean.getObject();

	assertThat(taskExecutionDao == taskExecutionDao2).isTrue();
}
 
Example #6
Source File: SimpleTaskRepository.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
public SimpleTaskRepository(
		FactoryBean<TaskExecutionDao> taskExecutionDaoFactoryBean) {
	Assert.notNull(taskExecutionDaoFactoryBean,
			"A FactoryBean that provides a TaskExecutionDao is required");

	this.taskExecutionDaoFactoryBean = taskExecutionDaoFactoryBean;
}
 
Example #7
Source File: TaskExecutionDaoFactoryBean.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Override
public TaskExecutionDao getObject() throws Exception {
	if (this.dao == null) {
		if (this.dataSource != null) {
			buildTaskExecutionDao(this.dataSource);
		}
		else {
			this.dao = new MapTaskExecutionDao();
		}
	}

	return this.dao;
}
 
Example #8
Source File: TaskExecutionDaoFactoryBeanTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
public void testMapTaskExecutionDaoWithoutAppContext() throws Exception {
	TaskExecutionDaoFactoryBean factoryBean = new TaskExecutionDaoFactoryBean();
	TaskExecutionDao taskExecutionDao = factoryBean.getObject();

	assertThat(taskExecutionDao instanceof MapTaskExecutionDao).isTrue();

	TaskExecutionDao taskExecutionDao2 = factoryBean.getObject();

	assertThat(taskExecutionDao == taskExecutionDao2).isTrue();
}
 
Example #9
Source File: TaskExecutionDaoFactoryBeanTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
public void testSettingTablePrefix() throws Exception {
	this.context = new AnnotationConfigApplicationContext(
			DefaultDataSourceConfiguration.class);

	DataSource dataSource = this.context.getBean(DataSource.class);

	TaskExecutionDaoFactoryBean factoryBean = new TaskExecutionDaoFactoryBean(
			dataSource, "foo_");
	TaskExecutionDao taskExecutionDao = factoryBean.getObject();

	assertThat(ReflectionTestUtils.getField(taskExecutionDao, "tablePrefix"))
			.isEqualTo("foo_");
}
 
Example #10
Source File: TaskLauncherTaskletTests.java    From composed-task-runner with Apache License 2.0 4 votes vote down vote up
@Bean
TaskExecutionDao taskExecutionDao(DataSource dataSource) {
	return new JdbcTaskExecutionDao(dataSource);
}
 
Example #11
Source File: TaskLauncherTaskletTests.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
TaskExecutionDao taskExecutionDao(DataSource dataSource) {
	return new JdbcTaskExecutionDao(dataSource);
}
 
Example #12
Source File: JobExecutionUtils.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
private static void createSampleJob(JobRepository jobRepository,
		TaskBatchDao taskBatchDao, TaskExecutionDao taskExecutionDao,
		String jobName, int jobExecutionCount) {
	createSampleJob(jobRepository, taskBatchDao, taskExecutionDao, jobName,
			jobExecutionCount, BatchStatus.UNKNOWN);
}
 
Example #13
Source File: SimpleTaskRepository.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieves the taskExecutionDao associated with this repository.
 * @return the taskExecutionDao
 */
public TaskExecutionDao getTaskExecutionDao() {
	initialize();
	return this.taskExecutionDao;
}
 
Example #14
Source File: TaskExecutionDaoFactoryBean.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Override
public Class<?> getObjectType() {
	return TaskExecutionDao.class;
}
 
Example #15
Source File: TaskExecutionDaoFactoryBeanTests.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetObjectType() {
	assertThat(TaskExecutionDao.class)
			.isEqualTo(new TaskExecutionDaoFactoryBean().getObjectType());
}