From ed492901ed8869dc5a435897a5a20551d8b17f9d Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Wed, 3 Feb 2016 10:44:06 +0100 Subject: [PATCH] Apply feedback from @bleskes and add fix some minor issues --- .../org/elasticsearch/common/network/NetworkModule.java | 6 +++--- .../elasticsearch/common/settings/ClusterSettings.java | 1 + .../org/elasticsearch/common/settings/SettingsModule.java | 8 ++++---- .../elasticsearch/rest/action/main/RestMainAction.java | 3 ++- .../java/org/elasticsearch/threadpool/ThreadPool.java | 5 +++-- .../elasticsearch/common/network/NetworkModuleTests.java | 2 +- .../main/java/org/elasticsearch/test/ExternalNode.java | 2 +- .../java/org/elasticsearch/test/ExternalTestCluster.java | 2 +- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java index 76be2318758..9b0998b6821 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java @@ -150,10 +150,11 @@ public class NetworkModule extends AbstractModule { public static final String TRANSPORT_TYPE_KEY = "transport.type"; public static final String TRANSPORT_SERVICE_TYPE_KEY = "transport.service.type"; + public static final String HTTP_TYPE_KEY = "http.type"; public static final String LOCAL_TRANSPORT = "local"; public static final String NETTY_TRANSPORT = "netty"; - public static final String HTTP_TYPE_KEY = "http.type"; + public static final Setting HTTP_TYPE_SETTING = Setting.simpleString("http.type", false, Scope.CLUSTER); public static final Setting HTTP_ENABLED = Setting.boolSetting("http.enabled", true, false, Scope.CLUSTER); public static final Setting TRANSPORT_SERVICE_TYPE_SETTING = Setting.simpleString("transport.service.type", false, Scope.CLUSTER); public static final Setting TRANSPORT_TYPE_SETTING = Setting.simpleString("transport.type", false, Scope.CLUSTER); @@ -162,7 +163,6 @@ public class NetworkModule extends AbstractModule { private static final List> builtinRestHandlers = Arrays.asList( RestMainAction.class, - RestNodesInfoAction.class, RestNodesStatsAction.class, RestNodesHotThreadsAction.class, @@ -383,7 +383,7 @@ public class NetworkModule extends AbstractModule { } else { if (HTTP_ENABLED.get(settings)) { bind(HttpServer.class).asEagerSingleton(); - httpTransportTypes.bindType(binder(), settings, HTTP_TYPE_KEY, NETTY_TRANSPORT); + httpTransportTypes.bindType(binder(), settings, HTTP_TYPE_SETTING.getKey(), NETTY_TRANSPORT); } bind(RestController.class).asEagerSingleton(); catHandlers.bind(binder()); diff --git a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java index c0a84ade9e0..fa5b81c9e6f 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -209,6 +209,7 @@ public final class ClusterSettings extends AbstractScopedSettings { GatewayService.RECOVER_AFTER_NODES_SETTING, GatewayService.RECOVER_AFTER_TIME_SETTING, NetworkModule.HTTP_ENABLED, + NetworkModule.HTTP_TYPE_SETTING, NetworkModule.TRANSPORT_SERVICE_TYPE_SETTING, NetworkModule.TRANSPORT_TYPE_SETTING, HttpTransportSettings.SETTING_CORS_ALLOW_CREDENTIALS, diff --git a/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java b/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java index 2ebeb1b2658..5d2f4d3054b 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java +++ b/core/src/main/java/org/elasticsearch/common/settings/SettingsModule.java @@ -38,7 +38,7 @@ public class SettingsModule extends AbstractModule { private final SettingsFilter settingsFilter; private final Map> clusterSettings = new HashMap<>(); private final Map> indexSettings = new HashMap<>(); - private static final Predicate NO_TRIBE_PREDICATE = (s) -> s.startsWith("tribe.") == false || TribeService.TRIBE_SETTING_KEYS.contains(s); + private static final Predicate TRIBE_CLIENT_NODE_SETTINGS_PREDICATE = (s) -> s.startsWith("tribe.") && TribeService.TRIBE_SETTING_KEYS.contains(s) == false; public SettingsModule(Settings settings, SettingsFilter settingsFilter) { @@ -58,8 +58,8 @@ public class SettingsModule extends AbstractModule { final ClusterSettings clusterSettings = new ClusterSettings(settings, new HashSet<>(this.clusterSettings.values())); // by now we are fully configured, lets check node level settings for unregistered index settings indexScopedSettings.validate(settings.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE)); - Predicate noIndexSettingPredicate = IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE.negate(); - clusterSettings.validate(settings.filter(NO_TRIBE_PREDICATE.and(noIndexSettingPredicate))); + final Predicate acceptOnlyClusterSettings = TRIBE_CLIENT_NODE_SETTINGS_PREDICATE.or(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE).negate(); + clusterSettings.validate(settings.filter(acceptOnlyClusterSettings)); validateTribeSettings(settings, clusterSettings); bind(Settings.class).toInstance(settings); bind(SettingsFilter.class).toInstance(settingsFilter); @@ -86,7 +86,7 @@ public class SettingsModule extends AbstractModule { } public void validateTribeSettings(Settings settings, ClusterSettings clusterSettings) { - Map groups = settings.filter(NO_TRIBE_PREDICATE.negate()).getGroups("tribe.", true); + Map groups = settings.filter(TRIBE_CLIENT_NODE_SETTINGS_PREDICATE).getGroups("tribe.", true); for (Map.Entry tribeSettings : groups.entrySet()) { Settings thisTribesSettings = tribeSettings.getValue(); for (Map.Entry entry : thisTribesSettings.getAsMap().entrySet()) { diff --git a/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java b/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java index 199f5124fa4..5504878bbef 100644 --- a/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java +++ b/core/src/main/java/org/elasticsearch/rest/action/main/RestMainAction.java @@ -27,6 +27,7 @@ import org.elasticsearch.cluster.ClusterService; import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.xcontent.XContentBuilder; +import org.elasticsearch.node.Node; import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.RestChannel; @@ -77,7 +78,7 @@ public class RestMainAction extends BaseRestHandler { builder.startObject(); assert settings.get("node.name") != null; - builder.field("name", settings.get("node.name")); + builder.field("name", Node.NODE_NAME_SETTING.get(settings)); builder.field("cluster_name", clusterName.value()); builder.startObject("version") .field("number", version.number()) diff --git a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java index ba5c075abec..c7f4392e56a 100644 --- a/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java +++ b/core/src/main/java/org/elasticsearch/threadpool/ThreadPool.java @@ -40,6 +40,7 @@ import org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler; import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilderString; +import org.elasticsearch.node.Node; import java.io.Closeable; import java.io.IOException; @@ -206,13 +207,13 @@ public class ThreadPool extends AbstractComponent implements Closeable { private final ThreadContext threadContext; public ThreadPool(String name) { - this(Settings.builder().put("node.name", name).build()); + this(Settings.builder().put(Node.NODE_NAME_SETTING.getKey(), name).build()); } public ThreadPool(Settings settings) { super(settings); - assert settings.get("node.name") != null : "ThreadPool's settings should contain a name"; + assert Node.NODE_NAME_SETTING.exists(settings) : "ThreadPool's settings should contain a name"; threadContext = new ThreadContext(settings); Map groupSettings = THREADPOOL_GROUP_SETTING.get(settings).getAsGroups(); validate(groupSettings); diff --git a/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java b/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java index 0fb9b1a92fb..4090daa23a0 100644 --- a/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java +++ b/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java @@ -127,7 +127,7 @@ public class NetworkModuleTests extends ModuleTestCase { } public void testRegisterHttpTransport() { - Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_KEY, "custom").build(); + Settings settings = Settings.builder().put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom").build(); NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, null); module.registerHttpTransport("custom", FakeHttpTransport.class); assertBinding(module, HttpServerTransport.class, FakeHttpTransport.class); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ExternalNode.java b/test/framework/src/main/java/org/elasticsearch/test/ExternalNode.java index 1a7164ff5a6..ea106bf9b98 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ExternalNode.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ExternalNode.java @@ -194,7 +194,7 @@ final class ExternalNode implements Closeable { Settings clientSettings = settingsBuilder().put(externalNodeSettings) .put("client.transport.nodes_sampler_interval", "1s") - .put("name", "transport_client_" + nodeInfo.getNode().name()) + .put("node.name", "transport_client_" + nodeInfo.getNode().name()) .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName).put("client.transport.sniff", false).build(); TransportClient client = TransportClient.builder().settings(clientSettings).build(); client.addTransportAddress(addr); diff --git a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java index cbd2669c92c..c997a41ad6d 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java +++ b/test/framework/src/main/java/org/elasticsearch/test/ExternalTestCluster.java @@ -73,7 +73,7 @@ public final class ExternalTestCluster extends TestCluster { super(0); Settings clientSettings = Settings.settingsBuilder() .put(additionalSettings) - .put("node. name", InternalTestCluster.TRANSPORT_CLIENT_PREFIX + EXTERNAL_CLUSTER_PREFIX + counter.getAndIncrement()) + .put("node.name", InternalTestCluster.TRANSPORT_CLIENT_PREFIX + EXTERNAL_CLUSTER_PREFIX + counter.getAndIncrement()) .put(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING.getKey(), true) // prevents any settings to be replaced by system properties. .put("client.transport.ignore_cluster_name", true) .put(Environment.PATH_HOME_SETTING.getKey(), tempDir)