summaryrefslogtreecommitdiff
path: root/core/src/main/java/org/elasticsearch
diff options
context:
space:
mode:
authorSimon Willnauer <simonw@apache.org>2017-07-02 10:16:50 +0200
committerGitHub <noreply@github.com>2017-07-02 10:16:50 +0200
commit5a7c8bb04ed135be1823a4db6b08f7481d7d22c0 (patch)
treeefbc4ac1d1f0bf0f09c4587d74de16d3d5096a84 /core/src/main/java/org/elasticsearch
parent2975e7f511d784b1a1d6dfea95d3e75ab241dfdb (diff)
Cleanup network / transport related settings (#25489)
This commit makes the use of the global network settings explicit instead of implicit within NetworkService. It cleans up several places where we fall back to the global settings while we should have used tcp or http ones. In addition this change also removes unnecessary settings classes
Diffstat (limited to 'core/src/main/java/org/elasticsearch')
-rw-r--r--core/src/main/java/org/elasticsearch/bootstrap/Security.java10
-rw-r--r--core/src/main/java/org/elasticsearch/client/transport/TransportClient.java2
-rw-r--r--core/src/main/java/org/elasticsearch/common/network/NetworkService.java89
-rw-r--r--core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java25
-rw-r--r--core/src/main/java/org/elasticsearch/node/Node.java6
-rw-r--r--core/src/main/java/org/elasticsearch/transport/TcpTransport.java76
-rw-r--r--core/src/main/java/org/elasticsearch/transport/TransportSettings.java56
-rw-r--r--core/src/main/java/org/elasticsearch/tribe/TribeService.java8
8 files changed, 104 insertions, 168 deletions
diff --git a/core/src/main/java/org/elasticsearch/bootstrap/Security.java b/core/src/main/java/org/elasticsearch/bootstrap/Security.java
index 9504bdefa5..075456cd9e 100644
--- a/core/src/main/java/org/elasticsearch/bootstrap/Security.java
+++ b/core/src/main/java/org/elasticsearch/bootstrap/Security.java
@@ -27,7 +27,7 @@ import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.env.Environment;
import org.elasticsearch.http.HttpTransportSettings;
import org.elasticsearch.plugins.PluginInfo;
-import org.elasticsearch.transport.TransportSettings;
+import org.elasticsearch.transport.TcpTransport;
import java.io.FilePermission;
import java.io.IOException;
@@ -324,8 +324,8 @@ final class Security {
final Permissions policy,
final Settings settings) {
// transport is way over-engineered
- final Map<String, Settings> profiles = new HashMap<>(TransportSettings.TRANSPORT_PROFILES_SETTING.get(settings).getAsGroups());
- profiles.putIfAbsent(TransportSettings.DEFAULT_PROFILE, Settings.EMPTY);
+ final Map<String, Settings> profiles = new HashMap<>(TcpTransport.TRANSPORT_PROFILES_SETTING.get(settings).getAsGroups());
+ profiles.putIfAbsent(TcpTransport.DEFAULT_PROFILE, Settings.EMPTY);
// loop through all profiles and add permissions for each one, if it's valid; otherwise Netty transports are lenient and ignores it
for (final Map.Entry<String, Settings> entry : profiles.entrySet()) {
@@ -335,7 +335,7 @@ final class Security {
// a profile is only valid if it's the default profile, or if it has an actual name and specifies a port
// TODO: can this leniency be removed?
final boolean valid =
- TransportSettings.DEFAULT_PROFILE.equals(name) ||
+ TcpTransport.DEFAULT_PROFILE.equals(name) ||
(name != null && name.length() > 0 && profileSettings.get("port") != null);
if (valid) {
final String transportRange = profileSettings.get("port");
@@ -355,7 +355,7 @@ final class Security {
* @param settings the {@link Settings} instance to read the transport settings from
*/
private static void addSocketPermissionForTransport(final Permissions policy, final Settings settings) {
- final String transportRange = TransportSettings.PORT.get(settings);
+ final String transportRange = TcpTransport.PORT.get(settings);
addSocketPermissionForPortRange(policy, transportRange);
}
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 1cf79c26d9..83cdd95119 100644
--- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java
+++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java
@@ -127,7 +127,7 @@ public abstract class TransportClient extends AbstractClient {
final List<Closeable> resourcesToClose = new ArrayList<>();
final ThreadPool threadPool = new ThreadPool(settings);
resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS));
- final NetworkService networkService = new NetworkService(settings, Collections.emptyList());
+ final NetworkService networkService = new NetworkService(Collections.emptyList());
try {
final List<Setting<?>> additionalSettings = new ArrayList<>(pluginsService.getPluginSettings());
final List<String> additionalSettingsFilter = new ArrayList<>(pluginsService.getPluginSettingsFilter());
diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkService.java b/core/src/main/java/org/elasticsearch/common/network/NetworkService.java
index a9d3dc4a33..b9440edd5c 100644
--- a/core/src/main/java/org/elasticsearch/common/network/NetworkService.java
+++ b/core/src/main/java/org/elasticsearch/common/network/NetworkService.java
@@ -19,11 +19,8 @@
package org.elasticsearch.common.network;
-import org.elasticsearch.common.Strings;
-import org.elasticsearch.common.component.AbstractComponent;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Setting.Property;
-import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
@@ -31,38 +28,37 @@ import java.io.IOException;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
+import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
-public class NetworkService extends AbstractComponent {
+public final class NetworkService {
/** By default, we bind to loopback interfaces */
public static final String DEFAULT_NETWORK_HOST = "_local_";
-
public static final Setting<List<String>> GLOBAL_NETWORK_HOST_SETTING =
- Setting.listSetting("network.host", Arrays.asList(DEFAULT_NETWORK_HOST), Function.identity(), Property.NodeScope);
+ Setting.listSetting("network.host", Collections.emptyList(), Function.identity(), Property.NodeScope);
public static final Setting<List<String>> GLOBAL_NETWORK_BINDHOST_SETTING =
Setting.listSetting("network.bind_host", GLOBAL_NETWORK_HOST_SETTING, Function.identity(), Property.NodeScope);
public static final Setting<List<String>> GLOBAL_NETWORK_PUBLISHHOST_SETTING =
Setting.listSetting("network.publish_host", GLOBAL_NETWORK_HOST_SETTING, Function.identity(), Property.NodeScope);
public static final Setting<Boolean> NETWORK_SERVER = Setting.boolSetting("network.server", true, Property.NodeScope);
- public static final class TcpSettings {
- public static final Setting<Boolean> TCP_NO_DELAY =
- Setting.boolSetting("network.tcp.no_delay", true, Property.NodeScope);
- public static final Setting<Boolean> TCP_KEEP_ALIVE =
- Setting.boolSetting("network.tcp.keep_alive", true, Property.NodeScope);
- public static final Setting<Boolean> TCP_REUSE_ADDRESS =
- Setting.boolSetting("network.tcp.reuse_address", NetworkUtils.defaultReuseAddress(), Property.NodeScope);
- public static final Setting<ByteSizeValue> TCP_SEND_BUFFER_SIZE =
- Setting.byteSizeSetting("network.tcp.send_buffer_size", new ByteSizeValue(-1), Property.NodeScope);
- public static final Setting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE =
- Setting.byteSizeSetting("network.tcp.receive_buffer_size", new ByteSizeValue(-1), Property.NodeScope);
- public static final Setting<TimeValue> TCP_CONNECT_TIMEOUT =
- Setting.timeSetting("network.tcp.connect_timeout", new TimeValue(30, TimeUnit.SECONDS), Property.NodeScope);
- }
+ public static final Setting<Boolean> TCP_NO_DELAY =
+ Setting.boolSetting("network.tcp.no_delay", true, Property.NodeScope);
+ public static final Setting<Boolean> TCP_KEEP_ALIVE =
+ Setting.boolSetting("network.tcp.keep_alive", true, Property.NodeScope);
+ public static final Setting<Boolean> TCP_REUSE_ADDRESS =
+ Setting.boolSetting("network.tcp.reuse_address", NetworkUtils.defaultReuseAddress(), Property.NodeScope);
+ public static final Setting<ByteSizeValue> TCP_SEND_BUFFER_SIZE =
+ Setting.byteSizeSetting("network.tcp.send_buffer_size", new ByteSizeValue(-1), Property.NodeScope);
+ public static final Setting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE =
+ Setting.byteSizeSetting("network.tcp.receive_buffer_size", new ByteSizeValue(-1), Property.NodeScope);
+ public static final Setting<TimeValue> TCP_CONNECT_TIMEOUT =
+ Setting.timeSetting("network.tcp.connect_timeout", new TimeValue(30, TimeUnit.SECONDS), Property.NodeScope);
/**
* A custom name resolver can support custom lookup keys (my_net_key:ipv4) and also change
@@ -82,9 +78,8 @@ public class NetworkService extends AbstractComponent {
private final List<CustomNameResolver> customNameResolvers;
- public NetworkService(Settings settings, List<CustomNameResolver> customNameResolvers) {
- super(settings);
- this.customNameResolvers = customNameResolvers;
+ public NetworkService(List<CustomNameResolver> customNameResolvers) {
+ this.customNameResolvers = Objects.requireNonNull(customNameResolvers, "customNameResolvers must be non null");
}
/**
@@ -92,29 +87,20 @@ public class NetworkService extends AbstractComponent {
* not contain duplicate addresses.
*
* @param bindHosts list of hosts to bind to. this may contain special pseudo-hostnames
- * such as _local_ (see the documentation). if it is null, it will be populated
- * based on global default settings.
+ * such as _local_ (see the documentation). if it is null, it will fall back to _local_
+ *
* @return unique set of internet addresses
*/
public InetAddress[] resolveBindHostAddresses(String bindHosts[]) throws IOException {
- // first check settings
if (bindHosts == null || bindHosts.length == 0) {
- if (GLOBAL_NETWORK_BINDHOST_SETTING.exists(settings) || GLOBAL_NETWORK_HOST_SETTING.exists(settings)) {
- // if we have settings use them (we have a fallback to GLOBAL_NETWORK_HOST_SETTING inline
- bindHosts = GLOBAL_NETWORK_BINDHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
- } else {
- // next check any registered custom resolvers if any
- if (customNameResolvers != null) {
- for (CustomNameResolver customNameResolver : customNameResolvers) {
- InetAddress addresses[] = customNameResolver.resolveDefault();
- if (addresses != null) {
- return addresses;
- }
- }
+ for (CustomNameResolver customNameResolver : customNameResolvers) {
+ InetAddress addresses[] = customNameResolver.resolveDefault();
+ if (addresses != null) {
+ return addresses;
}
- // we know it's not here. get the defaults
- bindHosts = GLOBAL_NETWORK_BINDHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
}
+ // we know it's not here. get the defaults
+ bindHosts = new String[] {"_local_"};
}
InetAddress addresses[] = resolveInetAddresses(bindHosts);
@@ -140,29 +126,20 @@ public class NetworkService extends AbstractComponent {
* If {@code publishHosts} resolves to more than one address, <b>then one is selected with magic</b>
*
* @param publishHosts list of hosts to publish as. this may contain special pseudo-hostnames
- * such as _local_ (see the documentation). if it is null, it will be populated
- * based on global default settings.
+ * such as _local_ (see the documentation). if it is null, it will fall back to _local_
* @return single internet address
*/
// TODO: needs to be InetAddress[]
public InetAddress resolvePublishHostAddresses(String publishHosts[]) throws IOException {
if (publishHosts == null || publishHosts.length == 0) {
- if (GLOBAL_NETWORK_PUBLISHHOST_SETTING.exists(settings) || GLOBAL_NETWORK_HOST_SETTING.exists(settings)) {
- // if we have settings use them (we have a fallback to GLOBAL_NETWORK_HOST_SETTING inline
- publishHosts = GLOBAL_NETWORK_PUBLISHHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
- } else {
- // next check any registered custom resolvers if any
- if (customNameResolvers != null) {
- for (CustomNameResolver customNameResolver : customNameResolvers) {
- InetAddress addresses[] = customNameResolver.resolveDefault();
- if (addresses != null) {
- return addresses[0];
- }
- }
+ for (CustomNameResolver customNameResolver : customNameResolvers) {
+ InetAddress addresses[] = customNameResolver.resolveDefault();
+ if (addresses != null) {
+ return addresses[0];
}
- // we know it's not here. get the defaults
- publishHosts = GLOBAL_NETWORK_PUBLISHHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
}
+ // we know it's not here. get the defaults
+ publishHosts = new String[] {DEFAULT_NETWORK_HOST};
}
InetAddress addresses[] = resolveInetAddresses(publishHosts);
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 15dffc427e..febede42da 100644
--- a/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java
+++ b/core/src/main/java/org/elasticsearch/common/settings/ClusterSettings.java
@@ -91,7 +91,6 @@ import org.elasticsearch.transport.RemoteClusterService;
import org.elasticsearch.transport.TcpTransport;
import org.elasticsearch.transport.Transport;
import org.elasticsearch.transport.TransportService;
-import org.elasticsearch.transport.TransportSettings;
import org.elasticsearch.tribe.TribeService;
import org.elasticsearch.watcher.ResourceWatcherService;
@@ -270,12 +269,12 @@ public final class ClusterSettings extends AbstractScopedSettings {
HierarchyCircuitBreakerService.FIELDDATA_CIRCUIT_BREAKER_TYPE_SETTING,
HierarchyCircuitBreakerService.REQUEST_CIRCUIT_BREAKER_TYPE_SETTING,
Transport.TRANSPORT_TCP_COMPRESS,
- TransportSettings.TRANSPORT_PROFILES_SETTING,
- TransportSettings.HOST,
- TransportSettings.PUBLISH_HOST,
- TransportSettings.BIND_HOST,
- TransportSettings.PUBLISH_PORT,
- TransportSettings.PORT,
+ TcpTransport.TRANSPORT_PROFILES_SETTING,
+ TcpTransport.HOST,
+ TcpTransport.PUBLISH_HOST,
+ TcpTransport.BIND_HOST,
+ TcpTransport.PUBLISH_PORT,
+ TcpTransport.PORT,
TcpTransport.CONNECTIONS_PER_NODE_RECOVERY,
TcpTransport.CONNECTIONS_PER_NODE_BULK,
TcpTransport.CONNECTIONS_PER_NODE_REG,
@@ -292,12 +291,12 @@ public final class ClusterSettings extends AbstractScopedSettings {
NetworkService.GLOBAL_NETWORK_HOST_SETTING,
NetworkService.GLOBAL_NETWORK_BINDHOST_SETTING,
NetworkService.GLOBAL_NETWORK_PUBLISHHOST_SETTING,
- NetworkService.TcpSettings.TCP_NO_DELAY,
- NetworkService.TcpSettings.TCP_KEEP_ALIVE,
- NetworkService.TcpSettings.TCP_REUSE_ADDRESS,
- NetworkService.TcpSettings.TCP_SEND_BUFFER_SIZE,
- NetworkService.TcpSettings.TCP_RECEIVE_BUFFER_SIZE,
- NetworkService.TcpSettings.TCP_CONNECT_TIMEOUT,
+ NetworkService.TCP_NO_DELAY,
+ NetworkService.TCP_KEEP_ALIVE,
+ NetworkService.TCP_REUSE_ADDRESS,
+ NetworkService.TCP_SEND_BUFFER_SIZE,
+ NetworkService.TCP_RECEIVE_BUFFER_SIZE,
+ NetworkService.TCP_CONNECT_TIMEOUT,
IndexSettings.QUERY_STRING_ANALYZE_WILDCARD,
IndexSettings.QUERY_STRING_ALLOW_LEADING_WILDCARD,
ScriptService.SCRIPT_CACHE_SIZE_SETTING,
diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java
index 93f37cddf0..b9e6668666 100644
--- a/core/src/main/java/org/elasticsearch/node/Node.java
+++ b/core/src/main/java/org/elasticsearch/node/Node.java
@@ -52,7 +52,6 @@ import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.routing.RoutingService;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.StopWatch;
-import org.elasticsearch.common.SuppressForbidden;
import org.elasticsearch.common.component.Lifecycle;
import org.elasticsearch.common.component.LifecycleComponent;
import org.elasticsearch.common.inject.Binder;
@@ -61,7 +60,6 @@ import org.elasticsearch.common.inject.Key;
import org.elasticsearch.common.inject.Module;
import org.elasticsearch.common.inject.ModulesBuilder;
import org.elasticsearch.common.inject.util.Providers;
-import org.elasticsearch.common.io.PathUtils;
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
import org.elasticsearch.common.lease.Releasables;
import org.elasticsearch.common.logging.DeprecationLogger;
@@ -151,9 +149,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
-import java.util.Locale;
import java.util.Map;
-import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
@@ -330,7 +326,7 @@ public class Node implements Closeable {
final SettingsModule settingsModule = new SettingsModule(this.settings, additionalSettings, additionalSettingsFilter);
scriptModule.registerClusterSettingsListeners(settingsModule.getClusterSettings());
resourcesToClose.add(resourceWatcherService);
- final NetworkService networkService = new NetworkService(settings,
+ final NetworkService networkService = new NetworkService(
getCustomNameResolvers(pluginsService.filterPlugins(DiscoveryPlugin.class)));
final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool);
clusterService.addListener(scriptModule.getScriptService());
diff --git a/core/src/main/java/org/elasticsearch/transport/TcpTransport.java b/core/src/main/java/org/elasticsearch/transport/TcpTransport.java
index 9631fc977c..f03b949c58 100644
--- a/core/src/main/java/org/elasticsearch/transport/TcpTransport.java
+++ b/core/src/main/java/org/elasticsearch/transport/TcpTransport.java
@@ -24,7 +24,6 @@ import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.logging.log4j.util.Supplier;
import org.apache.lucene.util.IOUtils;
import org.elasticsearch.ElasticsearchException;
-import org.elasticsearch.ExceptionsHelper;
import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.NotifyOnceListener;
@@ -67,7 +66,6 @@ import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.common.util.concurrent.KeyedLock;
import org.elasticsearch.common.util.concurrent.ThreadContext;
-import org.elasticsearch.common.util.iterable.Iterables;
import org.elasticsearch.indices.breaker.CircuitBreakerService;
import org.elasticsearch.monitor.jvm.JvmInfo;
import org.elasticsearch.rest.RestStatus;
@@ -103,13 +101,17 @@ import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Consumer;
+import java.util.function.Function;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
+import static java.util.Collections.emptyList;
import static java.util.Collections.unmodifiableMap;
import static org.elasticsearch.common.settings.Setting.boolSetting;
+import static org.elasticsearch.common.settings.Setting.groupSetting;
import static org.elasticsearch.common.settings.Setting.intSetting;
+import static org.elasticsearch.common.settings.Setting.listSetting;
import static org.elasticsearch.common.settings.Setting.timeSetting;
import static org.elasticsearch.common.transport.NetworkExceptionHelper.isCloseConnectionException;
import static org.elasticsearch.common.transport.NetworkExceptionHelper.isConnectException;
@@ -120,6 +122,19 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
public static final String TRANSPORT_SERVER_WORKER_THREAD_NAME_PREFIX = "transport_server_worker";
public static final String TRANSPORT_CLIENT_BOSS_THREAD_NAME_PREFIX = "transport_client_boss";
+ public static final Setting<List<String>> HOST =
+ listSetting("transport.host", emptyList(), Function.identity(), Setting.Property.NodeScope);
+ public static final Setting<List<String>> BIND_HOST =
+ listSetting("transport.bind_host", HOST, Function.identity(), Setting.Property.NodeScope);
+ public static final Setting<List<String>> PUBLISH_HOST =
+ listSetting("transport.publish_host", HOST, Function.identity(), Setting.Property.NodeScope);
+ public static final Setting<String> PORT =
+ new Setting<>("transport.tcp.port", "9300-9400", Function.identity(), Setting.Property.NodeScope);
+ public static final Setting<Integer> PUBLISH_PORT =
+ intSetting("transport.publish_port", -1, -1, Setting.Property.NodeScope);
+ public static final String DEFAULT_PROFILE = "default";
+ public static final Setting<Settings> TRANSPORT_PROFILES_SETTING =
+ groupSetting("transport.profiles.", Setting.Property.Dynamic, Setting.Property.NodeScope);
// the scheduled internal ping interval setting, defaults to disabled (-1)
public static final Setting<TimeValue> PING_SCHEDULE =
timeSetting("transport.ping_schedule", TimeValue.timeValueSeconds(-1), Setting.Property.NodeScope);
@@ -134,20 +149,21 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
public static final Setting<Integer> CONNECTIONS_PER_NODE_PING =
intSetting("transport.connections_per_node.ping", 1, 1, Setting.Property.NodeScope);
public static final Setting<TimeValue> TCP_CONNECT_TIMEOUT =
- timeSetting("transport.tcp.connect_timeout", NetworkService.TcpSettings.TCP_CONNECT_TIMEOUT, Setting.Property.NodeScope);
+ timeSetting("transport.tcp.connect_timeout", NetworkService.TCP_CONNECT_TIMEOUT, Setting.Property.NodeScope);
public static final Setting<Boolean> TCP_NO_DELAY =
- boolSetting("transport.tcp_no_delay", NetworkService.TcpSettings.TCP_NO_DELAY, Setting.Property.NodeScope);
+ boolSetting("transport.tcp_no_delay", NetworkService.TCP_NO_DELAY, Setting.Property.NodeScope);
public static final Setting<Boolean> TCP_KEEP_ALIVE =
- boolSetting("transport.tcp.keep_alive", NetworkService.TcpSettings.TCP_KEEP_ALIVE, Setting.Property.NodeScope);
+ boolSetting("transport.tcp.keep_alive", NetworkService.TCP_KEEP_ALIVE, Setting.Property.NodeScope);
public static final Setting<Boolean> TCP_REUSE_ADDRESS =
- boolSetting("transport.tcp.reuse_address", NetworkService.TcpSettings.TCP_REUSE_ADDRESS, Setting.Property.NodeScope);
+ boolSetting("transport.tcp.reuse_address", NetworkService.TCP_REUSE_ADDRESS, Setting.Property.NodeScope);
public static final Setting<ByteSizeValue> TCP_SEND_BUFFER_SIZE =
- Setting.byteSizeSetting("transport.tcp.send_buffer_size", NetworkService.TcpSettings.TCP_SEND_BUFFER_SIZE,
+ Setting.byteSizeSetting("transport.tcp.send_buffer_size", NetworkService.TCP_SEND_BUFFER_SIZE,
Setting.Property.NodeScope);
public static final Setting<ByteSizeValue> TCP_RECEIVE_BUFFER_SIZE =
- Setting.byteSizeSetting("transport.tcp.receive_buffer_size", NetworkService.TcpSettings.TCP_RECEIVE_BUFFER_SIZE,
+ Setting.byteSizeSetting("transport.tcp.receive_buffer_size", NetworkService.TCP_RECEIVE_BUFFER_SIZE,
Setting.Property.NodeScope);
+
private static final long NINETY_PER_HEAP_SIZE = (long) (JvmInfo.jvmInfo().getMem().getHeapMax().getBytes() * 0.9);
private static final int PING_DATA_SIZE = -1;
private final CircuitBreakerService circuitBreakerService;
@@ -650,12 +666,12 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
protected Map<String, Settings> buildProfileSettings() {
// extract default profile first and create standard bootstrap
- Map<String, Settings> profiles = TransportSettings.TRANSPORT_PROFILES_SETTING.get(settings).getAsGroups(true);
- if (!profiles.containsKey(TransportSettings.DEFAULT_PROFILE)) {
+ Map<String, Settings> profiles = TRANSPORT_PROFILES_SETTING.get(settings).getAsGroups(true);
+ if (!profiles.containsKey(DEFAULT_PROFILE)) {
profiles = new HashMap<>(profiles);
- profiles.put(TransportSettings.DEFAULT_PROFILE, Settings.EMPTY);
+ profiles.put(DEFAULT_PROFILE, Settings.EMPTY);
}
- Settings defaultSettings = profiles.get(TransportSettings.DEFAULT_PROFILE);
+ Settings defaultSettings = profiles.get(DEFAULT_PROFILE);
Map<String, Settings> result = new HashMap<>();
// loop through all profiles and start them up, special handling for default one
for (Map.Entry<String, Settings> entry : profiles.entrySet()) {
@@ -666,10 +682,10 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
logger.info("transport profile configured without a name. skipping profile with settings [{}]",
profileSettings.toDelimitedString(','));
continue;
- } else if (TransportSettings.DEFAULT_PROFILE.equals(name)) {
+ } else if (DEFAULT_PROFILE.equals(name)) {
profileSettings = Settings.builder()
.put(profileSettings)
- .put("port", profileSettings.get("port", TransportSettings.PORT.get(this.settings)))
+ .put("port", profileSettings.get("port", PORT.get(this.settings)))
.build();
} else if (profileSettings.get("port") == null) {
// if profile does not have a port, skip it
@@ -696,10 +712,11 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
return local;
}
- protected void bindServer(final String name, final Settings settings) {
+ protected void bindServer(final String name, final Settings profileSettings) {
// Bind and start to accept incoming connections.
InetAddress hostAddresses[];
- String bindHosts[] = settings.getAsArray("bind_host", null);
+ String bindHosts[] = profileSettings.getAsArray("bind_host",
+ NetworkService.GLOBAL_NETWORK_BINDHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY));
try {
hostAddresses = networkService.resolveBindHostAddresses(bindHosts);
} catch (IOException e) {
@@ -717,12 +734,12 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
List<InetSocketAddress> boundAddresses = new ArrayList<>();
for (InetAddress hostAddress : hostAddresses) {
- boundAddresses.add(bindToPort(name, hostAddress, settings.get("port")));
+ boundAddresses.add(bindToPort(name, hostAddress, profileSettings.get("port")));
}
- final BoundTransportAddress boundTransportAddress = createBoundTransportAddress(name, settings, boundAddresses);
+ final BoundTransportAddress boundTransportAddress = createBoundTransportAddress(name, profileSettings, boundAddresses);
- if (TransportSettings.DEFAULT_PROFILE.equals(name)) {
+ if (DEFAULT_PROFILE.equals(name)) {
this.boundAddress = boundTransportAddress;
} else {
profileBoundAddresses.put(name, boundTransportAddress);
@@ -772,12 +789,15 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
transportBoundAddresses[i] = new TransportAddress(boundAddress);
}
- final String[] publishHosts;
- if (TransportSettings.DEFAULT_PROFILE.equals(name)) {
- publishHosts = TransportSettings.PUBLISH_HOST.get(settings).toArray(Strings.EMPTY_ARRAY);
+ String[] publishHosts;
+ if (DEFAULT_PROFILE.equals(name)) {
+ publishHosts = PUBLISH_HOST.get(settings).toArray(Strings.EMPTY_ARRAY);
} else {
publishHosts = profileSettings.getAsArray("publish_host", boundAddressesHostStrings);
}
+ if (publishHosts == null || publishHosts.length == 0) {
+ publishHosts = NetworkService.GLOBAL_NETWORK_PUBLISHHOST_SETTING.get(settings).toArray(Strings.EMPTY_ARRAY);
+ }
final InetAddress publishInetAddress;
try {
@@ -795,8 +815,8 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
public static int resolvePublishPort(String profileName, Settings settings, Settings profileSettings,
List<InetSocketAddress> boundAddresses, InetAddress publishInetAddress) {
int publishPort;
- if (TransportSettings.DEFAULT_PROFILE.equals(profileName)) {
- publishPort = TransportSettings.PUBLISH_PORT.get(settings);
+ if (DEFAULT_PROFILE.equals(profileName)) {
+ publishPort = PUBLISH_PORT.get(settings);
} else {
publishPort = profileSettings.getAsInt("publish_port", -1);
}
@@ -824,18 +844,18 @@ public abstract class TcpTransport<Channel> extends AbstractLifecycleComponent i
}
if (publishPort < 0) {
- String profileExplanation = TransportSettings.DEFAULT_PROFILE.equals(profileName) ? "" : " for profile " + profileName;
+ String profileExplanation = DEFAULT_PROFILE.equals(profileName) ? "" : " for profile " + profileName;
throw new BindTransportException("Failed to auto-resolve publish port" + profileExplanation + ", multiple bound addresses " +
boundAddresses + " with distinct ports and none of them matched the publish address (" + publishInetAddress + "). " +
- "Please specify a unique port by setting " + TransportSettings.PORT.getKey() + " or " +
- TransportSettings.PUBLISH_PORT.getKey());
+ "Please specify a unique port by setting " + PORT.getKey() + " or " +
+ PUBLISH_PORT.getKey());
}
return publishPort;
}
@Override
public TransportAddress[] addressesFromString(String address, int perAddressLimit) throws UnknownHostException {
- return parse(address, settings.get("transport.profiles.default.port", TransportSettings.PORT.get(settings)), perAddressLimit);
+ return parse(address, settings.get("transport.profiles.default.port", PORT.get(settings)), perAddressLimit);
}
// this code is a take on guava's HostAndPort, like a HostAndPortRange
diff --git a/core/src/main/java/org/elasticsearch/transport/TransportSettings.java b/core/src/main/java/org/elasticsearch/transport/TransportSettings.java
deleted file mode 100644
index 6965e4ed24..0000000000
--- a/core/src/main/java/org/elasticsearch/transport/TransportSettings.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to Elasticsearch under one or more contributor
- * license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright
- * ownership. Elasticsearch licenses this file to you under
- * the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.elasticsearch.transport;
-
-import org.elasticsearch.common.settings.Setting;
-import org.elasticsearch.common.settings.Setting.Property;
-import org.elasticsearch.common.settings.Settings;
-
-import java.util.List;
-import java.util.function.Function;
-
-import static java.util.Collections.emptyList;
-import static org.elasticsearch.common.settings.Setting.groupSetting;
-import static org.elasticsearch.common.settings.Setting.intSetting;
-import static org.elasticsearch.common.settings.Setting.listSetting;
-
-/**
- * a collection of settings related to transport components, which are also needed in org.elasticsearch.bootstrap.Security
- * This class should only contain static code which is *safe* to load before the security manager is enforced.
- */
-public final class TransportSettings {
-
- public static final Setting<List<String>> HOST =
- listSetting("transport.host", emptyList(), Function.identity(), Property.NodeScope);
- public static final Setting<List<String>> PUBLISH_HOST =
- listSetting("transport.publish_host", HOST, Function.identity(), Property.NodeScope);
- public static final Setting<List<String>> BIND_HOST =
- listSetting("transport.bind_host", HOST, Function.identity(), Property.NodeScope);
- public static final Setting<String> PORT =
- new Setting<>("transport.tcp.port", "9300-9400", Function.identity(), Property.NodeScope);
- public static final Setting<Integer> PUBLISH_PORT =
- intSetting("transport.publish_port", -1, -1, Property.NodeScope);
- public static final String DEFAULT_PROFILE = "default";
- public static final Setting<Settings> TRANSPORT_PROFILES_SETTING =
- groupSetting("transport.profiles.", Property.Dynamic, Property.NodeScope);
-
- private TransportSettings() {
-
- }
-}
diff --git a/core/src/main/java/org/elasticsearch/tribe/TribeService.java b/core/src/main/java/org/elasticsearch/tribe/TribeService.java
index 81ed347382..a85bda7593 100644
--- a/core/src/main/java/org/elasticsearch/tribe/TribeService.java
+++ b/core/src/main/java/org/elasticsearch/tribe/TribeService.java
@@ -65,7 +65,7 @@ import org.elasticsearch.env.Environment;
import org.elasticsearch.env.NodeEnvironment;
import org.elasticsearch.node.Node;
import org.elasticsearch.rest.RestStatus;
-import org.elasticsearch.transport.TransportSettings;
+import org.elasticsearch.transport.TcpTransport;
import java.io.IOException;
import java.nio.file.Path;
@@ -207,9 +207,9 @@ public class TribeService extends AbstractLifecycleComponent {
NetworkService.GLOBAL_NETWORK_HOST_SETTING,
NetworkService.GLOBAL_NETWORK_BINDHOST_SETTING,
NetworkService.GLOBAL_NETWORK_PUBLISHHOST_SETTING,
- TransportSettings.HOST,
- TransportSettings.BIND_HOST,
- TransportSettings.PUBLISH_HOST
+ TcpTransport.HOST,
+ TcpTransport.BIND_HOST,
+ TcpTransport.PUBLISH_HOST
);
private final String onConflict;
private final Set<String> droppedIndices = ConcurrentCollections.newConcurrentSet();