From 57e9d4dcaedb55df5e05cbba89df03d5a81522c3 Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Thu, 30 Jun 2016 23:10:08 -0500 Subject: [PATCH] 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 --- pom.xml | 8 +- spring-cloud-task-batch/pom.xml | 6 ++ .../partition/DeployerPartitionHandler.java | 45 ++++++--- .../DeployerPartitionHandlerTests.java | 94 +++++++++++++++---- spring-cloud-task-core/pom.xml | 13 ++- .../ResourceLoadingAutoConfiguration.java | 82 ++++++++++++++++ .../main/resources/META-INF/spring.factories | 1 + spring-cloud-task-dependencies/pom.xml | 26 +++-- .../src/main/asciidoc/batch.adoc | 20 ++-- .../src/main/asciidoc/stream.adoc | 4 + spring-cloud-task-integration-tests/pom.xml | 9 ++ .../batch-events/README.adoc | 4 +- .../batch-events/pom.xml | 13 +-- .../batch-job/README.adoc | 2 +- spring-cloud-task-samples/batch-job/pom.xml | 7 +- .../partitioned-batch-job/README.adoc | 2 +- .../partitioned-batch-job/pom.xml | 5 +- .../main/java/io/spring/JobConfiguration.java | 7 +- .../src/main/resources/application.properties | 1 + .../task-events/README.adoc | 4 +- spring-cloud-task-samples/task-events/pom.xml | 8 +- .../taskprocessor/pom.xml | 2 +- .../main/java/io/spring/TaskProcessor.java | 2 +- .../spring/TaskProcessorApplicationTests.java | 11 ++- spring-cloud-task-samples/tasksink/pom.xml | 3 +- .../src/main/resources/application.properties | 1 + .../io/spring/TaskSinkApplicationTests.java | 9 +- .../src/test/resources/application.properties | 1 + .../timestamp/README.adoc | 2 +- spring-cloud-task-samples/timestamp/pom.xml | 3 +- spring-cloud-task-starter/pom.xml | 31 ++++++ spring-cloud-task-stream/pom.xml | 3 + .../listener/BatchEventAutoConfiguration.java | 5 +- ...skBatchEventListenerBeanPostProcessor.java | 1 - .../task/launcher/TaskLaunchRequest.java | 37 ++++++-- .../launcher/TaskLauncherConfiguration.java | 30 ------ .../cloud/task/launcher/TaskLauncherSink.java | 4 +- .../task/launcher/TaskLauncherSinkTests.java | 4 +- .../src/test/resources/application.properties | 1 + 39 files changed, 369 insertions(+), 142 deletions(-) create mode 100644 spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/ResourceLoadingAutoConfiguration.java create mode 100644 spring-cloud-task-core/src/main/resources/META-INF/spring.factories create mode 100644 spring-cloud-task-samples/tasksink/src/main/resources/application.properties create mode 100644 spring-cloud-task-samples/tasksink/src/test/resources/application.properties create mode 100644 spring-cloud-task-starter/pom.xml create mode 100644 spring-cloud-task-stream/src/test/resources/application.properties diff --git a/pom.xml b/pom.xml index 08094199..00ac47f7 100755 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ spring-cloud-task-docs spring-cloud-task-batch spring-cloud-task-stream - spring-cloud-task-integration-tests + spring-cloud-task-starter @@ -224,5 +224,11 @@ spring-cloud-task-samples + + integration-test + + spring-cloud-task-integration-tests + + diff --git a/spring-cloud-task-batch/pom.xml b/spring-cloud-task-batch/pom.xml index 42f72278..3ad4d37c 100644 --- a/spring-cloud-task-batch/pom.xml +++ b/spring-cloud-task-batch/pom.xml @@ -29,6 +29,11 @@ spring-cloud-deployer-local test + + org.springframework.cloud + spring-cloud-deployer-resource-support + true + org.springframework.batch spring-batch-integration @@ -43,6 +48,7 @@ org.springframework spring-test + test junit diff --git a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandler.java b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandler.java index d69453c9..0119d2c9 100644 --- a/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandler.java +++ b/spring-cloud-task-batch/src/main/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandler.java @@ -105,6 +105,8 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw private Environment environment; + private Map deploymentProperties; + public DeployerPartitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer, Resource resource, @@ -168,6 +170,15 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw this.timeout = timeout; } + /** + * Map of deployment properties to be used by the {@link TaskLauncher} + * + * @param deploymentProperties + */ + public void setDeploymentProperties(Map deploymentProperties) { + this.deploymentProperties = deploymentProperties; + } + @BeforeTask public void beforeTask(TaskExecution taskExecution) { this.taskExecution = taskExecution; @@ -213,32 +224,38 @@ public class DeployerPartitionHandler implements PartitionHandler, EnvironmentAw } private void launchWorker(StepExecution workerStepExecution) { - //TODO: Refactor these to be passed as command line args once SCD-20 is complete - // https://github.com/spring-cloud/spring-cloud-deployer/issues/20 - Map arguments = getArguments(this.taskExecution.getArguments()); - arguments.put(SPRING_CLOUD_TASK_JOB_EXECUTION_ID, - String.valueOf(workerStepExecution.getJobExecution().getId())); - arguments.put(SPRING_CLOUD_TASK_STEP_EXECUTION_ID, - String.valueOf(workerStepExecution.getId())); - arguments.put(SPRING_CLOUD_TASK_STEP_NAME, this.stepName); + List arguments = new ArrayList<>(); + arguments.addAll(this.taskExecution.getArguments()); + arguments.add(formatArgument(SPRING_CLOUD_TASK_JOB_EXECUTION_ID, + String.valueOf(workerStepExecution.getJobExecution().getId()))); + arguments.add(formatArgument(SPRING_CLOUD_TASK_STEP_EXECUTION_ID, + String.valueOf(workerStepExecution.getId()))); + arguments.add(formatArgument(SPRING_CLOUD_TASK_STEP_NAME, this.stepName)); + + Map environmentProperties = new HashMap<>(this.environmentProperties.size()); + environmentProperties.putAll(getCurrentEnvironmentProperties()); + environmentProperties.putAll(this.environmentProperties); AppDefinition definition = new AppDefinition(String.format("%s:%s:%s", taskExecution.getTaskName(), workerStepExecution.getJobExecution().getJobInstance().getJobName(), workerStepExecution.getStepName()), - arguments); - - Map environmentProperties = new HashMap<>(this.environmentProperties.size()); - environmentProperties.putAll(getCurrentEnvironmentProperties()); - environmentProperties.putAll(this.environmentProperties); + environmentProperties); AppDeploymentRequest request = - new AppDeploymentRequest(definition, this.resource, environmentProperties); + new AppDeploymentRequest(definition, + this.resource, + this.deploymentProperties, + arguments); taskLauncher.launch(request); } + private String formatArgument(String key, String value) { + return String.format("--%s=%s", key, value); + } + private Collection pollReplies(final StepExecution masterStepExecution, final Set executed, final Set candidates, diff --git a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java index 15470461..6d295831 100644 --- a/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java +++ b/spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/partition/DeployerPartitionHandlerTests.java @@ -147,9 +147,9 @@ public class DeployerPartitionHandlerTests { AppDefinition appDefinition = request.getDefinition(); assertEquals("partitionedJobTask:partitionedJob:step1:partition1", appDefinition.getName()); - assertEquals("1", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)); - assertEquals("4", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)); - assertEquals("step1", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))); assertEquals(1, results.size()); StepExecution resultStepExecution = results.iterator().next(); @@ -344,16 +344,16 @@ public class DeployerPartitionHandlerTests { AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue(); assertEquals(this.resource, request.getResource()); - assertEquals(2, request.getDeploymentProperties().size()); - assertEquals("bar", request.getDeploymentProperties().get("foo")); - assertEquals("qux", request.getDeploymentProperties().get("baz")); + assertEquals(2, request.getDefinition().getProperties().size()); + assertEquals("bar", request.getDefinition().getProperties().get("foo")); + assertEquals("qux", request.getDefinition().getProperties().get("baz")); AppDefinition appDefinition = request.getDefinition(); assertEquals("partitionedJobTask:partitionedJob:step1:partition1", appDefinition.getName()); - assertEquals("1", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)); - assertEquals("4", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)); - assertEquals("step1", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))); assertEquals(1, results.size()); StepExecution resultStepExecution = results.iterator().next(); @@ -361,6 +361,10 @@ public class DeployerPartitionHandlerTests { assertEquals("step1:partition1", resultStepExecution.getStepName()); } + private String formatArgs(String key, String value) { + return String.format("--%s=%s", key, value); + } + @Test public void testOverridingEnvironmentProperties() throws Exception { @@ -399,17 +403,17 @@ public class DeployerPartitionHandlerTests { AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue(); assertEquals(this.resource, request.getResource()); - assertEquals(3, request.getDeploymentProperties().size()); - assertEquals("bar", request.getDeploymentProperties().get("foo")); - assertEquals("qux", request.getDeploymentProperties().get("baz")); - assertEquals("batch", request.getDeploymentProperties().get("task")); + assertEquals(3, request.getDefinition().getProperties().size()); + assertEquals("bar", request.getDefinition().getProperties().get("foo")); + assertEquals("qux", request.getDefinition().getProperties().get("baz")); + assertEquals("batch", request.getDefinition().getProperties().get("task")); AppDefinition appDefinition = request.getDefinition(); assertEquals("partitionedJobTask:partitionedJob:step1:partition1", appDefinition.getName()); - assertEquals("1", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)); - assertEquals("4", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)); - assertEquals("step1", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))); assertEquals(1, results.size()); StepExecution resultStepExecution = results.iterator().next(); @@ -539,6 +543,58 @@ public class DeployerPartitionHandlerTests { validateStepExecutionResults(results); } + @Test + public void testDeployerProperties() throws Exception { + + StepExecution masterStepExecution = createMasterStepExecution(); + JobExecution jobExecution = masterStepExecution.getJobExecution(); + + StepExecution workerStepExecutionStart = getStepExecutionStart(jobExecution, 4L); + StepExecution workerStepExecutionFinish = getStepExecutionFinish(workerStepExecutionStart, BatchStatus.COMPLETED); + + DeployerPartitionHandler handler = new DeployerPartitionHandler(this.taskLauncher, this.jobExplorer, this.resource, "step1"); + handler.setEnvironment(this.environment); + + Map deploymentProperties = new HashMap<>(2); + deploymentProperties.put("foo", "bar"); + deploymentProperties.put("baz", "qux"); + + handler.setDeploymentProperties(deploymentProperties); + + TaskExecution taskExecution = new TaskExecution(); + taskExecution.setTaskName("partitionedJobTask"); + + Set stepExecutions = new HashSet<>(); + stepExecutions.add(workerStepExecutionStart); + when(this.splitter.split(masterStepExecution, 1)).thenReturn(stepExecutions); + + when(this.jobExplorer.getStepExecution(1L, 4L)).thenReturn(workerStepExecutionFinish); + + handler.beforeTask(taskExecution); + Collection results = handler.handle(this.splitter, masterStepExecution); + + verify(this.taskLauncher).launch(this.appDeploymentRequestArgumentCaptor.capture()); + + AppDeploymentRequest request = this.appDeploymentRequestArgumentCaptor.getValue(); + + assertEquals(this.resource, request.getResource()); + assertEquals(2, request.getDeploymentProperties().size()); + assertEquals("bar", request.getDeploymentProperties().get("foo")); + assertEquals("qux", request.getDeploymentProperties().get("baz")); + + AppDefinition appDefinition = request.getDefinition(); + + assertEquals("partitionedJobTask:partitionedJob:step1:partition1", appDefinition.getName()); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, "4"))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))); + + assertEquals(1, results.size()); + StepExecution resultStepExecution = results.iterator().next(); + assertEquals(BatchStatus.COMPLETED, resultStepExecution.getStatus()); + assertEquals("step1:partition1", resultStepExecution.getStepName()); + } + private StepExecution getStepExecutionFinish(StepExecution stepExecutionStart, BatchStatus status) { StepExecution workerStepExecutionFinish = new StepExecution(stepExecutionStart.getStepName(), stepExecutionStart.getJobExecution()); workerStepExecutionFinish.setId(stepExecutionStart.getId()); @@ -592,9 +648,9 @@ public class DeployerPartitionHandlerTests { AppDefinition appDefinition = request.getDefinition(); assertEquals("partitionedJobTask:partitionedJob:step1:partition" + (i - 3), appDefinition.getName()); - assertEquals("1", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID)); - assertEquals(String.valueOf(i), appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID)); - assertEquals("step1", appDefinition.getProperties().get(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME)); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_JOB_EXECUTION_ID, "1"))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_EXECUTION_ID, String.valueOf(i)))); + assertTrue(request.getCommandlineArguments().contains(formatArgs(DeployerPartitionHandler.SPRING_CLOUD_TASK_STEP_NAME, "step1"))); } } diff --git a/spring-cloud-task-core/pom.xml b/spring-cloud-task-core/pom.xml index 6f7c1391..166e4501 100755 --- a/spring-cloud-task-core/pom.xml +++ b/spring-cloud-task-core/pom.xml @@ -19,6 +19,15 @@ org.springframework.boot spring-boot-starter + + org.springframework.cloud + spring-cloud-deployer-resource-support + + + org.springframework.cloud + spring-cloud-deployer-resource-maven + true + org.springframework spring-jdbc @@ -42,10 +51,6 @@ org.springframework.batch spring-batch-infrastructure - - org.springframework.batch - spring-batch-core - org.springframework.data spring-data-commons diff --git a/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/ResourceLoadingAutoConfiguration.java b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/ResourceLoadingAutoConfiguration.java new file mode 100644 index 00000000..ea1e208b --- /dev/null +++ b/spring-cloud-task-core/src/main/java/org/springframework/cloud/task/configuration/ResourceLoadingAutoConfiguration.java @@ -0,0 +1,82 @@ +/* + * Copyright 2016 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.cloud.task.configuration; + +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.autoconfigure.condition.ConditionalOnMissingClass; +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.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ResourceLoader; + +/** + * Autoconfiguration of a file or Maven based {@link ResourceLoader}. + * + * @author Michael Minella + * @since 1.0.1 + */ +@Configuration +public class ResourceLoadingAutoConfiguration { + + @Configuration + @ConditionalOnClass(MavenResourceLoader.class) + public static class MavenResourceLoadingAutoConfiguration { + + @Bean + public MavenResourceLoader mavenResourceLoader(MavenProperties mavenProperties) { + return new MavenResourceLoader(mavenProperties); + } + + @Bean + @ConditionalOnMissingBean + public DelegatingResourceLoader delegatingResourceLoader(MavenResourceLoader mavenResourceLoader) { + Map loaders = new HashMap<>(1); + loaders.put("maven", mavenResourceLoader); + + return new DelegatingResourceLoader(loaders); + } + + @Bean + public MavenProperties mavenProperties() { + return new MavenConfigurationProperties(); + } + + @ConfigurationProperties(prefix = "maven") + public static class MavenConfigurationProperties extends MavenProperties {} + } + + @Configuration + @ConditionalOnMissingClass("org.springframework.cloud.deployer.resource.maven.MavenResourceLoader") + public static class LocalResourceLoadingAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + public DelegatingResourceLoader delegatingResourceLoader(ApplicationContext context) { + Map loaders = new HashMap<>(1); + loaders.put("file", context); + + return new DelegatingResourceLoader(loaders); + } + } +} diff --git a/spring-cloud-task-core/src/main/resources/META-INF/spring.factories b/spring-cloud-task-core/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..22ff66d1 --- /dev/null +++ b/spring-cloud-task-core/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.springframework.cloud.task.configuration.ResourceLoadingAutoConfiguration diff --git a/spring-cloud-task-dependencies/pom.xml b/spring-cloud-task-dependencies/pom.xml index fdbfb5d1..b79e24fc 100644 --- a/spring-cloud-task-dependencies/pom.xml +++ b/spring-cloud-task-dependencies/pom.xml @@ -1,6 +1,5 @@ - org.springframework.cloud 4.0.0 spring-cloud-task-dependencies 1.0.1.BUILD-SNAPSHOT @@ -17,10 +16,12 @@ 1.0.2.RELEASE - 1.0.0.RELEASE - 1.0.0.RELEASE + 1.0.1.RELEASE + 1.0.1.RELEASE 1.0.2.RELEASE - 1.0.0.RELEASE + 1.0.1.RELEASE + 1.0.1.RELEASE + 3.0.7.RELEASE @@ -65,15 +66,10 @@ ${spring-cloud-deployer-local.version} true - - org.springframework.cloud - spring-cloud-deployer-local - ${spring-cloud-deployer-spi.version} - org.springframework.cloud spring-cloud-deployer-resource-support - ${spring.cloud.deployer.resource.support} + ${spring-cloud-deployer-resource-support.version} org.springframework.cloud @@ -81,6 +77,16 @@ ${spring-cloud-stream-binder-rabbit.version} test + + org.springframework.cloud + spring-cloud-deployer-resource-maven + ${spring-cloud-deployer-resource-maven.version} + + + org.springframework.batch + spring-batch-core + ${spring-batch.version} + diff --git a/spring-cloud-task-docs/src/main/asciidoc/batch.adoc b/spring-cloud-task-docs/src/main/asciidoc/batch.adoc index 0e61bc17..17f48a0c 100644 --- a/spring-cloud-task-docs/src/main/asciidoc/batch.adoc +++ b/spring-cloud-task-docs/src/main/asciidoc/batch.adoc @@ -64,11 +64,16 @@ look like the following: @Bean public PartitionHandler partitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer) throws Exception { - MavenResource resource = + + MavenProperties mavenProperties = new MavenProperties(); + mavenProperties.setRemoteRepositories(new HashMap<>(Collections.singletonMap("springRepo", + new MavenProperties.RemoteRepository(repository)))); + + MavenResource resource = MavenResource.parse(String.format("%s:%s:%s", "io.spring.cloud", "partitioned-batch-job", - "1.0.0.RELEASE")); + "1.0.0.RELEASE"), mavenProperties); DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, "workerStep"); @@ -85,11 +90,12 @@ public PartitionHandler partitionHandler(TaskLauncher taskLauncher, The `Resource` to be executed is expected to be a Spring Boot über-jar with a `DeployerStepExecutionHandler` configured as a `CommandLineRunner` in the current context. -Both the master and slave are expected to have visibility into the same data store being -used as the job repository and task repository. Once the underlying infrastructure has -bootstrapped the Spring Boot jar and Spring Boot has launched the -`DeployerStepExecutionHandler`, the step handler will execute the Step requested. An -example of configuring the `DefaultStepExecutionHandler`: +The repository enumerated in the example above should be the location of the remote repository +from which the über-jar is located. Both the master and slave are expected to have +visibility into the same data store being used as the job repository and task repository. +Once the underlying infrastructure has bootstrapped the Spring Boot jar and Spring Boot +has launched the `DeployerStepExecutionHandler`, the step handler will execute the Step +requested. An example of configuring the `DefaultStepExecutionHandler` is show below: ``` @Bean diff --git a/spring-cloud-task-docs/src/main/asciidoc/stream.adoc b/spring-cloud-task-docs/src/main/asciidoc/stream.adoc index 1feb90bb..a292b4e9 100644 --- a/spring-cloud-task-docs/src/main/asciidoc/stream.adoc +++ b/spring-cloud-task-docs/src/main/asciidoc/stream.adoc @@ -42,6 +42,10 @@ repository execute a maven build from the `spring-cloud-task-samples` directory property `skipInstall` set to false. For example: `mvn clean install`. +NOTE: The maven.remoteRepositories.springRepo.url property will need to be set to +the location of the remote repository from which the über-jar is located. If not +set, then there will be no remote repository, so it will rely upon the local repository only. + [[stream-integration-launching-sink-dataflow]] === Spring Cloud Data Flow diff --git a/spring-cloud-task-integration-tests/pom.xml b/spring-cloud-task-integration-tests/pom.xml index 5fe04979..78af7978 100644 --- a/spring-cloud-task-integration-tests/pom.xml +++ b/spring-cloud-task-integration-tests/pom.xml @@ -36,5 +36,14 @@ spring-cloud-task-batch test + + org.springframework.batch + spring-batch-core + test + + + org.springframework.cloud + spring-cloud-deployer-resource-support + diff --git a/spring-cloud-task-samples/batch-events/README.adoc b/spring-cloud-task-samples/batch-events/README.adoc index 60ffc037..cf54107e 100644 --- a/spring-cloud-task-samples/batch-events/README.adoc +++ b/spring-cloud-task-samples/batch-events/README.adoc @@ -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 /log-sink-rabbit-1.0.0.BUILD-SNAPSHOT.jar --server.port=9090 +$ java -jar /log-sink-rabbit-1.0.1.BUILD-SNAPSHOT.jar --server.port=9090 --spring.cloud.stream.bindings.input.destination=job-execution-events ---- diff --git a/spring-cloud-task-samples/batch-events/pom.xml b/spring-cloud-task-samples/batch-events/pom.xml index a151aca6..29831ebc 100644 --- a/spring-cloud-task-samples/batch-events/pom.xml +++ b/spring-cloud-task-samples/batch-events/pom.xml @@ -34,14 +34,6 @@ - - org.springframework.cloud - spring-cloud-task-core - - - org.springframework.cloud - spring-cloud-task-stream - org.springframework.boot spring-boot-starter-batch @@ -65,6 +57,11 @@ spring-cloud-stream-test-support-internal test + + org.springframework.cloud + spring-cloud-task-starter + 1.0.1.BUILD-SNAPSHOT + diff --git a/spring-cloud-task-samples/batch-job/README.adoc b/spring-cloud-task-samples/batch-job/README.adoc index 599732d0..c8b21541 100644 --- a/spring-cloud-task-samples/batch-job/README.adoc +++ b/spring-cloud-task-samples/batch-job/README.adoc @@ -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 ---- diff --git a/spring-cloud-task-samples/batch-job/pom.xml b/spring-cloud-task-samples/batch-job/pom.xml index dea7860a..7a19a528 100644 --- a/spring-cloud-task-samples/batch-job/pom.xml +++ b/spring-cloud-task-samples/batch-job/pom.xml @@ -40,11 +40,8 @@ org.springframework.cloud - spring-cloud-task-core - - - org.springframework.cloud - spring-cloud-task-batch + spring-cloud-task-starter + 1.0.1.BUILD-SNAPSHOT com.h2database diff --git a/spring-cloud-task-samples/partitioned-batch-job/README.adoc b/spring-cloud-task-samples/partitioned-batch-job/README.adoc index 8d83aaf3..873a028a 100644 --- a/spring-cloud-task-samples/partitioned-batch-job/README.adoc +++ b/spring-cloud-task-samples/partitioned-batch-job/README.adoc @@ -22,7 +22,7 @@ $ export spring_datasource_url=jdbc:mysql://localhost:3306/ $ export spring_datasource_username= $ export spring_datasource_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. diff --git a/spring-cloud-task-samples/partitioned-batch-job/pom.xml b/spring-cloud-task-samples/partitioned-batch-job/pom.xml index 82dc2190..7409d16f 100644 --- a/spring-cloud-task-samples/partitioned-batch-job/pom.xml +++ b/spring-cloud-task-samples/partitioned-batch-job/pom.xml @@ -40,7 +40,8 @@ org.springframework.cloud - spring-cloud-task-batch + spring-cloud-task-starter + 1.0.1.BUILD-SNAPSHOT @@ -62,7 +63,7 @@ org.springframework.boot spring-boot-starter-jdbc - + org.springframework.boot spring-boot-starter-test diff --git a/spring-cloud-task-samples/partitioned-batch-job/src/main/java/io/spring/JobConfiguration.java b/spring-cloud-task-samples/partitioned-batch-job/src/main/java/io/spring/JobConfiguration.java index e6b43492..79a545c9 100644 --- a/spring-cloud-task-samples/partitioned-batch-job/src/main/java/io/spring/JobConfiguration.java +++ b/spring-cloud-task-samples/partitioned-batch-job/src/main/java/io/spring/JobConfiguration.java @@ -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"); diff --git a/spring-cloud-task-samples/partitioned-batch-job/src/main/resources/application.properties b/spring-cloud-task-samples/partitioned-batch-job/src/main/resources/application.properties index 4c9aa713..db26a862 100644 --- a/spring-cloud-task-samples/partitioned-batch-job/src/main/resources/application.properties +++ b/spring-cloud-task-samples/partitioned-batch-job/src/main/resources/application.properties @@ -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 diff --git a/spring-cloud-task-samples/task-events/README.adoc b/spring-cloud-task-samples/task-events/README.adoc index 357c8888..58bd84b9 100644 --- a/spring-cloud-task-samples/task-events/README.adoc +++ b/spring-cloud-task-samples/task-events/README.adoc @@ -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 /log-sink-rabbit-1.0.0.BUILD-SNAPSHOT.jar --server.port=9090 --spring.cloud.stream.bindings.input.destination=task-events +$ java -jar /log-sink-rabbit-1.0.1.BUILD-SNAPSHOT.jar --server.port=9090 --spring.cloud.stream.bindings.input.destination=task-events ---- == Dependencies: diff --git a/spring-cloud-task-samples/task-events/pom.xml b/spring-cloud-task-samples/task-events/pom.xml index 4bff6de7..dfc6b3bc 100644 --- a/spring-cloud-task-samples/task-events/pom.xml +++ b/spring-cloud-task-samples/task-events/pom.xml @@ -41,12 +41,8 @@ org.springframework.cloud - spring-cloud-task-core - - - - org.springframework.cloud - spring-cloud-task-stream + spring-cloud-task-starter + 1.0.1.BUILD-SNAPSHOT diff --git a/spring-cloud-task-samples/taskprocessor/pom.xml b/spring-cloud-task-samples/taskprocessor/pom.xml index 15cb53de..c0258bf2 100644 --- a/spring-cloud-task-samples/taskprocessor/pom.xml +++ b/spring-cloud-task-samples/taskprocessor/pom.xml @@ -40,7 +40,7 @@ org.springframework.cloud - spring-cloud-task-stream + spring-cloud-task-starter 1.0.1.BUILD-SNAPSHOT diff --git a/spring-cloud-task-samples/taskprocessor/src/main/java/io/spring/TaskProcessor.java b/spring-cloud-task-samples/taskprocessor/src/main/java/io/spring/TaskProcessor.java index 5f570cb9..c712ecc8 100644 --- a/spring-cloud-task-samples/taskprocessor/src/main/java/io/spring/TaskProcessor.java +++ b/spring-cloud-task-samples/taskprocessor/src/main/java/io/spring/TaskProcessor.java @@ -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(request); } diff --git a/spring-cloud-task-samples/taskprocessor/src/test/java/io/spring/TaskProcessorApplicationTests.java b/spring-cloud-task-samples/taskprocessor/src/test/java/io/spring/TaskProcessorApplicationTests.java index 6867e652..412d811e 100644 --- a/spring-cloud-task-samples/taskprocessor/src/test/java/io/spring/TaskProcessorApplicationTests.java +++ b/spring-cloud-task-samples/taskprocessor/src/test/java/io/spring/TaskProcessorApplicationTests.java @@ -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 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))); } diff --git a/spring-cloud-task-samples/tasksink/pom.xml b/spring-cloud-task-samples/tasksink/pom.xml index 6d5e18ea..9caee16a 100644 --- a/spring-cloud-task-samples/tasksink/pom.xml +++ b/spring-cloud-task-samples/tasksink/pom.xml @@ -44,7 +44,8 @@ org.springframework.cloud - spring-cloud-task-stream + spring-cloud-task-starter + 1.0.1.BUILD-SNAPSHOT org.springframework.cloud diff --git a/spring-cloud-task-samples/tasksink/src/main/resources/application.properties b/spring-cloud-task-samples/tasksink/src/main/resources/application.properties new file mode 100644 index 00000000..a2e7d812 --- /dev/null +++ b/spring-cloud-task-samples/tasksink/src/main/resources/application.properties @@ -0,0 +1 @@ +maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot diff --git a/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java b/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java index 2a3ce4da..d8651404 100644 --- a/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java +++ b/spring-cloud-task-samples/tasksink/src/test/java/io/spring/TaskSinkApplicationTests.java @@ -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 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 message = new GenericMessage(request); this.sink.input().send(message); assertEquals(LaunchState.complete, testTaskLauncher.status("TESTSTATUS").getState()); diff --git a/spring-cloud-task-samples/tasksink/src/test/resources/application.properties b/spring-cloud-task-samples/tasksink/src/test/resources/application.properties new file mode 100644 index 00000000..a2e7d812 --- /dev/null +++ b/spring-cloud-task-samples/tasksink/src/test/resources/application.properties @@ -0,0 +1 @@ +maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot diff --git a/spring-cloud-task-samples/timestamp/README.adoc b/spring-cloud-task-samples/timestamp/README.adoc index 4bb0e0ee..f395dc9d 100644 --- a/spring-cloud-task-samples/timestamp/README.adoc +++ b/spring-cloud-task-samples/timestamp/README.adoc @@ -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 ---- diff --git a/spring-cloud-task-samples/timestamp/pom.xml b/spring-cloud-task-samples/timestamp/pom.xml index 8d8f6232..c943d2de 100644 --- a/spring-cloud-task-samples/timestamp/pom.xml +++ b/spring-cloud-task-samples/timestamp/pom.xml @@ -45,7 +45,8 @@ org.springframework.cloud - spring-cloud-task-core + spring-cloud-task-starter + 1.0.1.BUILD-SNAPSHOT org.springframework.boot diff --git a/spring-cloud-task-starter/pom.xml b/spring-cloud-task-starter/pom.xml new file mode 100644 index 00000000..1c5f295d --- /dev/null +++ b/spring-cloud-task-starter/pom.xml @@ -0,0 +1,31 @@ + + + + 4.0.0 + + + org.springframework.cloud + spring-cloud-task-parent + 1.0.1.BUILD-SNAPSHOT + + + spring-cloud-task-starter + jar + Spring Cloud Task Starter + Spring Boot starter for Spring Cloud Task + + + + org.springframework.cloud + spring-cloud-task-core + + + org.springframework.cloud + spring-cloud-task-batch + + + org.springframework.cloud + spring-cloud-task-stream + + + diff --git a/spring-cloud-task-stream/pom.xml b/spring-cloud-task-stream/pom.xml index fe77892b..69f56da6 100644 --- a/spring-cloud-task-stream/pom.xml +++ b/spring-cloud-task-stream/pom.xml @@ -16,6 +16,7 @@ org.springframework.batch spring-batch-core + true org.springframework @@ -26,6 +27,7 @@ org.springframework.cloud spring-cloud-stream + true org.springframework.cloud @@ -70,6 +72,7 @@ org.springframework.cloud spring-cloud-deployer-resource-support + true diff --git a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/BatchEventAutoConfiguration.java b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/BatchEventAutoConfiguration.java index f454063f..fceae03d 100644 --- a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/BatchEventAutoConfiguration.java +++ b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/BatchEventAutoConfiguration.java @@ -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 { diff --git a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/TaskBatchEventListenerBeanPostProcessor.java b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/TaskBatchEventListenerBeanPostProcessor.java index 4ab24d9f..c8523eca 100644 --- a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/TaskBatchEventListenerBeanPostProcessor.java +++ b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/batch/listener/support/TaskBatchEventListenerBeanPostProcessor.java @@ -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; diff --git a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLaunchRequest.java b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLaunchRequest.java index f3d54326..3aa34f87 100644 --- a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLaunchRequest.java +++ b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLaunchRequest.java @@ -37,21 +37,25 @@ public class TaskLaunchRequest implements Serializable{ private static final long serialVersionUID = 1L; private String uri; private List commandlineArguments; - private Map properties; + private Map environmentProperties; + private Map 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 commandlineArguments, - Map properties) { + Map environmentProperties, + Map deploymentProperties) { Assert.hasText(uri, "uri must not be empty nor null."); this.uri = uri; this.commandlineArguments = (commandlineArguments == null) ? new ArrayList() : commandlineArguments; - this.properties = properties == null ? new HashMap() : properties; + this.environmentProperties = environmentProperties == null ? new HashMap() : environmentProperties; + this.deploymentProperties = deploymentProperties == null ? new HashMap() : deploymentProperties; } /** @@ -73,8 +77,17 @@ public class TaskLaunchRequest implements Serializable{ * @return map containing the environment variables for the task. */ - public Map getProperties() { - return properties; + public Map getEnvironmentProperties() { + return environmentProperties; + } + + /** + * Returns the properties used by a {@link org.springframework.cloud.deployer.spi.task.TaskLauncher} + * + * @return deployment properties + */ + public Map 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; } } diff --git a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLauncherConfiguration.java b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLauncherConfiguration.java index 350fc8c2..aa9a0eb4 100644 --- a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLauncherConfiguration.java +++ b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLauncherConfiguration.java @@ -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 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 { - } } diff --git a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLauncherSink.java b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLauncherSink.java index 6a097eaa..65ecc87e 100644 --- a/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLauncherSink.java +++ b/spring-cloud-task-stream/src/main/java/org/springframework/cloud/task/launcher/TaskLauncherSink.java @@ -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); } diff --git a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java index 804b6d04..2ea7f6eb 100644 --- a/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java +++ b/spring-cloud-task-stream/src/test/java/org/springframework/cloud/task/launcher/TaskLauncherSinkTests.java @@ -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 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 message = new GenericMessage<>(request); this.sink.input().send(message); return testTaskLauncher; diff --git a/spring-cloud-task-stream/src/test/resources/application.properties b/spring-cloud-task-stream/src/test/resources/application.properties new file mode 100644 index 00000000..a2e7d812 --- /dev/null +++ b/spring-cloud-task-stream/src/test/resources/application.properties @@ -0,0 +1 @@ +maven.remoteRepositories.springRepo.url=https://repo.spring.io/libs-snapshot