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:
Michael Minella
2016-06-30 23:10:08 -05:00
committed by Glenn Renfro
parent a1c1dd161f
commit 57e9d4dcae
39 changed files with 369 additions and 142 deletions

View File

@@ -27,7 +27,7 @@ $ ./mvnw clean install
[source,shell,indent=2]
----
$ java -jar target/batch-events-1.0.0.BUILD-SNAPSHOT.jar --spring.cloud.stream.bindings.batch-events.contentType=application/json
$ java -jar target/batch-events-1.0.1.BUILD-SNAPSHOT.jar --spring.cloud.stream.bindings.batch-events.contentType=application/json
----
For example you can listen for specific job execution events on a specified channel with a Spring Cloud Stream Sink
@@ -35,7 +35,7 @@ like the log sink using the following:
[source,shell,indent=2]
----
$ java -jar <PATH_TO_LOG_SINK_JAR>/log-sink-rabbit-1.0.0.BUILD-SNAPSHOT.jar --server.port=9090
$ java -jar <PATH_TO_LOG_SINK_JAR>/log-sink-rabbit-1.0.1.BUILD-SNAPSHOT.jar --server.port=9090
--spring.cloud.stream.bindings.input.destination=job-execution-events
----

View File

@@ -34,14 +34,6 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-stream</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
@@ -65,6 +57,11 @@
<artifactId>spring-cloud-stream-test-support-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-starter</artifactId>
<version>1.0.1.BUILD-SNAPSHOT</version>
</dependency>
</dependencies>
<build>

View File

@@ -22,5 +22,5 @@ $ mvn clean package
[source,shell,indent=2]
----
$ java -jar target/batch-job-1.0.0.BUILD-SNAPSHOT.jar
$ java -jar target/batch-job-1.0.1.BUILD-SNAPSHOT.jar
----

View File

@@ -40,11 +40,8 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-batch</artifactId>
<artifactId>spring-cloud-task-starter</artifactId>
<version>1.0.1.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>

View File

@@ -22,7 +22,7 @@ $ export spring_datasource_url=jdbc:mysql://localhost:3306/<your database>
$ export spring_datasource_username=<your username>
$ export spring_datasource_password=<your password>
$ export spring_datasource_driverClassName=org.mariadb.jdbc.Driver
$ java -jar -Dspring.profiles.active=master target/partitioned-batch-job-1.0.0.BUILD-SNAPSHOT.jar
$ java -jar -Dspring.profiles.active=master target/partitioned-batch-job-1.0.1.BUILD-SNAPSHOT.jar
----
NOTE: This example will use require a MySql RDBMS repository and currently uses the mariadb jdbc driver to connect.

View File

@@ -40,7 +40,8 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-batch</artifactId>
<artifactId>spring-cloud-task-starter</artifactId>
<version>1.0.1.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
@@ -62,7 +63,7 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>

View File

@@ -38,6 +38,7 @@ import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.deployer.resource.maven.MavenResource;
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;
@@ -47,6 +48,7 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.io.Resource;
/**
* @author Michael Minella
@@ -69,6 +71,9 @@ public class JobConfiguration {
@Autowired
private ConfigurableApplicationContext context;
@Autowired
private DelegatingResourceLoader delegatingResourceLoader;
private static final int GRID_SIZE = 4;
@Bean
@@ -91,7 +96,7 @@ public class JobConfiguration {
@Bean
public PartitionHandler partitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer) throws Exception {
MavenResource resource = MavenResource.parse("io.spring.cloud:partitioned-batch-job:1.0.0.BUILD-SNAPSHOT");
Resource resource = delegatingResourceLoader.getResource("maven://io.spring.cloud:partitioned-batch-job:1.0.1.BUILD-SNAPSHOT");
DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, "workerStep");

View File

@@ -1,2 +1,3 @@
spring.application.name=Partitioned Batch Job Task
logging.level.org.springframework.cloud.task=DEBUG
maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot

View File

@@ -17,7 +17,7 @@ $ ./mvnw clean install
[source,shell,indent=2]
----
$ java -jar target/task-events-1.0.0.BUILD-SNAPSHOT.jar --spring.cloud.stream.bindings.task-events.contentType=application/json
$ java -jar target/task-events-1.0.1.BUILD-SNAPSHOT.jar --spring.cloud.stream.bindings.task-events.contentType=application/json
----
You can listen for the events on the task-events channel with a Spring Cloud Stream Sink
@@ -25,7 +25,7 @@ like the log sink using the following:
[source,shell,indent=2]
----
$ java -jar <PATH_TO_LOG_SINK_JAR>/log-sink-rabbit-1.0.0.BUILD-SNAPSHOT.jar --server.port=9090 --spring.cloud.stream.bindings.input.destination=task-events
$ java -jar <PATH_TO_LOG_SINK_JAR>/log-sink-rabbit-1.0.1.BUILD-SNAPSHOT.jar --server.port=9090 --spring.cloud.stream.bindings.input.destination=task-events
----
== Dependencies:

View File

@@ -41,12 +41,8 @@
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-stream</artifactId>
<artifactId>spring-cloud-task-starter</artifactId>
<version>1.0.1.BUILD-SNAPSHOT</version>
</dependency>
<dependency>

View File

@@ -40,7 +40,7 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-stream</artifactId>
<artifactId>spring-cloud-task-starter</artifactId>
<version>1.0.1.BUILD-SNAPSHOT</version>
</dependency>
<dependency>

View File

@@ -58,7 +58,7 @@ public class TaskProcessor {
}
properties.put("payload", message);
TaskLaunchRequest request = new TaskLaunchRequest(processorProperties.getUri(), null, properties);
TaskLaunchRequest request = new TaskLaunchRequest(processorProperties.getUri(), null, properties, null);
return new GenericMessage<TaskLaunchRequest>(request);
}

View File

@@ -16,15 +16,12 @@
package io.spring;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.springframework.cloud.stream.test.matcher.MessageQueueMatcher.receivesPayloadThat;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.stream.annotation.Bindings;
@@ -34,6 +31,10 @@ import org.springframework.cloud.task.launcher.TaskLaunchRequest;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.springframework.cloud.stream.test.matcher.MessageQueueMatcher.receivesPayloadThat;
/**
* @author Glenn Renfro
*/
@@ -56,7 +57,7 @@ public class TaskProcessorApplicationTests {
Map<String, String> properties = new HashMap();
properties.put("payload", DEFAULT_PAYLOAD);
TaskLaunchRequest expectedRequest = 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);
assertThat(collector.forChannel(channels.output()), receivesPayloadThat(is(expectedRequest)));
}

View File

@@ -44,7 +44,8 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-stream</artifactId>
<artifactId>spring-cloud-task-starter</artifactId>
<version>1.0.1.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>

View File

@@ -0,0 +1 @@
maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot

View File

@@ -16,15 +16,13 @@
package io.spring;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import java.util.HashMap;
import java.util.Map;
import io.spring.configuration.TaskSinkConfiguration;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.deployer.spi.task.LaunchState;
@@ -36,6 +34,9 @@ import org.springframework.context.ApplicationContext;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Glenn Renfro
*/
@@ -60,7 +61,7 @@ public class TaskSinkApplicationTests {
Map<String, String> properties = new HashMap();
properties.put("server.port", "0");
TaskLaunchRequest request = 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);
GenericMessage<TaskLaunchRequest> message = new GenericMessage<TaskLaunchRequest>(request);
this.sink.input().send(message);
assertEquals(LaunchState.complete, testTaskLauncher.status("TESTSTATUS").getState());

View File

@@ -0,0 +1 @@
maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot

View File

@@ -22,5 +22,5 @@ $ mvn clean package
[source,shell,indent=2]
----
$ java -jar target/timestamp-task-1.0.0.BUILD-SNAPSHOT.jar
$ java -jar target/timestamp-task-1.0.1.BUILD-SNAPSHOT.jar
----

View File

@@ -45,7 +45,8 @@
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-core</artifactId>
<artifactId>spring-cloud-task-starter</artifactId>
<version>1.0.1.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>