diff --git a/core/src/main/java/org/elasticsearch/action/support/ThreadedActionListener.java b/core/src/main/java/org/elasticsearch/action/support/ThreadedActionListener.java index 2a2bdd7a061..6ed52e1ac46 100644 --- a/core/src/main/java/org/elasticsearch/action/support/ThreadedActionListener.java +++ b/core/src/main/java/org/elasticsearch/action/support/ThreadedActionListener.java @@ -50,7 +50,7 @@ public final class ThreadedActionListener implements ActionListener ActionListener wrap(ActionListener listener) { diff --git a/core/src/main/java/org/elasticsearch/client/Client.java b/core/src/main/java/org/elasticsearch/client/Client.java index e7461dabfe1..7795929b1c1 100644 --- a/core/src/main/java/org/elasticsearch/client/Client.java +++ b/core/src/main/java/org/elasticsearch/client/Client.java @@ -83,8 +83,11 @@ import org.elasticsearch.action.update.UpdateResponse; import org.elasticsearch.client.support.Headers; import org.elasticsearch.common.Nullable; import org.elasticsearch.common.lease.Releasable; +import org.elasticsearch.common.settings.Setting; import org.elasticsearch.common.settings.Settings; +import java.util.function.Function; + /** * A client provides a one stop interface for performing actions/operations against the cluster. *

@@ -100,7 +103,15 @@ import org.elasticsearch.common.settings.Settings; */ public interface Client extends ElasticsearchClient, Releasable { - String CLIENT_TYPE_SETTING = "client.type"; + Setting CLIENT_TYPE_SETTING_S = new Setting<>("client.type", "node", (s) -> { + switch (s) { + case "node": + case "transport": + return s; + default: + throw new IllegalArgumentException("Can't parse [client.type] must be one of [node, transport]"); + } + }, false, Setting.Scope.CLUSTER); /** * The admin client that can be used to perform administrative operations. diff --git a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java index ea809a8cc38..e6735840736 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -115,7 +115,7 @@ public class TransportClient extends AbstractClient { .put( InternalSettingsPreparer.prepareSettings(settings)) .put("network.server", false) .put(Node.NODE_CLIENT_SETTING.getKey(), true) - .put(CLIENT_TYPE_SETTING, CLIENT_TYPE); + .put(CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE); return new PluginsService(settingsBuilder.build(), null, null, pluginClasses); } 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 7306ae6ce95..0d9362929ce 100644 --- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java +++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java @@ -22,6 +22,7 @@ import org.elasticsearch.action.admin.indices.close.TransportCloseIndexAction; import org.elasticsearch.action.support.AutoCreateIndex; import org.elasticsearch.action.support.DestructiveOperations; import org.elasticsearch.action.support.master.TransportMasterNodeReadAction; +import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClientNodesService; import org.elasticsearch.cluster.ClusterModule; import org.elasticsearch.cluster.ClusterName; @@ -270,6 +271,7 @@ public final class ClusterSettings extends AbstractScopedSettings { AutoCreateIndex.AUTO_CREATE_INDEX_SETTING, BaseRestHandler.MULTI_ALLOW_EXPLICIT_INDEX, ClusterName.CLUSTER_NAME_SETTING, + Client.CLIENT_TYPE_SETTING_S, InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING, EsExecutors.PROCESSORS_SETTING))); diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index ea9d0be1eec..2678636ea24 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -149,7 +149,7 @@ public class Node implements Releasable { protected Node(Environment tmpEnv, Version version, Collection> classpathPlugins) { Settings tmpSettings = settingsBuilder().put(tmpEnv.settings()) - .put(Client.CLIENT_TYPE_SETTING, CLIENT_TYPE).build(); + .put(Client.CLIENT_TYPE_SETTING_S.getKey(), CLIENT_TYPE).build(); tmpSettings = TribeService.processSettings(tmpSettings); ESLogger logger = Loggers.getLogger(Node.class, tmpSettings.get("name")); diff --git a/core/src/test/java/org/elasticsearch/action/ListenerActionIT.java b/core/src/test/java/org/elasticsearch/action/ListenerActionIT.java index f68cb76c955..a9bb96a0a9f 100644 --- a/core/src/test/java/org/elasticsearch/action/ListenerActionIT.java +++ b/core/src/test/java/org/elasticsearch/action/ListenerActionIT.java @@ -61,7 +61,7 @@ public class ListenerActionIT extends ESIntegTestCase { latch.await(); - boolean shouldBeThreaded = DiscoveryNode.clientNode(client.settings()) || TransportClient.CLIENT_TYPE.equals(client.settings().get(Client.CLIENT_TYPE_SETTING)); + boolean shouldBeThreaded = DiscoveryNode.clientNode(client.settings()) || TransportClient.CLIENT_TYPE.equals(Client.CLIENT_TYPE_SETTING_S.get(client.settings())); if (shouldBeThreaded) { assertTrue(threadName.get().contains("listener")); } else { diff --git a/core/src/test/java/org/elasticsearch/client/node/NodeClientIT.java b/core/src/test/java/org/elasticsearch/client/node/NodeClientIT.java index 966553b8f3d..ae839e8837e 100644 --- a/core/src/test/java/org/elasticsearch/client/node/NodeClientIT.java +++ b/core/src/test/java/org/elasticsearch/client/node/NodeClientIT.java @@ -34,12 +34,12 @@ import static org.hamcrest.Matchers.is; public class NodeClientIT extends ESIntegTestCase { @Override protected Settings nodeSettings(int nodeOrdinal) { - return settingsBuilder().put(super.nodeSettings(nodeOrdinal)).put(Client.CLIENT_TYPE_SETTING, "anything").build(); + return settingsBuilder().put(super.nodeSettings(nodeOrdinal)).put(Client.CLIENT_TYPE_SETTING_S.getKey(), "anything").build(); } public void testThatClientTypeSettingCannotBeChanged() { for (Settings settings : internalCluster().getInstances(Settings.class)) { - assertThat(settings.get(Client.CLIENT_TYPE_SETTING), is("node")); + assertThat(Client.CLIENT_TYPE_SETTING_S.get(settings), is("node")); } } } diff --git a/core/src/test/java/org/elasticsearch/client/transport/TransportClientIT.java b/core/src/test/java/org/elasticsearch/client/transport/TransportClientIT.java index 673dbca80ac..a561b5bcf7b 100644 --- a/core/src/test/java/org/elasticsearch/client/transport/TransportClientIT.java +++ b/core/src/test/java/org/elasticsearch/client/transport/TransportClientIT.java @@ -86,17 +86,16 @@ public class TransportClientIT extends ESIntegTestCase { public void testThatTransportClientSettingIsSet() { TransportClient client = (TransportClient) internalCluster().client(); Settings settings = client.injector.getInstance(Settings.class); - assertThat(settings.get(Client.CLIENT_TYPE_SETTING), is("transport")); + assertThat(Client.CLIENT_TYPE_SETTING_S.get(settings), is("transport")); } public void testThatTransportClientSettingCannotBeChanged() { Settings baseSettings = settingsBuilder() - .put(Client.CLIENT_TYPE_SETTING, "anything") .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); try (TransportClient client = TransportClient.builder().settings(baseSettings).build()) { Settings settings = client.injector.getInstance(Settings.class); - assertThat(settings.get(Client.CLIENT_TYPE_SETTING), is("transport")); + assertThat(Client.CLIENT_TYPE_SETTING_S.get(settings), is("transport")); } } }