Convert `request.headers.*` to the new settings infra

This commit is contained in:
Simon Willnauer 2016-01-28 14:55:26 +01:00
parent d65635e478
commit 7ddf842348
2 changed files with 6 additions and 2 deletions

View File

@ -42,6 +42,7 @@ import org.elasticsearch.cluster.routing.allocation.decider.ThrottlingAllocation
import org.elasticsearch.cluster.service.InternalClusterService; import org.elasticsearch.cluster.service.InternalClusterService;
import org.elasticsearch.common.logging.ESLoggerFactory; import org.elasticsearch.common.logging.ESLoggerFactory;
import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.ThreadContext;
import org.elasticsearch.discovery.DiscoveryModule; import org.elasticsearch.discovery.DiscoveryModule;
import org.elasticsearch.discovery.DiscoveryService; import org.elasticsearch.discovery.DiscoveryService;
import org.elasticsearch.common.network.NetworkModule; import org.elasticsearch.common.network.NetworkModule;
@ -278,5 +279,6 @@ public final class ClusterSettings extends AbstractScopedSettings {
Client.CLIENT_TYPE_SETTING_S, Client.CLIENT_TYPE_SETTING_S,
InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING, InternalSettingsPreparer.IGNORE_SYSTEM_PROPERTIES_SETTING,
ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING, ClusterModule.SHARDS_ALLOCATOR_TYPE_SETTING,
EsExecutors.PROCESSORS_SETTING))); EsExecutors.PROCESSORS_SETTING,
ThreadContext.DEFAULT_HEADERS_SETTING)));
} }

View File

@ -23,6 +23,7 @@ import org.elasticsearch.common.collect.Iterators;
import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput; import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.io.stream.Writeable; import org.elasticsearch.common.io.stream.Writeable;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.settings.Settings;
import java.io.Closeable; import java.io.Closeable;
@ -62,6 +63,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
public final class ThreadContext implements Closeable, Writeable<ThreadContext.ThreadContextStruct>{ public final class ThreadContext implements Closeable, Writeable<ThreadContext.ThreadContextStruct>{
public static final String PREFIX = "request.headers"; public static final String PREFIX = "request.headers";
public static final Setting<Settings> DEFAULT_HEADERS_SETTING = Setting.groupSetting(PREFIX + ".", false, Setting.Scope.CLUSTER);
private final Map<String, String> defaultHeader; private final Map<String, String> defaultHeader;
private static final ThreadContextStruct DEFAULT_CONTEXT = new ThreadContextStruct(Collections.emptyMap()); private static final ThreadContextStruct DEFAULT_CONTEXT = new ThreadContextStruct(Collections.emptyMap());
private final ContextThreadLocal threadLocal; private final ContextThreadLocal threadLocal;
@ -71,7 +73,7 @@ public final class ThreadContext implements Closeable, Writeable<ThreadContext.T
* @param settings the settings to read the default request headers from * @param settings the settings to read the default request headers from
*/ */
public ThreadContext(Settings settings) { public ThreadContext(Settings settings) {
Settings headers = settings.getAsSettings(PREFIX); Settings headers = DEFAULT_HEADERS_SETTING.get(settings);
if (headers == null) { if (headers == null) {
this.defaultHeader = Collections.emptyMap(); this.defaultHeader = Collections.emptyMap();
} else { } else {