Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

XD-1350: Remove enums as option coercion mechanism #619

Closed
wants to merge 4 commits into from

3 participants

Eric Bottard Mark Fisher Mark Pollack
Eric Bottard
Collaborator

I'm obviously not a big fan of the empty xml files.

Alternatives (and also considering not using varargs in the constructor in favor of a more explicit call) :

{
   addValidValue("local");
   removeValidValue("memory");
}
Mark Fisher
Owner

I don't think empty XML files are the way to go. Just accept that "local" is a valid option.

Mark Fisher
Owner

A couple other comments:

  1. We do not necessarily need to rush to remove enums for "store" and "analytics". The most important first step is to support a pluggable message bus.
  2. The control transport option will be disappearing with our move to ZooKeeper for deployment.
Eric Bottard
Collaborator
Mark Pollack markpollack self-assigned this
...erver/options/FromResourceLocationOptionHandlers.java
((31 lines not shown))
+public final class FromResourceLocationOptionHandlers {
+
+ private FromResourceLocationOptionHandlers() {
+
+ }
+
+ public static final String SINGLE_NODE_SPECIAL_CONTROL_TRANSPORT = "local";
+
+ /**
+ * Computes values for --controlTransport for the distributed case.
+ */
+ public static class DistributedControlTransportOptionHandler extends FromResourceLocationOptionHandler {
+
+ public DistributedControlTransportOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, "classpath*:/META-INF/spring-xd/transports/*-admin.xml");
Mark Fisher Owner

we should probably at least use a private constant for the common prefix ("classpath*:/META-INF/spring-xd") so we don't duplicate that for each of these

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Eric Bottard
Collaborator

Rebased and extracted constant for config file location

Mark Fisher markfisher commented on the diff
...amework/xd/dirt/server/options/SingleNodeOptions.java
((17 lines not shown))
- @Option(name = "--transport", usage = "The transport to use for data messages (from node to node)")
- private DataTransport transport;
+ @Option(name = "--transport", handler = SingleNodeDataTransportOptionHandler.class,
+ usage = "The transport to use for data messages (from node to node)")
Mark Fisher Owner

I know this did not change in this PR, but saying "node to node" in the context of single node does not make sense.

Eric Bottard Collaborator

Indeed. Do you want me to change it, or can you do on merge?

Mark Fisher Owner

I can do that on merge. I also created a new issue: https://jira.springsource.org/browse/XD-1377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mark Fisher markfisher commented on the diff
...server/options/FromResourceLocationOptionHandler.java
((33 lines not shown))
+
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+
+
+/**
+ * An {@link OptionHandler} that scans a resource pattern for existing resources (using a single '*' wildcard) and
+ * allows all String values <i>s</i> that would fit if that single wildcard was replaced by <i>s</i>.
+ *
+ * <p>
+ * Given that an option handler has to appear as an annotation parameter, expected usage is to sublcass this class,
+ * provide the canonical 3 arg contructor to {@link OptionHandler} and pass the resource pattern as the 4th argument.
+ * </p>
+ *
+ */
+public class FromResourceLocationOptionHandler extends OptionHandler<String> {
Mark Fisher Owner

If you don't mind, I think I'll rename this to ResourcePatternScanningOptionHandler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mark Fisher markfisher commented on the diff
...erver/options/FromResourceLocationOptionHandlers.java
((28 lines not shown))
+ *
+ * @author Eric Bottard
+ */
+public final class FromResourceLocationOptionHandlers {
+
+ private FromResourceLocationOptionHandlers() {
+
+ }
+
+ private static final String CONFIGURATION_ROOT = "classpath*:/META-INF/spring-xd/";
+
+ /**
+ * The special controlTransport, usable only in singlenode mode, that requires the admin and container application
+ * contexts to talk to each other.
+ */
+ public static final String SINGLE_NODE_SPECIAL_CONTROL_TRANSPORT = "local";
Mark Fisher Owner

If you don't mind, I think I'll rename this constant to SINGLE_NODE_LOCAL_CONTROL_TRANSPORT.

Eric Bottard Collaborator

Definitely not, on both.

Mark Fisher Owner

Just to be clear, you mean that "you definitely DONT MIND"?... or "definitely do not change". I don't want to make you angry :)

Eric Bottard Collaborator

DON'T YOU DARE CHANGE THOSE!

No, just kidding, be my guest of course. better names indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mark Pollack markpollack removed their assignment
Mark Fisher
Owner

Based on the discussion, I will apply some renames while merging.

Otherwise LGTM.

Mark Fisher markfisher commented on the diff
...erver/options/FromResourceLocationOptionHandlers.java
((22 lines not shown))
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.Setter;
+
+
+/**
+ * Holds definitions of {@link FromResourceLocationOptionHandler}s used in Spring XD.
+ *
+ * @author Eric Bottard
+ */
+public final class FromResourceLocationOptionHandlers {
+
+ private FromResourceLocationOptionHandlers() {
+
+ }
+
+ private static final String CONFIGURATION_ROOT = "classpath*:/META-INF/spring-xd/";
Mark Fisher Owner

Could use the constant for config root, e.g.: "classpath*:/" + ConfigLocations.XD_CONFIG_ROOT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mark Fisher markfisher commented on the diff
...server/options/FromResourceLocationOptionHandler.java
((35 lines not shown))
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+
+
+/**
+ * An {@link OptionHandler} that scans a resource pattern for existing resources (using a single '*' wildcard) and
+ * allows all String values <i>s</i> that would fit if that single wildcard was replaced by <i>s</i>.
+ *
+ * <p>
+ * Given that an option handler has to appear as an annotation parameter, expected usage is to sublcass this class,
+ * provide the canonical 3 arg contructor to {@link OptionHandler} and pass the resource pattern as the 4th argument.
+ * </p>
+ *
+ */
+public class FromResourceLocationOptionHandler extends OptionHandler<String> {
+
+ private Set<String> possibleValues = new HashSet<String>();
Mark Fisher Owner

these 2 sets should be final

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mark Fisher markfisher commented on the diff
...erver/options/FromResourceLocationOptionHandlers.java
((106 lines not shown))
+
+ /**
+ * Computes values for --analytics in the distributed case (memory is NOT supported).
+ */
+ public static class DistributedAnalyticsOptionHandler extends FromResourceLocationOptionHandler {
+
+ public DistributedAnalyticsOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, CONFIGURATION_ROOT + "analytics/*-analytics.xml");
+ exclude("memory");
+ }
+
+ }
+
+ /**
+ * Computes values for --store in the distributed case (memory is NOT supported).
Mark Fisher Owner

This says memory is NOT supported, but it is not excluded here.

Also it says for "distributed case", but this one appears to be applied to both distributed AND singlenode.

Eric Bottard Collaborator

Indeed, there should be two variants of this one.

Eric Bottard Collaborator

I take that back. Memory is supported for distributed as well. The javadoc is wrong that's all

Eric Bottard Collaborator

Hmmm, now I have a doubt. Should check with current behavior, but I think there are actually two cases here indeed, because of the runtime container info (ie the admin is no longer the only thing that writes to the "store")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Mark Fisher
Owner

Actually I made a few more comments. Some can be handled on merge by me, but I need a reply on this one: https://github.com/spring-projects/spring-xd/pull/619/files#r10392789

Eric Bottard
Collaborator

OK, I finally found the problem that was blocking me and fixed it.
I opted with the following regarding "store", which is slightly different from what we have currently:
singlenode : redis + memory
distributed : redis only

The rationale is this: Although IMO only the admin server should be responsible for STORing, currently the container nodes do a little bit of that when they advertise their container id. Hence, the only case where this is fully functional is when using redis. One could argue that if you're not interested in the container info, then memory for distributed is fine.
In any case, as discussed earlier, this is going away soon, so..

Mark Fisher
Owner

Yes, the Container nodes advertising their attributes (including the Container IDs) will all be moved to ZooKeeper.

Mark Fisher
Owner

Here are the changes I plan to make while merging:

  1. in SingleNodeOptions: remove "node to node" comments
  2. make FromResourceLocationOptionHandler abstract
  3. in FromResourceLocationOptionHandlers: use "classpath*:/" + ConfigLocations.XD_CONFIG_ROOT
  4. in FromResourceLocationOptionHandler: the 2 sets ("*Values") should be final
  5. rename: FromResourceLocationOptionHandler -> ResourcePatternScanningOptionHandler
  6. rename: FromResourceLocationOptionHandlers -> ResourcePatternScanningOptionHandlers
  7. rename: SINGLE_NODE_SPECIAL_CONTROL_TRANSPORT -> SINGLE_NODE_LOCAL_CONTROL_TRANSPORT
Eric Bottard
Collaborator
Mark Fisher markfisher closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
14 spring-xd-dirt/src/main/java/org/springframework/xd/dirt/server/SingleNodeApplication.java
View
@@ -13,7 +13,6 @@
package org.springframework.xd.dirt.server;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
@@ -21,8 +20,8 @@
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.SubscribableChannel;
import org.springframework.xd.dirt.server.options.CommandLinePropertySourceOverridingListener;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers;
import org.springframework.xd.dirt.server.options.SingleNodeOptions;
-import org.springframework.xd.dirt.server.options.SingleNodeOptions.ControlTransport;
import org.springframework.xd.dirt.util.BannerUtils;
/**
@@ -37,9 +36,6 @@
private ConfigurableApplicationContext containerContext;
- @Value("${XD_CONTROL_TRANSPORT}")
- ControlTransport controlTransport;
-
public static final String SINGLE_PROFILE = "single";
public static void main(String[] args) {
@@ -55,8 +51,7 @@ public SingleNodeApplication run(String... args) {
new SingleNodeOptions());
SpringApplicationBuilder admin =
- new SpringApplicationBuilder(SingleNodeOptions.class, ParentConfiguration.class,
- SingleNodeApplication.class)
+ new SpringApplicationBuilder(SingleNodeOptions.class, ParentConfiguration.class)
.listeners(commandLineListener)
.profiles(AdminServerApplication.ADMIN_PROFILE, SINGLE_PROFILE)
.child(SingleNodeOptions.class, AdminServerApplication.class)
@@ -73,8 +68,9 @@ public SingleNodeApplication run(String... args) {
adminContext = admin.context();
containerContext = container.context();
- SingleNodeApplication singleNodeApp = adminContext.getBean(SingleNodeApplication.class);
- if (singleNodeApp.controlTransport == ControlTransport.local) {
+ String controlTransport = adminContext.getEnvironment().getProperty(
+ "XD_CONTROL_TRANSPORT");
+ if (FromResourceLocationOptionHandlers.SINGLE_NODE_SPECIAL_CONTROL_TRANSPORT.equals(controlTransport)) {
setUpControlChannels(adminContext, containerContext);
}
return this;
26 spring-xd-dirt/src/main/java/org/springframework/xd/dirt/server/options/AdminOptions.java
View
@@ -21,6 +21,7 @@
import org.kohsuke.args4j.Option;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers.DistributedControlTransportOptionHandler;
/**
@@ -34,18 +35,10 @@
@Option(name = "--httpPort", usage = "Http port for the REST API server", metaVar = "<httpPort>")
private Integer httpPort;
-
- @Option(name = "--controlTransport", aliases = { "--control-transport", "--transport" }, usage = "The transport to use for control messages (between admin and nodes)")
- private ControlTransport controlTransport;
-
- public void setXD_CONTROL_TRANSPORT(ControlTransport controlTransport) {
- this.controlTransport = controlTransport;
- }
-
- @NotNull
- public ControlTransport getXD_CONTROL_TRANSPORT() {
- return controlTransport;
- }
+ @Option(name = "--controlTransport", aliases = { "--control-transport", "--transport" },
+ handler = DistributedControlTransportOptionHandler.class,
+ usage = "The transport to use for control messages (between admin and nodes)")
+ private String controlTransport;
public Integer getPORT() {
return httpPort;
@@ -55,5 +48,14 @@ public void setPORT(int httpPort) {
this.httpPort = httpPort;
}
+ public void setXD_CONTROL_TRANSPORT(String controlTransport) {
+ this.controlTransport = controlTransport;
+ }
+
+ @NotNull
+ public String getXD_CONTROL_TRANSPORT() {
+ return controlTransport;
+ }
+
}
39 spring-xd-dirt/src/main/java/org/springframework/xd/dirt/server/options/CommonDistributedOptions.java
View
@@ -20,6 +20,9 @@
import org.kohsuke.args4j.Option;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers.DistributedAnalyticsOptionHandler;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers.DistributedStoreOptionHandler;
+
/**
* Holds options that are common to both admin and container servers, when used in distributed mode. Note that single
@@ -29,42 +32,32 @@
*/
public class CommonDistributedOptions extends CommonOptions {
- public static enum Analytics {
- // note: memory is NOT an option here
- redis;
- }
-
- public static enum ControlTransport {
- rabbit, redis
- }
-
- // Should be pushed down to AdminOptions but currently
- // can't b/c of the way container runtime info is persisted
- public static enum Store {
- memory, redis;
- }
-
- @Option(name = "--analytics", usage = "How to persist analytics such as counters and gauges")
- private Analytics analytics;
+ @Option(name = "--analytics", handler = DistributedAnalyticsOptionHandler.class,
+ usage = "How to persist analytics such as counters and gauges")
+ private String analytics;
- @Option(name = "--store", usage = "How to persist admin data")
- private Store store;
+ // Should be pushed down to AdminOptions (and would then be able to include memory)
+ // but currently can't b/c of the way container runtime info is persisted.
+ // Likely to change with ZK support anyway.
+ @Option(name = "--store", handler = DistributedStoreOptionHandler.class,
+ usage = "How to persist admin data")
+ private String store;
@NotNull
- public Analytics getXD_ANALYTICS() {
+ public String getXD_ANALYTICS() {
return analytics;
}
@NotNull
- public Store getXD_STORE() {
+ public String getXD_STORE() {
return store;
}
- public void setXD_ANALYTICS(Analytics analytics) {
+ public void setXD_ANALYTICS(String analytics) {
this.analytics = analytics;
}
- public void setXD_STORE(Store store) {
+ public void setXD_STORE(String store) {
this.store = store;
}
36 spring-xd-dirt/src/main/java/org/springframework/xd/dirt/server/options/ContainerOptions.java
View
@@ -21,6 +21,8 @@
import org.kohsuke.args4j.Option;
import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers.DistributedControlTransportOptionHandler;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers.DistributedDataTransportOptionHandler;
/**
@@ -33,30 +35,23 @@
public class ContainerOptions extends CommonDistributedOptions {
- @Option(name = "--transport", usage = "The transport to use for data messages (from node to node)")
- private DataTransport transport;
+ @Option(name = "--transport", handler = DistributedDataTransportOptionHandler.class,
+ usage = "The transport to use for data messages (from node to node)")
+ private String transport;
@Option(name = "--hadoopDistro", usage = "The Hadoop distribution to be used for HDFS access")
private HadoopDistro distro;
- @Option(name = "--controlTransport", aliases = "--control-transport", usage = "The transport to use for control messages (between admin and nodes)")
- private ControlTransport controlTransport;
+ @Option(name = "--controlTransport", aliases = { "--control-transport" },
+ handler = DistributedControlTransportOptionHandler.class,
+ usage = "The transport to use for control messages (between admin and nodes)")
+ private String controlTransport;
- public void setXD_CONTROL_TRANSPORT(ControlTransport controlTransport) {
- this.controlTransport = controlTransport;
- }
-
- @NotNull
- public ControlTransport getXD_CONTROL_TRANSPORT() {
- return controlTransport;
- }
-
-
- public void setXD_TRANSPORT(DataTransport transport) {
+ public void setXD_TRANSPORT(String transport) {
this.transport = transport;
}
- public DataTransport getXD_TRANSPORT() {
+ public String getXD_TRANSPORT() {
return this.transport;
}
@@ -67,4 +62,13 @@ public void setHADOOP_DISTRO(HadoopDistro distro) {
public HadoopDistro getHADOOP_DISTRO() {
return this.distro;
}
+
+ public void setXD_CONTROL_TRANSPORT(String controlTransport) {
+ this.controlTransport = controlTransport;
+ }
+
+ @NotNull
+ public String getXD_CONTROL_TRANSPORT() {
+ return controlTransport;
+ }
}
24 spring-xd-dirt/src/main/java/org/springframework/xd/dirt/server/options/DataTransport.java
View
@@ -1,24 +0,0 @@
-/*
- * Copyright 2013 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.xd.dirt.server.options;
-
-/**
- * @author David Turanski
- */
-public enum DataTransport {
- local, rabbit, redis
-}
114 ...-xd-dirt/src/main/java/org/springframework/xd/dirt/server/options/FromResourceLocationOptionHandler.java
View
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2013-2014 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.xd.dirt.server.options;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.kohsuke.args4j.CmdLineException;
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.NamedOptionDef;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.OptionHandler;
+import org.kohsuke.args4j.spi.Parameters;
+import org.kohsuke.args4j.spi.Setter;
+
+import org.springframework.core.io.Resource;
+import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
+
+
+/**
+ * An {@link OptionHandler} that scans a resource pattern for existing resources (using a single '*' wildcard) and
+ * allows all String values <i>s</i> that would fit if that single wildcard was replaced by <i>s</i>.
+ *
+ * <p>
+ * Given that an option handler has to appear as an annotation parameter, expected usage is to sublcass this class,
+ * provide the canonical 3 arg contructor to {@link OptionHandler} and pass the resource pattern as the 4th argument.
+ * </p>
+ *
+ */
+public class FromResourceLocationOptionHandler extends OptionHandler<String> {
Mark Fisher Owner

If you don't mind, I think I'll rename this to ResourcePatternScanningOptionHandler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ private Set<String> possibleValues = new HashSet<String>();
Mark Fisher Owner

these 2 sets should be final

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ private Set<String> excluded = new HashSet<String>();
+
+ protected FromResourceLocationOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter,
+ String glob)
+ throws IOException {
+ super(parser, option, setter);
+ init(glob);
+ }
+
+ @Override
+ public int parseArguments(Parameters params) throws CmdLineException {
+ String s = params.getParameter(0);
+ if (!possibleValues.contains(s)) {
+ String errorMessage = String.format("'%s' is not a valid value. Possible values are %s", s, possibleValues);
+ if (this.option instanceof NamedOptionDef) {
+ NamedOptionDef named = (NamedOptionDef) this.option;
+ errorMessage = String.format("'%s' is not a valid value for option %s. Possible values are %s", s,
+ named.name(), possibleValues);
+ }
+ if (excluded.contains(s)) {
+ errorMessage += String.format(
+ ". Note that '%s' has been explicitly excluded from the list of possible values,"
+ + " even though a resource with that name exists", s);
+ }
+ throw new CmdLineException(owner, errorMessage);
+ }
+ setter.addValue(s);
+ return 1;
+ }
+
+ @Override
+ public String getDefaultMetaVariable() {
+ return possibleValues.toString().replace(",", " |");
+ }
+
+ private void init(String glob, String... excludes) throws IOException {
+ int protocolColon = glob.indexOf(':');
+ String withoutProtocol = protocolColon != -1 ? glob.substring(protocolColon + 1) : glob;
+ Pattern capturing = Pattern.compile(".*" + withoutProtocol.replace("*", "([^/]*)") + ".*");
+
+ PathMatchingResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
+ for (Resource r : resolver.getResources(glob)) {
+ String path = r.getURL().toString();
+ Matcher matcher = capturing.matcher(path);
+ if (!matcher.matches()) {
+ throw new IllegalStateException(
+ String.format("Expected to match '%s' with regex '%s'", path, capturing));
+ }
+ possibleValues.add(matcher.group(1));
+ }
+
+ }
+
+ protected void exclude(String... excludes) {
+ excluded.addAll(Arrays.asList(excludes));
+ possibleValues.removeAll(excluded);
+ }
+
+ protected void include(String... includes) {
+ possibleValues.addAll(Arrays.asList(includes));
+ }
+
+}
144 ...xd-dirt/src/main/java/org/springframework/xd/dirt/server/options/FromResourceLocationOptionHandlers.java
View
@@ -0,0 +1,144 @@
+/*
+ * Copyright 2013-2014 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.xd.dirt.server.options;
+
+import java.io.IOException;
+
+import org.kohsuke.args4j.CmdLineParser;
+import org.kohsuke.args4j.OptionDef;
+import org.kohsuke.args4j.spi.Setter;
+
+
+/**
+ * Holds definitions of {@link FromResourceLocationOptionHandler}s used in Spring XD.
+ *
+ * @author Eric Bottard
+ */
+public final class FromResourceLocationOptionHandlers {
+
+ private FromResourceLocationOptionHandlers() {
+
+ }
+
+ private static final String CONFIGURATION_ROOT = "classpath*:/META-INF/spring-xd/";
Mark Fisher Owner

Could use the constant for config root, e.g.: "classpath*:/" + ConfigLocations.XD_CONFIG_ROOT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ /**
+ * The special controlTransport, usable only in singlenode mode, that requires the admin and container application
+ * contexts to talk to each other.
+ */
+ public static final String SINGLE_NODE_SPECIAL_CONTROL_TRANSPORT = "local";
Mark Fisher Owner

If you don't mind, I think I'll rename this constant to SINGLE_NODE_LOCAL_CONTROL_TRANSPORT.

Eric Bottard Collaborator

Definitely not, on both.

Mark Fisher Owner

Just to be clear, you mean that "you definitely DONT MIND"?... or "definitely do not change". I don't want to make you angry :)

Eric Bottard Collaborator

DON'T YOU DARE CHANGE THOSE!

No, just kidding, be my guest of course. better names indeed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+
+ /**
+ * Computes values for --controlTransport for the distributed case.
+ */
+ public static class DistributedControlTransportOptionHandler extends FromResourceLocationOptionHandler {
+
+ public DistributedControlTransportOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, CONFIGURATION_ROOT + "transports/*-admin.xml");
+ }
+
+ }
+
+ /**
+ * Computes values for --controlTransport for the singlenode case.
+ */
+ public static class SingleNodeControlTransportOptionHandler extends FromResourceLocationOptionHandler {
+
+ public SingleNodeControlTransportOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, CONFIGURATION_ROOT + "transports/*-admin.xml");
+ include(SINGLE_NODE_SPECIAL_CONTROL_TRANSPORT);
+ }
+
+ }
+
+ /**
+ * Computes values for (data) --transport for the distributed case.
+ */
+ public static class DistributedDataTransportOptionHandler extends FromResourceLocationOptionHandler {
+
+ public DistributedDataTransportOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, CONFIGURATION_ROOT + "transports/*-bus.xml");
+ exclude("local");
+ }
+
+ }
+
+ /**
+ * Computes values for (data) --transport for the singlenode case.
+ */
+ public static class SingleNodeDataTransportOptionHandler extends FromResourceLocationOptionHandler {
+
+ public SingleNodeDataTransportOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, CONFIGURATION_ROOT + "transports/*-bus.xml");
+ }
+
+ }
+
+ /**
+ * Computes values for --analytics in the single node case (accepts memory).
+ */
+ public static class SingleNodeAnalyticsOptionHandler extends FromResourceLocationOptionHandler {
+
+ public SingleNodeAnalyticsOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, CONFIGURATION_ROOT + "analytics/*-analytics.xml");
+ }
+
+ }
+
+ /**
+ * Computes values for --analytics in the distributed case (memory is NOT supported).
+ */
+ public static class DistributedAnalyticsOptionHandler extends FromResourceLocationOptionHandler {
+
+ public DistributedAnalyticsOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, CONFIGURATION_ROOT + "analytics/*-analytics.xml");
+ exclude("memory");
+ }
+
+ }
+
+ /**
+ * Computes values for --store in the distributed case (memory is NOT supported).
Mark Fisher Owner

This says memory is NOT supported, but it is not excluded here.

Also it says for "distributed case", but this one appears to be applied to both distributed AND singlenode.

Eric Bottard Collaborator

Indeed, there should be two variants of this one.

Eric Bottard Collaborator

I take that back. Memory is supported for distributed as well. The javadoc is wrong that's all

Eric Bottard Collaborator

Hmmm, now I have a doubt. Should check with current behavior, but I think there are actually two cases here indeed, because of the runtime container info (ie the admin is no longer the only thing that writes to the "store")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ */
+ public static class DistributedStoreOptionHandler extends FromResourceLocationOptionHandler {
+
+ public DistributedStoreOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, CONFIGURATION_ROOT + "store/*-store.xml");
+ exclude("memory");
+ }
+ }
+
+ /**
+ * Computes values for --store in the singlenode case.
+ */
+ public static class SingleNodeStoreOptionHandler extends FromResourceLocationOptionHandler {
+
+ public SingleNodeStoreOptionHandler(CmdLineParser parser, OptionDef option, Setter<String> setter)
+ throws IOException {
+ super(parser, option, setter, CONFIGURATION_ROOT + "store/*-store.xml");
+ }
+ }
+
+
+}
51 spring-xd-dirt/src/main/java/org/springframework/xd/dirt/server/options/SingleNodeOptions.java
View
@@ -19,8 +19,12 @@
import javax.validation.constraints.NotNull;
import org.kohsuke.args4j.Option;
+
import org.springframework.boot.context.properties.ConfigurationProperties;
-import org.springframework.xd.dirt.server.options.CommonDistributedOptions.Store;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers.SingleNodeAnalyticsOptionHandler;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers.SingleNodeControlTransportOptionHandler;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers.SingleNodeDataTransportOptionHandler;
+import org.springframework.xd.dirt.server.options.FromResourceLocationOptionHandlers.SingleNodeStoreOptionHandler;
/**
@@ -33,25 +37,22 @@
@ConfigurationProperties
public class SingleNodeOptions extends CommonOptions {
- public static enum Analytics {
- memory, redis;
- }
-
- public static enum ControlTransport {
- local, rabbit, redis;
- }
-
- @Option(name = "--analytics", usage = "How to persist analytics such as counters and gauges")
- private Analytics analytics;
+ @Option(name = "--analytics", handler = SingleNodeAnalyticsOptionHandler.class,
+ usage = "How to persist analytics such as counters and gauges")
+ private String analytics;
- @Option(name = "--transport", usage = "The transport to use for data messages (from node to node)")
- private DataTransport transport;
+ @Option(name = "--transport", handler = SingleNodeDataTransportOptionHandler.class,
+ usage = "The transport to use for data messages (from node to node)")
Mark Fisher Owner

I know this did not change in this PR, but saying "node to node" in the context of single node does not make sense.

Eric Bottard Collaborator

Indeed. Do you want me to change it, or can you do on merge?

Mark Fisher Owner

I can do that on merge. I also created a new issue: https://jira.springsource.org/browse/XD-1377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+ private String transport;
- @Option(name = "--controlTransport", aliases = "--control-transport", usage = "The transport to use for control messages (between admin and nodes)")
- private ControlTransport controlTransport;
+ @Option(name = "--controlTransport", aliases = { "--control-transport" },
+ handler = SingleNodeControlTransportOptionHandler.class,
+ usage = "The transport to use for control messages (between admin and nodes)")
+ private String controlTransport;
- @Option(name = "--store", usage = "How to persist admin data")
- private Store store;
+ @Option(name = "--store", handler = SingleNodeStoreOptionHandler.class,
+ usage = "How to persist admin data")
+ private String store;
@Option(name = "--httpPort", usage = "Http port for the REST API server", metaVar = "<httpPort>")
private Integer httpPort;
@@ -68,38 +69,38 @@ public void setPORT(int httpPort) {
}
@NotNull
- public Analytics getXD_ANALYTICS() {
+ public String getXD_ANALYTICS() {
return analytics;
}
@NotNull
- public Store getXD_STORE() {
+ public String getXD_STORE() {
return store;
}
@NotNull
- public DataTransport getXD_TRANSPORT() {
+ public String getXD_TRANSPORT() {
return transport;
}
@NotNull
- public ControlTransport getXD_CONTROL_TRANSPORT() {
+ public String getXD_CONTROL_TRANSPORT() {
return controlTransport;
}
- public void setXD_ANALYTICS(Analytics analytics) {
+ public void setXD_ANALYTICS(String analytics) {
this.analytics = analytics;
}
- public void setXD_STORE(Store store) {
+ public void setXD_STORE(String store) {
this.store = store;
}
- public void setXD_TRANSPORT(DataTransport transport) {
+ public void setXD_TRANSPORT(String transport) {
this.transport = transport;
}
- public void setXD_CONTROL_TRANSPORT(ControlTransport controlTransport) {
+ public void setXD_CONTROL_TRANSPORT(String controlTransport) {
this.controlTransport = controlTransport;
}
Something went wrong with that request. Please try again.