Apply feedback from @bleskes and add fix some minor issues

This commit is contained in:
Simon Willnauer 2016-02-03 10:44:06 +01:00
parent 818a9eefb2
commit ed492901ed
8 changed files with 16 additions and 13 deletions

View File

@ -150,10 +150,11 @@ public class NetworkModule extends AbstractModule {
public static final String TRANSPORT_TYPE_KEY = "transport.type"; public static final String TRANSPORT_TYPE_KEY = "transport.type";
public static final String TRANSPORT_SERVICE_TYPE_KEY = "transport.service.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 LOCAL_TRANSPORT = "local";
public static final String NETTY_TRANSPORT = "netty"; public static final String NETTY_TRANSPORT = "netty";
public static final String HTTP_TYPE_KEY = "http.type"; public static final Setting<String> HTTP_TYPE_SETTING = Setting.simpleString("http.type", false, Scope.CLUSTER);
public static final Setting<Boolean> HTTP_ENABLED = Setting.boolSetting("http.enabled", true, false, Scope.CLUSTER); public static final Setting<Boolean> HTTP_ENABLED = Setting.boolSetting("http.enabled", true, false, Scope.CLUSTER);
public static final Setting<String> TRANSPORT_SERVICE_TYPE_SETTING = Setting.simpleString("transport.service.type", false, Scope.CLUSTER); public static final Setting<String> TRANSPORT_SERVICE_TYPE_SETTING = Setting.simpleString("transport.service.type", false, Scope.CLUSTER);
public static final Setting<String> TRANSPORT_TYPE_SETTING = Setting.simpleString("transport.type", false, Scope.CLUSTER); public static final Setting<String> TRANSPORT_TYPE_SETTING = Setting.simpleString("transport.type", false, Scope.CLUSTER);
@ -162,7 +163,6 @@ public class NetworkModule extends AbstractModule {
private static final List<Class<? extends RestHandler>> builtinRestHandlers = Arrays.asList( private static final List<Class<? extends RestHandler>> builtinRestHandlers = Arrays.asList(
RestMainAction.class, RestMainAction.class,
RestNodesInfoAction.class, RestNodesInfoAction.class,
RestNodesStatsAction.class, RestNodesStatsAction.class,
RestNodesHotThreadsAction.class, RestNodesHotThreadsAction.class,
@ -383,7 +383,7 @@ public class NetworkModule extends AbstractModule {
} else { } else {
if (HTTP_ENABLED.get(settings)) { if (HTTP_ENABLED.get(settings)) {
bind(HttpServer.class).asEagerSingleton(); 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(); bind(RestController.class).asEagerSingleton();
catHandlers.bind(binder()); catHandlers.bind(binder());

View File

@ -209,6 +209,7 @@ public final class ClusterSettings extends AbstractScopedSettings {
GatewayService.RECOVER_AFTER_NODES_SETTING, GatewayService.RECOVER_AFTER_NODES_SETTING,
GatewayService.RECOVER_AFTER_TIME_SETTING, GatewayService.RECOVER_AFTER_TIME_SETTING,
NetworkModule.HTTP_ENABLED, NetworkModule.HTTP_ENABLED,
NetworkModule.HTTP_TYPE_SETTING,
NetworkModule.TRANSPORT_SERVICE_TYPE_SETTING, NetworkModule.TRANSPORT_SERVICE_TYPE_SETTING,
NetworkModule.TRANSPORT_TYPE_SETTING, NetworkModule.TRANSPORT_TYPE_SETTING,
HttpTransportSettings.SETTING_CORS_ALLOW_CREDENTIALS, HttpTransportSettings.SETTING_CORS_ALLOW_CREDENTIALS,

View File

@ -38,7 +38,7 @@ public class SettingsModule extends AbstractModule {
private final SettingsFilter settingsFilter; private final SettingsFilter settingsFilter;
private final Map<String, Setting<?>> clusterSettings = new HashMap<>(); private final Map<String, Setting<?>> clusterSettings = new HashMap<>();
private final Map<String, Setting<?>> indexSettings = new HashMap<>(); private final Map<String, Setting<?>> indexSettings = new HashMap<>();
private static final Predicate<String> NO_TRIBE_PREDICATE = (s) -> s.startsWith("tribe.") == false || TribeService.TRIBE_SETTING_KEYS.contains(s); private static final Predicate<String> TRIBE_CLIENT_NODE_SETTINGS_PREDICATE = (s) -> s.startsWith("tribe.") && TribeService.TRIBE_SETTING_KEYS.contains(s) == false;
public SettingsModule(Settings settings, SettingsFilter settingsFilter) { 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())); 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 // by now we are fully configured, lets check node level settings for unregistered index settings
indexScopedSettings.validate(settings.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE)); indexScopedSettings.validate(settings.filter(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE));
Predicate<String> noIndexSettingPredicate = IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE.negate(); final Predicate<String> acceptOnlyClusterSettings = TRIBE_CLIENT_NODE_SETTINGS_PREDICATE.or(IndexScopedSettings.INDEX_SETTINGS_KEY_PREDICATE).negate();
clusterSettings.validate(settings.filter(NO_TRIBE_PREDICATE.and(noIndexSettingPredicate))); clusterSettings.validate(settings.filter(acceptOnlyClusterSettings));
validateTribeSettings(settings, clusterSettings); validateTribeSettings(settings, clusterSettings);
bind(Settings.class).toInstance(settings); bind(Settings.class).toInstance(settings);
bind(SettingsFilter.class).toInstance(settingsFilter); bind(SettingsFilter.class).toInstance(settingsFilter);
@ -86,7 +86,7 @@ public class SettingsModule extends AbstractModule {
} }
public void validateTribeSettings(Settings settings, ClusterSettings clusterSettings) { public void validateTribeSettings(Settings settings, ClusterSettings clusterSettings) {
Map<String, Settings> groups = settings.filter(NO_TRIBE_PREDICATE.negate()).getGroups("tribe.", true); Map<String, Settings> groups = settings.filter(TRIBE_CLIENT_NODE_SETTINGS_PREDICATE).getGroups("tribe.", true);
for (Map.Entry<String, Settings> tribeSettings : groups.entrySet()) { for (Map.Entry<String, Settings> tribeSettings : groups.entrySet()) {
Settings thisTribesSettings = tribeSettings.getValue(); Settings thisTribesSettings = tribeSettings.getValue();
for (Map.Entry<String, String> entry : thisTribesSettings.getAsMap().entrySet()) { for (Map.Entry<String, String> entry : thisTribesSettings.getAsMap().entrySet()) {

View File

@ -27,6 +27,7 @@ import org.elasticsearch.cluster.ClusterService;
import org.elasticsearch.common.inject.Inject; import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.node.Node;
import org.elasticsearch.rest.BaseRestHandler; import org.elasticsearch.rest.BaseRestHandler;
import org.elasticsearch.rest.BytesRestResponse; import org.elasticsearch.rest.BytesRestResponse;
import org.elasticsearch.rest.RestChannel; import org.elasticsearch.rest.RestChannel;
@ -77,7 +78,7 @@ public class RestMainAction extends BaseRestHandler {
builder.startObject(); builder.startObject();
assert settings.get("node.name") != null; 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.field("cluster_name", clusterName.value());
builder.startObject("version") builder.startObject("version")
.field("number", version.number()) .field("number", version.number())

View File

@ -40,6 +40,7 @@ import org.elasticsearch.common.util.concurrent.XRejectedExecutionHandler;
import org.elasticsearch.common.xcontent.ToXContent; import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentBuilderString; import org.elasticsearch.common.xcontent.XContentBuilderString;
import org.elasticsearch.node.Node;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
@ -206,13 +207,13 @@ public class ThreadPool extends AbstractComponent implements Closeable {
private final ThreadContext threadContext; private final ThreadContext threadContext;
public ThreadPool(String name) { 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) { public ThreadPool(Settings settings) {
super(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); threadContext = new ThreadContext(settings);
Map<String, Settings> groupSettings = THREADPOOL_GROUP_SETTING.get(settings).getAsGroups(); Map<String, Settings> groupSettings = THREADPOOL_GROUP_SETTING.get(settings).getAsGroups();
validate(groupSettings); validate(groupSettings);

View File

@ -127,7 +127,7 @@ public class NetworkModuleTests extends ModuleTestCase {
} }
public void testRegisterHttpTransport() { 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); NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, null);
module.registerHttpTransport("custom", FakeHttpTransport.class); module.registerHttpTransport("custom", FakeHttpTransport.class);
assertBinding(module, HttpServerTransport.class, FakeHttpTransport.class); assertBinding(module, HttpServerTransport.class, FakeHttpTransport.class);

View File

@ -194,7 +194,7 @@ final class ExternalNode implements Closeable {
Settings clientSettings = settingsBuilder().put(externalNodeSettings) Settings clientSettings = settingsBuilder().put(externalNodeSettings)
.put("client.transport.nodes_sampler_interval", "1s") .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(); .put(ClusterName.CLUSTER_NAME_SETTING.getKey(), clusterName).put("client.transport.sniff", false).build();
TransportClient client = TransportClient.builder().settings(clientSettings).build(); TransportClient client = TransportClient.builder().settings(clientSettings).build();
client.addTransportAddress(addr); client.addTransportAddress(addr);

View File

@ -73,7 +73,7 @@ public final class ExternalTestCluster extends TestCluster {
super(0); super(0);
Settings clientSettings = Settings.settingsBuilder() Settings clientSettings = Settings.settingsBuilder()
.put(additionalSettings) .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(InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING.getKey(), true) // prevents any settings to be replaced by system properties.
.put("client.transport.ignore_cluster_name", true) .put("client.transport.ignore_cluster_name", true)
.put(Environment.PATH_HOME_SETTING.getKey(), tempDir) .put(Environment.PATH_HOME_SETTING.getKey(), tempDir)