Refactored dependency management
Created a Spring Boot starter that can be used to configure Spring Cloud Task and it's related functionality. Updates per code review Removed autowiring of app context Refactored DeployerPartitionHandler to correctly use environment variables Exposed deployment properties of TaskLauncher Exposed deployment properties via the TaskLaunchRequest Updated based on code review
This commit is contained in:
committed by
Glenn Renfro
parent
a1c1dd161f
commit
57e9d4dcae
@@ -25,6 +25,7 @@ import org.springframework.batch.core.SkipListener;
|
||||
import org.springframework.batch.core.StepExecutionListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.stream.annotation.EnableBinding;
|
||||
@@ -54,6 +55,7 @@ import org.springframework.messaging.MessageChannel;
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnClass(Job.class)
|
||||
@ConditionalOnBean(value = { Job.class, TaskLifecycleListener.class })
|
||||
@ConditionalOnProperty(prefix = "spring.cloud.task.batch.events", name = "enabled", havingValue = "true", matchIfMissing = true)
|
||||
public class BatchEventAutoConfiguration {
|
||||
@@ -68,11 +70,12 @@ public class BatchEventAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public TaskBatchEventListenerBeanPostProcessor batchTaskExecutionListenerBeanPostProcessor() {
|
||||
public TaskBatchEventListenerBeanPostProcessor batchTaskEventListenerBeanPostProcessor() {
|
||||
return new TaskBatchEventListenerBeanPostProcessor();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@ConditionalOnClass(EnableBinding.class)
|
||||
@EnableBinding(BatchEventsChannels.class)
|
||||
@ConditionalOnMissingBean(name = JOB_EXECUTION_EVENTS_LISTENER)
|
||||
public static class JobExecutionListenerConfiguration {
|
||||
|
||||
@@ -32,7 +32,6 @@ import org.springframework.batch.core.step.item.SimpleChunkProvider;
|
||||
import org.springframework.batch.core.step.tasklet.Tasklet;
|
||||
import org.springframework.batch.core.step.tasklet.TaskletStep;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanPostProcessor;
|
||||
import org.springframework.cloud.task.batch.listener.BatchEventAutoConfiguration;
|
||||
|
||||
@@ -37,21 +37,25 @@ public class TaskLaunchRequest implements Serializable{
|
||||
private static final long serialVersionUID = 1L;
|
||||
private String uri;
|
||||
private List<String> commandlineArguments;
|
||||
private Map<String, String> properties;
|
||||
private Map<String, String> environmentProperties;
|
||||
private Map<String, String> deploymentProperties;
|
||||
|
||||
/**
|
||||
* Constructor for the TaskLaunchRequest;
|
||||
* @param uri the URI to the task artifact to be launched.
|
||||
* @param commandlineArguments list of commandlineArguments to be used by the task
|
||||
* @param properties is the environment variables for this task.
|
||||
* @param environmentProperties are the environment variables for this task.
|
||||
* @param deploymentProperties are the variables used to setup task on the platform.
|
||||
*/
|
||||
public TaskLaunchRequest(String uri, List<String> commandlineArguments,
|
||||
Map<String, String> properties) {
|
||||
Map<String, String> environmentProperties,
|
||||
Map<String, String> deploymentProperties) {
|
||||
Assert.hasText(uri, "uri must not be empty nor null.");
|
||||
|
||||
this.uri = uri;
|
||||
this.commandlineArguments = (commandlineArguments == null) ? new ArrayList<String>() : commandlineArguments;
|
||||
this.properties = properties == null ? new HashMap() : properties;
|
||||
this.environmentProperties = environmentProperties == null ? new HashMap<String, String>() : environmentProperties;
|
||||
this.deploymentProperties = deploymentProperties == null ? new HashMap<String, String>() : deploymentProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -73,8 +77,17 @@ public class TaskLaunchRequest implements Serializable{
|
||||
* @return map containing the environment variables for the task.
|
||||
*/
|
||||
|
||||
public Map<String, String> getProperties() {
|
||||
return properties;
|
||||
public Map<String, String> getEnvironmentProperties() {
|
||||
return environmentProperties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the properties used by a {@link org.springframework.cloud.deployer.spi.task.TaskLauncher}
|
||||
*
|
||||
* @return deployment properties
|
||||
*/
|
||||
public Map<String, String> getDeploymentProperties() {
|
||||
return deploymentProperties;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,7 +95,8 @@ public class TaskLaunchRequest implements Serializable{
|
||||
return "TaskLaunchRequest{" +
|
||||
"uri='" + uri + '\'' +
|
||||
", commandlineArguments=" + commandlineArguments +
|
||||
", properties=" + properties +
|
||||
", environmentProperties=" + environmentProperties +
|
||||
", deploymentProperties=" + deploymentProperties +
|
||||
'}';
|
||||
}
|
||||
|
||||
@@ -103,7 +117,11 @@ public class TaskLaunchRequest implements Serializable{
|
||||
if (!(commandlineArguments != null ? commandlineArguments.equals(that.commandlineArguments) : that.commandlineArguments == null)){
|
||||
return false;
|
||||
}
|
||||
return properties != null ? properties.equals(that.properties) : that.properties == null;
|
||||
if(!(deploymentProperties != null ? deploymentProperties.equals(that.deploymentProperties) : that.deploymentProperties == null))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return environmentProperties != null ? environmentProperties.equals(that.environmentProperties) : that.environmentProperties == null;
|
||||
|
||||
}
|
||||
|
||||
@@ -111,7 +129,8 @@ public class TaskLaunchRequest implements Serializable{
|
||||
public int hashCode() {
|
||||
int result = uri != null ? uri.hashCode() : 0;
|
||||
result = 31 * result + (commandlineArguments != null ? commandlineArguments.hashCode() : 0);
|
||||
result = 31 * result + (properties != null ? properties.hashCode() : 0);
|
||||
result = 31 * result + (environmentProperties != null ? environmentProperties.hashCode() : 0);
|
||||
result = 31 * result + (deploymentProperties != null ? deploymentProperties.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,21 +16,13 @@
|
||||
|
||||
package org.springframework.cloud.task.launcher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenProperties;
|
||||
import org.springframework.cloud.deployer.resource.maven.MavenResourceLoader;
|
||||
import org.springframework.cloud.deployer.resource.support.DelegatingResourceLoader;
|
||||
import org.springframework.cloud.deployer.spi.local.LocalDeployerProperties;
|
||||
import org.springframework.cloud.deployer.spi.local.LocalTaskLauncher;
|
||||
import org.springframework.cloud.deployer.spi.task.TaskLauncher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.ResourceLoader;
|
||||
|
||||
/**
|
||||
* Creates the appropriate Task Launcher Configuration based on the TaskLauncher
|
||||
@@ -51,26 +43,4 @@ public class TaskLauncherConfiguration {
|
||||
return new LocalTaskLauncher(new LocalDeployerProperties());
|
||||
}
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MavenResourceLoader mavenResourceLoader(MavenProperties properties) {
|
||||
return new MavenResourceLoader(properties);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(DelegatingResourceLoader.class)
|
||||
public DelegatingResourceLoader delegatingResourceLoader(MavenResourceLoader mavenResourceLoader) {
|
||||
Map<String, ResourceLoader> loaders = new HashMap<>();
|
||||
loaders.put("maven", mavenResourceLoader);
|
||||
return new DelegatingResourceLoader(loaders);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MavenProperties mavenProperties() {
|
||||
return new MavenConfigurationProperties();
|
||||
}
|
||||
|
||||
@ConfigurationProperties(prefix = "maven")
|
||||
static class MavenConfigurationProperties extends MavenProperties {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,8 +61,8 @@ public class TaskLauncherSink {
|
||||
Assert.notNull(taskLauncher, "TaskLauncher has not been initialized");
|
||||
logger.info("Launching Task for the following resource " + taskLaunchRequest);
|
||||
Resource resource = delegatingResourceLoader.getResource(taskLaunchRequest.getUri());
|
||||
AppDefinition definition = new AppDefinition("Task-" + taskLaunchRequest.hashCode(), taskLaunchRequest.getProperties());
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, null, taskLaunchRequest.getCommandlineArguments());
|
||||
AppDefinition definition = new AppDefinition("Task-" + taskLaunchRequest.hashCode(), taskLaunchRequest.getEnvironmentProperties());
|
||||
AppDeploymentRequest request = new AppDeploymentRequest(definition, resource, taskLaunchRequest.getDeploymentProperties(), taskLaunchRequest.getCommandlineArguments());
|
||||
taskLauncher.launch(request);
|
||||
}
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ public class TaskLauncherSinkTests {
|
||||
public void testNoTaskLauncher() {
|
||||
TaskLauncherSink sink = new TaskLauncherSink();
|
||||
sink.taskLauncherSink(new TaskLaunchRequest("maven://org.springframework.cloud.task.app:"
|
||||
+ "timestamp-task:jar:1.0.0.BUILD-SNAPSHOT",null, properties));
|
||||
+ "timestamp-task:jar:1.0.0.BUILD-SNAPSHOT",null, properties, null));
|
||||
}
|
||||
|
||||
private TaskConfiguration.TestTaskLauncher launchTask(List<String> commandLineArgs) {
|
||||
@@ -110,7 +110,7 @@ public class TaskLauncherSinkTests {
|
||||
context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
|
||||
TaskLaunchRequest request = new TaskLaunchRequest("maven://org.springframework.cloud.task.app:"
|
||||
+ "timestamp-task:jar:1.0.0.BUILD-SNAPSHOT",commandLineArgs, properties);
|
||||
+ "timestamp-task:jar:1.0.0.BUILD-SNAPSHOT",commandLineArgs, properties, null);
|
||||
GenericMessage<TaskLaunchRequest> message = new GenericMessage<>(request);
|
||||
this.sink.input().send(message);
|
||||
return testTaskLauncher;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot
|
||||
Reference in New Issue
Block a user