org.springframework.cloud.task.repository.TaskRepository Java Examples

The following examples show how to use org.springframework.cloud.task.repository.TaskRepository. 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: TestDependencies.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Bean
public TaskExecutionService taskService(LauncherRepository launcherRepository,
		AuditRecordService auditRecordService,
		TaskRepository taskRepository,
		TaskExecutionInfoService taskExecutionInfoService,
		TaskDeploymentRepository taskDeploymentRepository,
		TaskExecutionCreationService taskExecutionRepositoryService,
		TaskAppDeploymentRequestCreator taskAppDeploymentRequestCreator,
		TaskExplorer taskExplorer, DataflowTaskExecutionDao dataflowTaskExecutionDao,
		DataflowTaskExecutionMetadataDao dataflowTaskExecutionMetadataDao,
		OAuth2TokenUtilsService oauth2TokenUtilsService,
		TaskSaveService taskSaveService,
		TaskConfigurationProperties taskConfigurationProperties) {

	return new DefaultTaskExecutionService(
			launcherRepository, auditRecordService, taskRepository,
			taskExecutionInfoService, taskDeploymentRepository,
			taskExecutionRepositoryService, taskAppDeploymentRequestCreator,
			taskExplorer, dataflowTaskExecutionDao, dataflowTaskExecutionMetadataDao,
			oauth2TokenUtilsService, taskSaveService, taskConfigurationProperties);
}
 
Example #2
Source File: ComposedTaskRunnerStepFactoryTests.java    From composed-task-runner with Apache License 2.0 6 votes vote down vote up
@Bean
public TaskConfigurer taskConfigurer() {
	return new TaskConfigurer() {
		@Override
		public TaskRepository getTaskRepository() {
			return null;
		}

		@Override
		public PlatformTransactionManager getTransactionManager() {
			return null;
		}

		@Override
		public TaskExplorer getTaskExplorer() {
			return mock(TaskExplorer.class);
		}

		@Override
		public DataSource getTaskDataSource() {
			return mock(DataSource.class);
		}
	};
}
 
Example #3
Source File: TaskLifecycleListener.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
/**
 * @param taskRepository {@link TaskRepository} to record executions.
 * @param taskNameResolver {@link TaskNameResolver} used to determine task name for
 * task execution.
 * @param applicationArguments {@link ApplicationArguments} to be used for task
 * execution.
 * @param taskExplorer {@link TaskExplorer} to be used for task execution.
 * @param taskProperties {@link TaskProperties} to be used for the task execution.
 * @param taskListenerExecutorObjectFactory {@link TaskListenerExecutorObjectFactory}
 * to initialize TaskListenerExecutor for a task
 */
public TaskLifecycleListener(TaskRepository taskRepository,
		TaskNameResolver taskNameResolver, ApplicationArguments applicationArguments,
		TaskExplorer taskExplorer, TaskProperties taskProperties,
		TaskListenerExecutorObjectFactory taskListenerExecutorObjectFactory) {
	Assert.notNull(taskRepository, "A taskRepository is required");
	Assert.notNull(taskNameResolver, "A taskNameResolver is required");
	Assert.notNull(taskExplorer, "A taskExplorer is required");
	Assert.notNull(taskProperties, "TaskProperties is required");
	Assert.notNull(taskListenerExecutorObjectFactory,
			"A TaskListenerExecutorObjectFactory is required");

	this.taskRepository = taskRepository;
	this.taskNameResolver = taskNameResolver;
	this.applicationArguments = applicationArguments;
	this.taskExplorer = taskExplorer;
	this.taskProperties = taskProperties;
	this.taskListenerExecutorObjectFactory = taskListenerExecutorObjectFactory;
	this.taskMetrics = new TaskMetrics();
}
 
Example #4
Source File: JobDependencies.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public TaskExecutionService taskService(LauncherRepository launcherRepository,
		AuditRecordService auditRecordService, TaskRepository taskRepository,
		TaskExecutionInfoService taskExecutionInfoService,
		TaskDeploymentRepository taskDeploymentRepository,
		TaskExecutionCreationService taskExecutionRepositoryService,
		TaskAppDeploymentRequestCreator taskAppDeploymentRequestCreator,
		TaskExplorer taskExplorer, DataflowTaskExecutionDao dataflowTaskExecutionDao,
		DataflowTaskExecutionMetadataDao dataflowTaskExecutionMetadataDao,
		OAuth2TokenUtilsService oauth2TokenUtilsService,
		TaskSaveService taskSaveService, TaskConfigurationProperties taskConfigurationProperties) {
	return new DefaultTaskExecutionService(
			launcherRepository, auditRecordService,
			taskRepository,
			taskExecutionInfoService, taskDeploymentRepository,
			taskExecutionRepositoryService, taskAppDeploymentRequestCreator,
			taskExplorer, dataflowTaskExecutionDao,
			dataflowTaskExecutionMetadataDao, oauth2TokenUtilsService,
			taskSaveService, taskConfigurationProperties);
}
 
Example #5
Source File: TaskServiceDependencies.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Bean
public TaskExecutionService defaultTaskService(LauncherRepository launcherRepository,
		AuditRecordService auditRecordService, TaskRepository taskRepository,
		TaskExecutionInfoService taskExecutionInfoService,
		TaskDeploymentRepository taskDeploymentRepository,
		TaskExecutionCreationService taskExecutionRepositoryService,
		TaskAppDeploymentRequestCreator taskAppDeploymentRequestCreator,
		TaskExplorer taskExplorer, DataflowTaskExecutionDao dataflowTaskExecutionDao,
		DataflowTaskExecutionMetadataDao dataflowTaskExecutionMetadataDao,
		OAuth2TokenUtilsService oauth2TokenUtilsService,
		TaskSaveService taskSaveService) {
	DefaultTaskExecutionService taskExecutionService = new DefaultTaskExecutionService(
			launcherRepository, auditRecordService, taskRepository,
			taskExecutionInfoService, taskDeploymentRepository,
			taskExecutionRepositoryService, taskAppDeploymentRequestCreator,
			taskExplorer, dataflowTaskExecutionDao, dataflowTaskExecutionMetadataDao,
			oauth2TokenUtilsService, taskSaveService, this.taskConfigurationProperties);
	taskExecutionService.setAutoCreateTaskDefinitions(this.taskConfigurationProperties.isAutoCreateTaskDefinitions());
	return taskExecutionService;
}
 
Example #6
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
private void verifyTaskRepositoryConstructor(Integer maxExitMessage,
		Integer maxErrorMessage, TaskRepository taskRepository) {
	TaskExecution expectedTaskExecution = TaskExecutionCreator
			.createAndStoreTaskExecutionNoParams(taskRepository);
	expectedTaskExecution.setErrorMessage(new String(new char[maxErrorMessage + 1]));
	expectedTaskExecution.setExitMessage(new String(new char[maxExitMessage + 1]));
	expectedTaskExecution.setEndTime(new Date());
	expectedTaskExecution.setExitCode(0);

	TaskExecution actualTaskExecution = completeTaskExecution(expectedTaskExecution,
			taskRepository);
	assertThat(actualTaskExecution.getErrorMessage().length())
			.isEqualTo(maxErrorMessage.intValue());
	assertThat(actualTaskExecution.getExitMessage().length())
			.isEqualTo(maxExitMessage.intValue());
}
 
Example #7
Source File: TaskConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Bean
public TaskExecutionService taskService(LauncherRepository launcherRepository,
		AuditRecordService auditRecordService,
		TaskRepository taskRepository,
		TaskExecutionInfoService taskExecutionInfoService,
		TaskDeploymentRepository taskDeploymentRepository,
		TaskExecutionCreationService taskExecutionRepositoryService,
		TaskAppDeploymentRequestCreator taskAppDeploymentRequestCreator,
		TaskExplorer taskExplorer,
		DataflowTaskExecutionDao dataflowTaskExecutionDao,
		DataflowTaskExecutionMetadataDao dataflowTaskExecutionMetadataDao,
		@Nullable OAuth2TokenUtilsService oauth2TokenUtilsService,
		TaskSaveService taskSaveService) {
	DefaultTaskExecutionService defaultTaskExecutionService =  new DefaultTaskExecutionService(
			launcherRepository, auditRecordService, taskRepository,
			taskExecutionInfoService, taskDeploymentRepository, taskExecutionRepositoryService,
			taskAppDeploymentRequestCreator, taskExplorer, dataflowTaskExecutionDao,
			dataflowTaskExecutionMetadataDao, oauth2TokenUtilsService, taskSaveService,
			this.taskConfigurationProperties);
	defaultTaskExecutionService.setAutoCreateTaskDefinitions(this.taskConfigurationProperties.isAutoCreateTaskDefinitions());
	return defaultTaskExecutionService;
}
 
Example #8
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoConfigurationDisabled() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(AutoConfigurations.of(
					PropertyPlaceholderAutoConfiguration.class,
					SimpleTaskAutoConfiguration.class, SingleTaskConfiguration.class))
			.withPropertyValues("spring.cloud.task.autoconfiguration.enabled=false");
	Executable executable = () -> {
		applicationContextRunner.run((context) -> {
			context.getBean(TaskRepository.class);
		});
	};
	verifyExceptionThrown(NoSuchBeanDefinitionException.class, "No qualifying "
			+ "bean of type 'org.springframework.cloud.task.repository.TaskRepository' "
			+ "available", executable);
}
 
Example #9
Source File: ComposedTaskRunnerStepFactoryTests.java    From spring-cloud-dataflow with Apache License 2.0 6 votes vote down vote up
@Bean
public TaskConfigurer taskConfigurer() {
	return new TaskConfigurer() {
		@Override
		public TaskRepository getTaskRepository() {
			return null;
		}

		@Override
		public PlatformTransactionManager getTransactionManager() {
			return null;
		}

		@Override
		public TaskExplorer getTaskExplorer() {
			return mock(TaskExplorer.class);
		}

		@Override
		public DataSource getTaskDataSource() {
			return mock(DataSource.class);
		}
	};
}
 
Example #10
Source File: SimpleTaskAutoConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Test
public void testRepository() {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
							SimpleTaskAutoConfiguration.class,
							SingleTaskConfiguration.class));
	applicationContextRunner.run((context) -> {

		TaskRepository taskRepository = context.getBean(TaskRepository.class);
		assertThat(taskRepository).isNotNull();
		Class<?> targetClass = AopProxyUtils.ultimateTargetClass(taskRepository);
		assertThat(targetClass).isEqualTo(SimpleTaskRepository.class);
	});
}
 
Example #11
Source File: RepositoryTransactionManagerConfigurationTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private void testConfiguration(Class configurationClass) {
	ApplicationContextRunner applicationContextRunner = new ApplicationContextRunner()
			.withConfiguration(
					AutoConfigurations.of(PropertyPlaceholderAutoConfiguration.class,
							SimpleTaskAutoConfiguration.class, configurationClass))
			.withPropertyValues("application.name=transactionManagerTask");

	applicationContextRunner.run((context) -> {
		DataSource dataSource = context.getBean("dataSource", DataSource.class);

		int taskExecutionCount = JdbcTestUtils
				.countRowsInTable(new JdbcTemplate(dataSource), "TASK_EXECUTION");

		// Verify that the create call was rolled back
		assertThat(taskExecutionCount).isEqualTo(0);

		// Execute a new create call so that things close cleanly
		TaskRepository taskRepository = context.getBean("taskRepository",
				TaskRepository.class);

		TaskExecution taskExecution = taskRepository
				.createTaskExecution("transactionManagerTask");
		taskExecution = taskRepository.startTaskExecution(
				taskExecution.getExecutionId(), taskExecution.getTaskName(),
				new Date(), new ArrayList<>(0), null);

		TaskLifecycleListener listener = context.getBean(TaskLifecycleListener.class);

		ReflectionTestUtils.setField(listener, "taskExecution", taskExecution);
	});
}
 
Example #12
Source File: DeployerPartitionHandler.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
public DeployerPartitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer,
		Resource resource, String stepName, TaskRepository taskRepository) {
	Assert.notNull(taskLauncher, "A taskLauncher is required");
	Assert.notNull(jobExplorer, "A jobExplorer is required");
	Assert.notNull(resource, "A resource is required");
	Assert.hasText(stepName, "A step name is required");
	Assert.notNull(taskRepository, "A TaskRepository is required");

	this.taskLauncher = taskLauncher;
	this.jobExplorer = jobExplorer;
	this.resource = resource;
	this.stepName = stepName;
	this.taskRepository = taskRepository;
}
 
Example #13
Source File: SimpleTaskRepositoryJdbcTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private TaskExecution completeTaskExecution(TaskExecution expectedTaskExecution,
		TaskRepository taskRepository) {
	return taskRepository.completeTaskExecution(
			expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getExitCode(), new Date(),
			expectedTaskExecution.getExitMessage(),
			expectedTaskExecution.getErrorMessage());
}
 
Example #14
Source File: TaskLifecycleConfiguration.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
@Autowired
public TaskLifecycleConfiguration(TaskProperties taskProperties,
		ConfigurableApplicationContext context, TaskRepository taskRepository,
		TaskExplorer taskExplorer, TaskNameResolver taskNameResolver,
		ObjectProvider<ApplicationArguments> applicationArguments) {

	this.taskProperties = taskProperties;
	this.context = context;
	this.taskRepository = taskRepository;
	this.taskExplorer = taskExplorer;
	this.taskNameResolver = taskNameResolver;
	this.applicationArguments = applicationArguments.getIfAvailable();
}
 
Example #15
Source File: TaskExecutionCreator.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a sample TaskExecution and stores it in the taskRepository with params.
 * @param taskRepository the taskRepository where the taskExecution should be stored.
 * @return the taskExecution created.
 */
public static TaskExecution createAndStoreTaskExecutionWithParams(
		TaskRepository taskRepository) {
	TaskExecution expectedTaskExecution = TestVerifierUtils
			.createSampleTaskExecutionNoArg();
	List<String> params = new ArrayList<>();
	params.add(UUID.randomUUID().toString());
	params.add(UUID.randomUUID().toString());
	expectedTaskExecution.setArguments(params);
	expectedTaskExecution = taskRepository.createTaskExecution(expectedTaskExecution);
	return expectedTaskExecution;
}
 
Example #16
Source File: TaskExecutionCreator.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
/**
 * Updates a sample TaskExecution in the taskRepository.
 * @param taskRepository the taskRepository where the taskExecution should be updated.
 * @param expectedTaskExecution the expected task execution.
 * @return the taskExecution created.
 */
public static TaskExecution completeExecution(TaskRepository taskRepository,
		TaskExecution expectedTaskExecution) {
	return taskRepository.completeTaskExecution(
			expectedTaskExecution.getExecutionId(),
			expectedTaskExecution.getExitCode(), expectedTaskExecution.getEndTime(),
			expectedTaskExecution.getExitMessage(),
			expectedTaskExecution.getErrorMessage());
}
 
Example #17
Source File: DeployerPartitionHandlerTests.java    From spring-cloud-task with Apache License 2.0 5 votes vote down vote up
private void validateConstructorValidation(TaskLauncher taskLauncher,
		JobExplorer jobExplorer, Resource resource, String stepName,
		TaskRepository taskRepository, String expectedMessage) {
	try {
		new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName,
				taskRepository);
	}
	catch (IllegalArgumentException iae) {
		assertThat(iae.getMessage()).isEqualTo(expectedMessage);
	}
}
 
Example #18
Source File: TestConfiguration.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskRepository taskRepository() {
	return new SimpleTaskRepository(this.taskExecutionDaoFactoryBean);
}
 
Example #19
Source File: TestDefaultConfiguration.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskRepository taskRepository() {
	return new SimpleTaskRepository(this.factoryBean);
}
 
Example #20
Source File: DefaultTaskExecutionService.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
/**
 * Initializes the {@link DefaultTaskExecutionService}.
 *
 * @param launcherRepository the repository of task launcher used to launch task apps.
 * @param auditRecordService the audit record service
 * @param taskRepository the repository to use for accessing and updating task executions
 * @param taskExecutionInfoService the task execution info service
 * @param taskDeploymentRepository the repository to track task deployment
 * @param taskExecutionInfoService the service used to setup a task execution
 * @param taskExecutionRepositoryService the service used to create the task execution
 * @param taskAppDeploymentRequestCreator the task app deployment request creator
 * @param taskExplorer the task explorer
 * @param dataflowTaskExecutionDao the dataflow task execution dao
 * @param dataflowTaskExecutionMetadataDao repository used to manipulate task manifests
 * @param oauth2TokenUtilsService the oauth2 token server
 * @param taskSaveService the task save service
 */
public DefaultTaskExecutionService(LauncherRepository launcherRepository,
		AuditRecordService auditRecordService,
		TaskRepository taskRepository,
		TaskExecutionInfoService taskExecutionInfoService,
		TaskDeploymentRepository taskDeploymentRepository,
		TaskExecutionCreationService taskExecutionRepositoryService,
		TaskAppDeploymentRequestCreator taskAppDeploymentRequestCreator,
		TaskExplorer taskExplorer,
		DataflowTaskExecutionDao dataflowTaskExecutionDao,
		DataflowTaskExecutionMetadataDao dataflowTaskExecutionMetadataDao,
		OAuth2TokenUtilsService oauth2TokenUtilsService,
		TaskSaveService taskSaveService,
		TaskConfigurationProperties taskConfigurationProperties) {
	Assert.notNull(launcherRepository, "launcherRepository must not be null");
	Assert.notNull(auditRecordService, "auditRecordService must not be null");
	Assert.notNull(taskExecutionInfoService, "taskExecutionInfoService must not be null");
	Assert.notNull(taskRepository, "taskRepository must not be null");
	Assert.notNull(taskExecutionInfoService, "taskExecutionInfoService must not be null");
	Assert.notNull(taskDeploymentRepository, "taskDeploymentRepository must not be null");
	Assert.notNull(taskExecutionRepositoryService, "taskExecutionRepositoryService must not be null");
	Assert.notNull(taskAppDeploymentRequestCreator, "taskAppDeploymentRequestCreator must not be null");
	Assert.notNull(taskExplorer, "taskExplorer must not be null");
	Assert.notNull(dataflowTaskExecutionDao, "dataflowTaskExecutionDao must not be null");
	Assert.notNull(dataflowTaskExecutionMetadataDao, "dataflowTaskExecutionMetadataDao must not be null");
	Assert.notNull(taskSaveService, "taskSaveService must not be null");
	Assert.notNull(taskConfigurationProperties, "taskConfigurationProperties must not be null");

	this.oauth2TokenUtilsService = oauth2TokenUtilsService;
	this.launcherRepository = launcherRepository;
	this.auditRecordService = auditRecordService;
	this.taskRepository = taskRepository;
	this.taskExecutionInfoService = taskExecutionInfoService;
	this.taskDeploymentRepository = taskDeploymentRepository;
	this.taskExecutionRepositoryService = taskExecutionRepositoryService;
	this.taskAppDeploymentRequestCreator = taskAppDeploymentRequestCreator;
	this.taskExplorer = taskExplorer;
	this.dataflowTaskExecutionDao = dataflowTaskExecutionDao;
	this.dataflowTaskExecutionMetadataDao = dataflowTaskExecutionMetadataDao;
	this.taskSaveService = taskSaveService;
	this.taskConfigurationProperties = taskConfigurationProperties;
}
 
Example #21
Source File: DefaultTaskExecutionRepositoryService.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
public DefaultTaskExecutionRepositoryService(TaskRepository taskRepository) {
	Assert.notNull(taskRepository, "taskRepository must not be null");
	this.taskRepository = taskRepository;
}
 
Example #22
Source File: TaskExecutionCreator.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a sample TaskExecution and stores it in the taskRepository.
 * @param taskRepository the taskRepository where the taskExecution should be stored.
 * @return the taskExecution created.
 */
public static TaskExecution createAndStoreTaskExecutionNoParams(
		TaskRepository taskRepository) {
	TaskExecution expectedTaskExecution = taskRepository.createTaskExecution();
	return expectedTaskExecution;
}
 
Example #23
Source File: TaskConfiguration.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskExecutionCreationService taskExecutionRepositoryService(TaskRepository taskRepository) {
	return new DefaultTaskExecutionRepositoryService(taskRepository);
}
 
Example #24
Source File: TestDependencies.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskRepository taskRepository(DataSource dataSource) {
	return new SimpleTaskRepository(new TaskExecutionDaoFactoryBean(dataSource));
}
 
Example #25
Source File: TestDependencies.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskExecutionCreationService taskExecutionRepositoryService(TaskRepository taskRepository) {
	return new DefaultTaskExecutionRepositoryService(taskRepository);
}
 
Example #26
Source File: DefaultEnvironmentPostProcessorTests.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskRepository taskRepository() {
	return mock(TaskRepository.class);
}
 
Example #27
Source File: TaskServiceDependencies.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskRepository taskRepository(TaskExecutionDaoFactoryBean daoFactoryBean) {
	return new SimpleTaskRepository(daoFactoryBean);
}
 
Example #28
Source File: TaskServiceDependencies.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskExecutionCreationService taskExecutionRepositoryService(TaskRepository taskRepository) {
	return new DefaultTaskExecutionRepositoryService(taskRepository);
}
 
Example #29
Source File: JobDependencies.java    From spring-cloud-dataflow with Apache License 2.0 4 votes vote down vote up
@Bean
public TaskExecutionCreationService taskExecutionRepositoryService(TaskRepository taskRepository) {
	return new DefaultTaskExecutionRepositoryService(taskRepository);
}
 
Example #30
Source File: DefaultTaskConfigurer.java    From spring-cloud-task with Apache License 2.0 4 votes vote down vote up
@Override
public TaskRepository getTaskRepository() {
	return this.taskRepository;
}