Convert `client.type` to new settings infra

This commit is contained in:
Simon Willnauer 2016-01-27 16:20:26 +01:00
parent bbba1e5d7f
commit d296d26ce2
8 changed files with 22 additions and 10 deletions

View File

@ -50,7 +50,7 @@ public final class ThreadedActionListener<Response> implements ActionListener<Re
this.threadPool = threadPool;
// Should the action listener be threaded or not by default. Action listeners are automatically threaded for client
// nodes and transport client in order to make sure client side code is not executed on IO threads.
this.threadedListener = DiscoveryNode.clientNode(settings) || TransportClient.CLIENT_TYPE.equals(settings.get(Client.CLIENT_TYPE_SETTING));
this.threadedListener = DiscoveryNode.clientNode(settings) || TransportClient.CLIENT_TYPE.equals(Client.CLIENT_TYPE_SETTING_S.get(settings));
}
public <Response> ActionListener<Response> wrap(ActionListener<Response> listener) {

View File

@ -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.
* <p>
@ -100,7 +103,15 @@ import org.elasticsearch.common.settings.Settings;
*/
public interface Client extends ElasticsearchClient, Releasable {
String CLIENT_TYPE_SETTING = "client.type";
Setting<String> 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.

View File

@ -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);
}

View File

@ -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)));

View File

@ -149,7 +149,7 @@ public class Node implements Releasable {
protected Node(Environment tmpEnv, Version version, Collection<Class<? extends Plugin>> 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"));

View File

@ -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 {

View File

@ -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"));
}
}
}

View File

@ -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"));
}
}
}