From 745a4bd2dd90308db467ad3f68d40e8715a3c7ce Mon Sep 17 00:00:00 2001
From: Marius Bogoevici
Date: Sat, 5 Sep 2015 16:09:22 -0400
Subject: [PATCH] Use 'args.aggregate' for aggregate parameters
---
.../module/launcher/ModuleLauncher.java | 23 +++++++++++-------
.../launcher/ModuleLauncherProperties.java | 24 +++++++++++++------
.../module/launcher/ModuleLauncherRunner.java | 13 +++-------
3 files changed, 34 insertions(+), 26 deletions(-)
diff --git a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncher.java b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncher.java
index ff947a617..221fbec77 100644
--- a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncher.java
+++ b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncher.java
@@ -29,7 +29,6 @@ import java.util.regex.Pattern;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-
import org.springframework.boot.loader.archive.Archive;
import org.springframework.boot.loader.archive.JarFileArchive;
import org.springframework.cloud.stream.module.resolver.ModuleResolver;
@@ -88,19 +87,20 @@ public class ModuleLauncher {
* @param aggregate whether the modules should be aggregated at launch
* @param parentArgs a list of arguments for the whole aggregate
*/
- public void launch(List moduleLaunchRequests, boolean aggregate, String parentArgs[]) {
+ public void launch(List moduleLaunchRequests, boolean aggregate, Map parentArgs) {
List reversed = new ArrayList<>(moduleLaunchRequests);
Collections.reverse(reversed);
if (moduleLaunchRequests.size() == 1 || !aggregate) {
launchIndividualModules(moduleLaunchRequests);
}
else {
- launchAggregatedModules(moduleLaunchRequests, parentArgs);
+ launchAggregatedModules(moduleLaunchRequests, toArgArray(parentArgs));
}
}
+ @SuppressWarnings("unchecked")
public void launch(List moduleLaunchRequests, boolean aggregate) {
- this.launch(moduleLaunchRequests, aggregate, new String[0]);
+ this.launch(moduleLaunchRequests, aggregate, Collections.EMPTY_MAP);
}
public void launch(List moduleLaunchRequests) {
@@ -112,12 +112,17 @@ public class ModuleLauncher {
* {@literal --foo=bar} form.
*/
private String[] toArgArray(Map args) {
- String[] result = new String[args.size()];
- int i = 0;
- for (Map.Entry kv : args.entrySet()) {
- result[i++] = String.format("--%s=%s", kv.getKey(), kv.getValue());
+ if (args != null) {
+ String[] result = new String[args.size()];
+ int i = 0;
+ for (Map.Entry kv : args.entrySet()) {
+ result[i++] = String.format("--%s=%s", kv.getKey(), kv.getValue());
+ }
+ return result;
+ }
+ else {
+ return new String[0];
}
- return result;
}
public void launchAggregatedModules(List moduleLaunchRequests, final String[] parentArgs) {
diff --git a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncherProperties.java b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncherProperties.java
index cd3e93274..ba7a3ce2d 100644
--- a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncherProperties.java
+++ b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncherProperties.java
@@ -31,14 +31,25 @@ import org.springframework.core.env.Environment;
* properties, environment variables, program arguments, etc. _):
* - {@literal modules =
}: an ordered list of maven coordinates of modules to launch
* - {@literal args[][] = }: key/value pairs that will become module arguments,
- * where {@literal } is the 0-based index of the module in the list above
+ * where {@literal } is the 0-based index of the module in the list above and '*' can be used for passing
+ * arguments to all modules
+ * - {@literal aggregate = true | false}
: whether multiple modules launched together should be aggregated,
+ * case in which they will be launched as a single individual unit, and {@literal args['aggregate'][] = }
+ * can be used for passing arguments to the aggregate;
*
*
- * As an example, this is how one would launch {@literal time --fixedDelay=4 | log} canonical example:
+ * As an example, this is how one would launch the {@literal time --fixedDelay=4 | log} canonical example:
*
* modules = org.springframework.cloud.modules:time-source:1.0.0-SNAPSHOT,org.springframework.cloud.modules:log-sink:1.0.0-SNAPSHOT
* args.0.fixedDelay=4
*
+ *
+ * And this is how one would launch the {@literal time --fixedDelay=4 | log} example as an aggregate:
+ *
+ * modules = org.springframework.cloud.modules:time-source:1.0.0-SNAPSHOT,org.springframework.cloud.modules:log-sink:1.0.0-SNAPSHOT
+ * args.0.fixedDelay=4
+ * aggregate=true
+ *
*
*
* @author Ilayaperumal Gopinathan
@@ -64,10 +75,6 @@ public class ModuleLauncherProperties {
*/
private Map> args = new HashMap<>();
- public void setModules(String[] modules) {
- this.modules = modules;
- }
-
public boolean isAggregate() {
return aggregate;
}
@@ -76,6 +83,10 @@ public class ModuleLauncherProperties {
this.aggregate = aggregate;
}
+ public void setModules(String[] modules) {
+ this.modules = modules;
+ }
+
@NotEmpty(message = "A list of modules must be specified.")
public String[] getModules() {
return modules;
@@ -88,5 +99,4 @@ public class ModuleLauncherProperties {
public Map> getArgs() {
return args;
}
-
}
diff --git a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncherRunner.java b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncherRunner.java
index eeb492a9e..83272e01c 100644
--- a/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncherRunner.java
+++ b/spring-cloud-stream-module-launcher/src/main/java/org/springframework/cloud/stream/module/launcher/ModuleLauncherRunner.java
@@ -45,6 +45,8 @@ public class ModuleLauncherRunner implements CommandLineRunner {
private final static String GLOBAL_ARGS_KEY = "*";
+ private final static String AGGREGATE_ARGS_KEY = "aggregate";
+
@Autowired
private ModuleLauncherProperties moduleLauncherProperties;
@@ -63,7 +65,7 @@ public class ModuleLauncherRunner implements CommandLineRunner {
}
this.moduleLauncher.launch(launchRequests,
moduleLauncherProperties.isAggregate(),
- moduleLauncherProperties.isAggregate() ? extractAggregateProperties(args) : new String[0]);
+ moduleLauncherProperties.isAggregate() ? moduleLauncherProperties.getArgs().get(AGGREGATE_ARGS_KEY) : null);
}
private List generateModuleLaunchRequests() {
@@ -91,14 +93,5 @@ public class ModuleLauncherRunner implements CommandLineRunner {
return requests;
}
- private String[] extractAggregateProperties(String[] args) {
- List filteredProperties = new ArrayList<>();
- for (String arg : args) {
- if (arg.startsWith("--spring.")) {
- filteredProperties.add(arg);
- }
- }
- return filteredProperties.toArray(new String[filteredProperties.size()]);
- }
}