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 fdecfd0a005..4d692cc36c6 100644 --- a/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java +++ b/core/src/main/java/org/elasticsearch/client/transport/TransportClient.java @@ -64,6 +64,8 @@ import org.elasticsearch.threadpool.ThreadPool; import org.elasticsearch.transport.TcpTransport; import org.elasticsearch.transport.TransportService; +import static org.elasticsearch.common.network.NetworkService.registerCustomNameResolvers; + /** * The transport client allows to create a client that is not part of the cluster, but simply connects to one * or more nodes directly by adding their respective addresses using {@link #addTransportAddress(org.elasticsearch.common.transport.TransportAddress)}. @@ -106,7 +108,8 @@ public abstract class TransportClient extends AbstractClient { final List resourcesToClose = new ArrayList<>(); final ThreadPool threadPool = new ThreadPool(settings); resourcesToClose.add(() -> ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS)); - final NetworkService networkService = new NetworkService(settings); + final NetworkService networkService = new NetworkService(settings, + registerCustomNameResolvers(settings, pluginsService.filterPlugins(DiscoveryPlugin.class))); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); try { final List> additionalSettings = new ArrayList<>(); @@ -123,7 +126,7 @@ public abstract class TransportClient extends AbstractClient { for (Module pluginModule : pluginsService.createGuiceModules()) { modules.add(pluginModule); } - modules.add(new NetworkModule(networkService, settings, true, namedWriteableRegistry, pluginsService.filterPlugins(DiscoveryPlugin.class))); + modules.add(new NetworkModule(networkService, settings, true, namedWriteableRegistry)); modules.add(b -> b.bind(ThreadPool.class).toInstance(threadPool)); modules.add(new SearchModule(settings, namedWriteableRegistry, true, pluginsService.filterPlugins(SearchPlugin.class))); ActionModule actionModule = new ActionModule(false, true, settings, null, settingsModule.getClusterSettings(), diff --git a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java index 5ccbb86c95a..9d3a92a65b9 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkModule.java @@ -38,17 +38,12 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.ExtensionPoint; import org.elasticsearch.http.HttpServer; import org.elasticsearch.http.HttpServerTransport; -import org.elasticsearch.plugins.DiscoveryPlugin; import org.elasticsearch.tasks.RawTaskStatus; import org.elasticsearch.tasks.Task; import org.elasticsearch.transport.Transport; import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.local.LocalTransport; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CopyOnWriteArrayList; - /** * A module to handle registering and binding all network related classes. */ @@ -83,10 +78,9 @@ public class NetworkModule extends AbstractModule { * @param settings The settings for the node * @param transportClient True if only transport classes should be allowed to be registered, false otherwise. * @param namedWriteableRegistry registry for named writeables for use during streaming - * @param discoveryPlugins Discovery plugins */ public NetworkModule(NetworkService networkService, Settings settings, boolean transportClient, - NamedWriteableRegistry namedWriteableRegistry, List discoveryPlugins) { + NamedWriteableRegistry namedWriteableRegistry) { this.networkService = networkService; this.settings = settings; this.transportClient = transportClient; @@ -96,7 +90,6 @@ public class NetworkModule extends AbstractModule { registerTaskStatus(ReplicationTask.Status.NAME, ReplicationTask.Status::new); registerTaskStatus(RawTaskStatus.NAME, RawTaskStatus::new); registerBuiltinAllocationCommands(); - registerCustomNameResolvers(discoveryPlugins); } public boolean isTransportClient() { @@ -142,18 +135,6 @@ public class NetworkModule extends AbstractModule { namedWriteableRegistry.register(AllocationCommand.class, commandName.getPreferredName(), reader); } - /** - * Register custom name resolver a DiscoveryPlugin might provide - * @param discoveryPlugins Discovery plugins - */ - private void registerCustomNameResolvers(List discoveryPlugins) { - for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) { - NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings); - if (customNameResolver != null) { - this.networkService.addCustomNameResolver(customNameResolver); - } - } - } /** * The registry of allocation command parsers. */ 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 c245813560c..32d2a09a46b 100644 --- a/core/src/main/java/org/elasticsearch/common/network/NetworkService.java +++ b/core/src/main/java/org/elasticsearch/common/network/NetworkService.java @@ -26,6 +26,7 @@ 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; +import org.elasticsearch.plugins.DiscoveryPlugin; import java.io.IOException; import java.net.InetAddress; @@ -33,7 +34,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; -import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; import java.util.function.Function; @@ -90,15 +90,12 @@ public class NetworkService extends AbstractComponent { InetAddress[] resolveIfPossible(String value) throws IOException; } - private final List customNameResolvers = new CopyOnWriteArrayList<>();; + private final List customNameResolvers; - public NetworkService(Settings settings) { + public NetworkService(Settings settings, List customNameResolvers) { super(settings); IfConfig.logIfNecessary(); - } - - public void addCustomNameResolver(CustomNameResolver customNameResolver) { - this.customNameResolvers.add(customNameResolver); + this.customNameResolvers = customNameResolvers; } /** @@ -273,4 +270,19 @@ public class NetworkService extends AbstractComponent { } return InetAddress.getAllByName(host); } + + /** + * Register custom name resolver a DiscoveryPlugin might provide + * @param discoveryPlugins Discovery plugins + */ + public static List registerCustomNameResolvers(Settings settings, List discoveryPlugins) { + List customNameResolvers = new ArrayList<>(); + for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) { + NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings); + if (customNameResolver != null) { + customNameResolvers.add(customNameResolver); + } + } + return customNameResolvers; + } } diff --git a/core/src/main/java/org/elasticsearch/node/Node.java b/core/src/main/java/org/elasticsearch/node/Node.java index 785d8fa8379..40fca99b638 100644 --- a/core/src/main/java/org/elasticsearch/node/Node.java +++ b/core/src/main/java/org/elasticsearch/node/Node.java @@ -133,9 +133,10 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import java.util.function.Function; import java.util.stream.Collectors; +import static org.elasticsearch.common.network.NetworkService.registerCustomNameResolvers; + /** * A node represent a node within a cluster (cluster.name). The {@link #client()} can be used * in order to use a {@link Client} to perform actions/operations against the cluster. @@ -264,7 +265,8 @@ public class Node implements Closeable { throw new IllegalStateException("Failed to created node environment", ex); } resourcesToClose.add(resourceWatcherService); - final NetworkService networkService = new NetworkService(settings); + final NetworkService networkService = new NetworkService(settings, + registerCustomNameResolvers(settings, pluginsService.filterPlugins(DiscoveryPlugin.class))); final ClusterService clusterService = new ClusterService(settings, settingsModule.getClusterSettings(), threadPool); clusterService.add(scriptModule.getScriptService()); resourcesToClose.add(clusterService); @@ -281,8 +283,7 @@ public class Node implements Closeable { } final MonitorService monitorService = new MonitorService(settings, nodeEnvironment, threadPool); modules.add(new NodeModule(this, monitorService)); - modules.add(new NetworkModule(networkService, settings, false, namedWriteableRegistry, - pluginsService.filterPlugins(DiscoveryPlugin.class))); + modules.add(new NetworkModule(networkService, settings, false, namedWriteableRegistry)); modules.add(new DiscoveryModule(this.settings)); ClusterModule clusterModule = new ClusterModule(settings, clusterService); modules.add(clusterModule); diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java index 6f3bcc4012e..c2f9938861b 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteRequestTests.java @@ -75,8 +75,7 @@ public class ClusterRerouteRequestTests extends ESTestCase { public ClusterRerouteRequestTests() { namedWriteableRegistry = new NamedWriteableRegistry(); - allocationCommandRegistry = new NetworkModule(null, null, true, namedWriteableRegistry, Collections.emptyList()) - .getAllocationCommandRegistry(); + allocationCommandRegistry = new NetworkModule(null, null, true, namedWriteableRegistry).getAllocationCommandRegistry(); } private ClusterRerouteRequest randomRequest() { diff --git a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java index d279324a352..657fec558b8 100644 --- a/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java +++ b/core/src/test/java/org/elasticsearch/action/admin/cluster/reroute/ClusterRerouteTests.java @@ -65,7 +65,7 @@ public class ClusterRerouteTests extends ESAllocationTestCase { req.writeTo(out); BytesReference bytes = out.bytes(); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); - new NetworkModule(null, Settings.EMPTY, true, namedWriteableRegistry, Collections.emptyList()); + new NetworkModule(null, Settings.EMPTY, true, namedWriteableRegistry); StreamInput wrap = new NamedWriteableAwareStreamInput(bytes.streamInput(), namedWriteableRegistry); ClusterRerouteRequest deserializedReq = new ClusterRerouteRequest(); diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java index 7e8a7495bd7..9624e32dfce 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/AllocationCommandsTests.java @@ -437,7 +437,7 @@ public class AllocationCommandsTests extends ESAllocationTestCase { // Since the commands are named writeable we need to register them and wrap the input stream NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); - new NetworkModule(null, Settings.EMPTY, true, namedWriteableRegistry, Collections.emptyList()); + new NetworkModule(null, Settings.EMPTY, true, namedWriteableRegistry); in = new NamedWriteableAwareStreamInput(in, namedWriteableRegistry); // Now we can read them! @@ -483,8 +483,8 @@ public class AllocationCommandsTests extends ESAllocationTestCase { // move two tokens, parser expected to be "on" `commands` field parser.nextToken(); parser.nextToken(); - AllocationCommandRegistry registry = new NetworkModule(null, Settings.EMPTY, true, new NamedWriteableRegistry(), - Collections.emptyList()).getAllocationCommandRegistry(); + AllocationCommandRegistry registry = new NetworkModule(null, Settings.EMPTY, true, new NamedWriteableRegistry()) + .getAllocationCommandRegistry(); AllocationCommands sCommands = AllocationCommands.fromXContent(parser, ParseFieldMatcher.STRICT, registry); assertThat(sCommands.commands().size(), equalTo(5)); diff --git a/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java b/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java index b5531ab4f12..9abcaa0ce3e 100644 --- a/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java +++ b/core/src/test/java/org/elasticsearch/common/network/NetworkModuleTests.java @@ -113,14 +113,14 @@ public class NetworkModuleTests extends ModuleTestCase { .put(NetworkModule.HTTP_ENABLED.getKey(), false) .put(NetworkModule.TRANSPORT_TYPE_KEY, "local") .build(); - NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry(), - Collections.emptyList()); + NetworkModule module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false, + new NamedWriteableRegistry()); module.registerTransportService("custom", FakeTransportService.class); assertBinding(module, TransportService.class, FakeTransportService.class); assertFalse(module.isTransportClient()); // check it works with transport only as well - module = new NetworkModule(new NetworkService(settings), settings, true, new NamedWriteableRegistry(), Collections.emptyList()); + module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, true, new NamedWriteableRegistry()); module.registerTransportService("custom", FakeTransportService.class); assertBinding(module, TransportService.class, FakeTransportService.class); assertTrue(module.isTransportClient()); @@ -130,14 +130,14 @@ public class NetworkModuleTests extends ModuleTestCase { Settings settings = Settings.builder().put(NetworkModule.TRANSPORT_TYPE_KEY, "custom") .put(NetworkModule.HTTP_ENABLED.getKey(), false) .build(); - NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry(), - Collections.emptyList()); + NetworkModule module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false, + new NamedWriteableRegistry()); module.registerTransport("custom", FakeTransport.class); assertBinding(module, Transport.class, FakeTransport.class); assertFalse(module.isTransportClient()); // check it works with transport only as well - module = new NetworkModule(new NetworkService(settings), settings, true, new NamedWriteableRegistry(), Collections.emptyList()); + module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, true, new NamedWriteableRegistry()); module.registerTransport("custom", FakeTransport.class); assertBinding(module, Transport.class, FakeTransport.class); assertTrue(module.isTransportClient()); @@ -147,14 +147,14 @@ public class NetworkModuleTests extends ModuleTestCase { Settings settings = Settings.builder() .put(NetworkModule.HTTP_TYPE_SETTING.getKey(), "custom") .put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build(); - NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry(), - Collections.emptyList()); + NetworkModule module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false, + new NamedWriteableRegistry()); module.registerHttpTransport("custom", FakeHttpTransport.class); assertBinding(module, HttpServerTransport.class, FakeHttpTransport.class); assertFalse(module.isTransportClient()); // check registration not allowed for transport only - module = new NetworkModule(new NetworkService(settings), settings, true, new NamedWriteableRegistry(), Collections.emptyList()); + module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, true, new NamedWriteableRegistry()); assertTrue(module.isTransportClient()); try { module.registerHttpTransport("custom", FakeHttpTransport.class); @@ -167,7 +167,7 @@ public class NetworkModuleTests extends ModuleTestCase { // not added if http is disabled settings = Settings.builder().put(NetworkModule.HTTP_ENABLED.getKey(), false) .put(NetworkModule.TRANSPORT_TYPE_KEY, "local").build(); - module = new NetworkModule(new NetworkService(settings), settings, false, new NamedWriteableRegistry(), Collections.emptyList()); + module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false, new NamedWriteableRegistry()); assertNotBound(module, HttpServerTransport.class); assertFalse(module.isTransportClient()); } @@ -175,7 +175,7 @@ public class NetworkModuleTests extends ModuleTestCase { public void testRegisterTaskStatus() { NamedWriteableRegistry registry = new NamedWriteableRegistry(); Settings settings = Settings.EMPTY; - NetworkModule module = new NetworkModule(new NetworkService(settings), settings, false, registry, Collections.emptyList()); + NetworkModule module = new NetworkModule(new NetworkService(settings, Collections.emptyList()), settings, false, registry); assertFalse(module.isTransportClient()); // Builtin reader comes back diff --git a/core/src/test/java/org/elasticsearch/common/network/NetworkServiceTests.java b/core/src/test/java/org/elasticsearch/common/network/NetworkServiceTests.java index 7ec4756d784..096d3b0a9a9 100644 --- a/core/src/test/java/org/elasticsearch/common/network/NetworkServiceTests.java +++ b/core/src/test/java/org/elasticsearch/common/network/NetworkServiceTests.java @@ -23,6 +23,7 @@ import org.elasticsearch.common.settings.Settings; import org.elasticsearch.test.ESTestCase; import java.net.InetAddress; +import java.util.Collections; import static org.hamcrest.Matchers.is; @@ -36,7 +37,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure exception if we bind to multicast ipv4 address */ public void testBindMulticastV4() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); try { service.resolveBindHostAddresses(new String[] { "239.1.1.1" }); fail("should have hit exception"); @@ -48,7 +49,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure exception if we bind to multicast ipv6 address */ public void testBindMulticastV6() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); try { service.resolveBindHostAddresses(new String[] { "FF08::108" }); fail("should have hit exception"); @@ -61,7 +62,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure exception if we publish to multicast ipv4 address */ public void testPublishMulticastV4() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); try { service.resolvePublishHostAddresses(new String[] { "239.1.1.1" }); fail("should have hit exception"); @@ -74,7 +75,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure exception if we publish to multicast ipv6 address */ public void testPublishMulticastV6() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); try { service.resolvePublishHostAddresses(new String[] { "FF08::108" }); fail("should have hit exception"); @@ -87,7 +88,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure specifying wildcard ipv4 address will bind to all interfaces */ public void testBindAnyLocalV4() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); assertEquals(InetAddress.getByName("0.0.0.0"), service.resolveBindHostAddresses(new String[] { "0.0.0.0" })[0]); } @@ -95,7 +96,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure specifying wildcard ipv6 address will bind to all interfaces */ public void testBindAnyLocalV6() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); assertEquals(InetAddress.getByName("::"), service.resolveBindHostAddresses(new String[] { "::" })[0]); } @@ -103,7 +104,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure specifying wildcard ipv4 address selects reasonable publish address */ public void testPublishAnyLocalV4() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); InetAddress address = service.resolvePublishHostAddresses(new String[] { "0.0.0.0" }); assertFalse(address.isAnyLocalAddress()); } @@ -112,7 +113,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure specifying wildcard ipv6 address selects reasonable publish address */ public void testPublishAnyLocalV6() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); InetAddress address = service.resolvePublishHostAddresses(new String[] { "::" }); assertFalse(address.isAnyLocalAddress()); } @@ -121,7 +122,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure we can bind to multiple addresses */ public void testBindMultipleAddresses() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); InetAddress[] addresses = service.resolveBindHostAddresses(new String[]{"127.0.0.1", "127.0.0.2"}); assertThat(addresses.length, is(2)); } @@ -130,7 +131,7 @@ public class NetworkServiceTests extends ESTestCase { * ensure we can't bind to multiple addresses when using wildcard */ public void testBindMultipleAddressesWithWildcard() throws Exception { - NetworkService service = new NetworkService(Settings.EMPTY); + NetworkService service = new NetworkService(Settings.EMPTY, Collections.emptyList()); try { service.resolveBindHostAddresses(new String[]{"0.0.0.0", "127.0.0.1"}); fail("should have hit exception"); diff --git a/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java b/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java index 6696174c08f..884ac1aa98f 100644 --- a/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/zen/ping/unicast/UnicastZenPingIT.java @@ -45,6 +45,7 @@ import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportSettings; import java.net.InetSocketAddress; +import java.util.Collections; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicInteger; @@ -66,7 +67,7 @@ public class UnicastZenPingIT extends ESTestCase { .put(TransportSettings.PORT.getKey(), startPort + "-" + endPort).build(); ThreadPool threadPool = new TestThreadPool(getClass().getName()); - NetworkService networkService = new NetworkService(settings); + NetworkService networkService = new NetworkService(settings, Collections.emptyList()); ElectMasterService electMasterService = new ElectMasterService(settings); NetworkHandle handleA = startServices(settings, threadPool, networkService, "UZP_A", Version.CURRENT); diff --git a/core/src/test/java/org/elasticsearch/transport/TransportServiceHandshakeTests.java b/core/src/test/java/org/elasticsearch/transport/TransportServiceHandshakeTests.java index 39ab7949a65..a9bf3f0f01d 100644 --- a/core/src/test/java/org/elasticsearch/transport/TransportServiceHandshakeTests.java +++ b/core/src/test/java/org/elasticsearch/transport/TransportServiceHandshakeTests.java @@ -36,6 +36,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.concurrent.TimeUnit; @@ -63,7 +64,7 @@ public class TransportServiceHandshakeTests extends ESTestCase { BigArrays.NON_RECYCLING_INSTANCE, new NoneCircuitBreakerService(), new NamedWriteableRegistry(), - new NetworkService(settings)); + new NetworkService(settings, Collections.emptyList())); TransportService transportService = new MockTransportService(settings, transport, threadPool); transportService.start(); transportService.acceptIncomingRequests(); diff --git a/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpChannelTests.java b/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpChannelTests.java index 41ea8612fed..ccb8aedd94c 100644 --- a/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpChannelTests.java +++ b/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpChannelTests.java @@ -50,6 +50,7 @@ import org.junit.Before; import java.net.SocketAddress; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import static org.elasticsearch.http.HttpTransportSettings.SETTING_CORS_ALLOW_CREDENTIALS; @@ -70,7 +71,7 @@ public class Netty3HttpChannelTests extends ESTestCase { @Before public void setup() throws Exception { - networkService = new NetworkService(Settings.EMPTY); + networkService = new NetworkService(Settings.EMPTY, Collections.emptyList()); threadPool = new TestThreadPool("test"); bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); } diff --git a/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpServerPipeliningTests.java b/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpServerPipeliningTests.java index ebaff71e0c2..b432708de15 100644 --- a/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpServerPipeliningTests.java +++ b/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpServerPipeliningTests.java @@ -49,6 +49,7 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -72,7 +73,7 @@ public class Netty3HttpServerPipeliningTests extends ESTestCase { @Before public void setup() throws Exception { - networkService = new NetworkService(Settings.EMPTY); + networkService = new NetworkService(Settings.EMPTY, Collections.emptyList()); threadPool = new TestThreadPool("test"); bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); } diff --git a/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpServerTransportTests.java b/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpServerTransportTests.java index da7e320a557..d24b23ad74a 100644 --- a/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpServerTransportTests.java +++ b/modules/transport-netty3/src/test/java/org/elasticsearch/http/netty3/Netty3HttpServerTransportTests.java @@ -33,6 +33,7 @@ import org.junit.After; import org.junit.Before; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.Set; import java.util.stream.Collectors; @@ -54,7 +55,7 @@ public class Netty3HttpServerTransportTests extends ESTestCase { @Before public void setup() throws Exception { - networkService = new NetworkService(Settings.EMPTY); + networkService = new NetworkService(Settings.EMPTY, Collections.emptyList()); threadPool = new TestThreadPool("test"); bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); } diff --git a/modules/transport-netty3/src/test/java/org/elasticsearch/transport/Netty3SizeHeaderFrameDecoderTests.java b/modules/transport-netty3/src/test/java/org/elasticsearch/transport/Netty3SizeHeaderFrameDecoderTests.java index e4047798071..46e65d9d1fe 100644 --- a/modules/transport-netty3/src/test/java/org/elasticsearch/transport/Netty3SizeHeaderFrameDecoderTests.java +++ b/modules/transport-netty3/src/test/java/org/elasticsearch/transport/Netty3SizeHeaderFrameDecoderTests.java @@ -38,6 +38,7 @@ import java.io.InputStreamReader; import java.net.InetAddress; import java.net.Socket; import java.nio.charset.StandardCharsets; +import java.util.Collections; import static org.hamcrest.Matchers.is; @@ -61,7 +62,7 @@ public class Netty3SizeHeaderFrameDecoderTests extends ESTestCase { @Before public void startThreadPool() { threadPool = new ThreadPool(settings); - NetworkService networkService = new NetworkService(settings); + NetworkService networkService = new NetworkService(settings, Collections.emptyList()); BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); nettyTransport = new Netty3Transport(settings, threadPool, networkService, bigArrays, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); diff --git a/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/Netty3ScheduledPingTests.java b/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/Netty3ScheduledPingTests.java index 16694dbed0b..3b02caf3b99 100644 --- a/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/Netty3ScheduledPingTests.java +++ b/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/Netty3ScheduledPingTests.java @@ -43,6 +43,7 @@ import org.elasticsearch.transport.TransportResponseOptions; import org.elasticsearch.transport.TransportSettings; import java.io.IOException; +import java.util.Collections; import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; @@ -62,14 +63,14 @@ public class Netty3ScheduledPingTests extends ESTestCase { CircuitBreakerService circuitBreakerService = new NoneCircuitBreakerService(); NamedWriteableRegistry registryA = new NamedWriteableRegistry(); - final Netty3Transport nettyA = new Netty3Transport(settings, threadPool, new NetworkService(settings), + final Netty3Transport nettyA = new Netty3Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()), BigArrays.NON_RECYCLING_INSTANCE, registryA, circuitBreakerService); MockTransportService serviceA = new MockTransportService(settings, nettyA, threadPool); serviceA.start(); serviceA.acceptIncomingRequests(); NamedWriteableRegistry registryB = new NamedWriteableRegistry(); - final Netty3Transport nettyB = new Netty3Transport(settings, threadPool, new NetworkService(settings), + final Netty3Transport nettyB = new Netty3Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()), BigArrays.NON_RECYCLING_INSTANCE, registryB, circuitBreakerService); MockTransportService serviceB = new MockTransportService(settings, nettyB, threadPool); diff --git a/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/Netty3TransportMultiPortTests.java b/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/Netty3TransportMultiPortTests.java index f21edf3f596..c460f630d5e 100644 --- a/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/Netty3TransportMultiPortTests.java +++ b/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/Netty3TransportMultiPortTests.java @@ -34,6 +34,8 @@ import org.elasticsearch.transport.TransportService; import org.elasticsearch.transport.TransportSettings; import org.junit.Before; +import java.util.Collections; + import static org.hamcrest.Matchers.is; public class Netty3TransportMultiPortTests extends ESTestCase { @@ -135,8 +137,8 @@ public class Netty3TransportMultiPortTests extends ESTestCase { private TcpTransport startTransport(Settings settings, ThreadPool threadPool) { BigArrays bigArrays = new MockBigArrays(Settings.EMPTY, new NoneCircuitBreakerService()); - TcpTransport transport = new Netty3Transport(settings, threadPool, new NetworkService(settings), bigArrays, - new NamedWriteableRegistry(), new NoneCircuitBreakerService()); + TcpTransport transport = new Netty3Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()), + bigArrays, new NamedWriteableRegistry(), new NoneCircuitBreakerService()); transport.start(); assertThat(transport.lifecycleState(), is(Lifecycle.State.STARTED)); diff --git a/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/SimpleNetty3TransportTests.java b/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/SimpleNetty3TransportTests.java index db400f4df43..60994273fb4 100644 --- a/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/SimpleNetty3TransportTests.java +++ b/modules/transport-netty3/src/test/java/org/elasticsearch/transport/netty3/SimpleNetty3TransportTests.java @@ -36,6 +36,7 @@ import org.elasticsearch.transport.TransportSettings; import java.net.InetAddress; import java.net.UnknownHostException; +import java.util.Collections; import static java.util.Collections.emptyMap; import static java.util.Collections.emptySet; @@ -47,8 +48,8 @@ public class SimpleNetty3TransportTests extends AbstractSimpleTransportTestCase Settings settings, ThreadPool threadPool, final Version version) { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); - Transport transport = new Netty3Transport(settings, threadPool, new NetworkService(settings), BigArrays.NON_RECYCLING_INSTANCE, - namedWriteableRegistry, new NoneCircuitBreakerService()) { + Transport transport = new Netty3Transport(settings, threadPool, new NetworkService(settings, Collections.emptyList()), + BigArrays.NON_RECYCLING_INSTANCE, namedWriteableRegistry, new NoneCircuitBreakerService()) { @Override protected Version getCurrentVersion() { return version; diff --git a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2NetworkTests.java b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2NetworkTests.java index b69ebd369a4..11ba53ca59e 100644 --- a/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2NetworkTests.java +++ b/plugins/discovery-ec2/src/test/java/org/elasticsearch/discovery/ec2/Ec2NetworkTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.test.ESTestCase; import java.io.IOException; import java.net.InetAddress; +import java.util.Collections; import static org.hamcrest.Matchers.arrayContaining; import static org.hamcrest.Matchers.containsString; @@ -42,8 +43,7 @@ public class Ec2NetworkTests extends ESTestCase { .put("network.host", "_ec2_") .build(); - NetworkService networkService = new NetworkService(nodeSettings); - networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings)); + NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings))); // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. try { networkService.resolveBindHostAddresses(null); @@ -60,8 +60,7 @@ public class Ec2NetworkTests extends ESTestCase { .put("network.host", "_ec2:publicIp_") .build(); - NetworkService networkService = new NetworkService(nodeSettings); - networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings)); + NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings))); // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. try { networkService.resolveBindHostAddresses(null); @@ -78,8 +77,7 @@ public class Ec2NetworkTests extends ESTestCase { .put("network.host", "_ec2:privateIp_") .build(); - NetworkService networkService = new NetworkService(nodeSettings); - networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings)); + NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings))); // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. try { networkService.resolveBindHostAddresses(null); @@ -96,8 +94,7 @@ public class Ec2NetworkTests extends ESTestCase { .put("network.host", "_ec2:privateIpv4_") .build(); - NetworkService networkService = new NetworkService(nodeSettings); - networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings)); + NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings))); // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. try { networkService.resolveBindHostAddresses(null); @@ -114,8 +111,7 @@ public class Ec2NetworkTests extends ESTestCase { .put("network.host", "_ec2:privateDns_") .build(); - NetworkService networkService = new NetworkService(nodeSettings); - networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings)); + NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings))); // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. try { networkService.resolveBindHostAddresses(null); @@ -132,8 +128,7 @@ public class Ec2NetworkTests extends ESTestCase { .put("network.host", "_ec2:publicIpv4_") .build(); - NetworkService networkService = new NetworkService(nodeSettings); - networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings)); + NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings))); // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. try { networkService.resolveBindHostAddresses(null); @@ -150,8 +145,7 @@ public class Ec2NetworkTests extends ESTestCase { .put("network.host", "_ec2:publicDns_") .build(); - NetworkService networkService = new NetworkService(nodeSettings); - networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings)); + NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings))); // TODO we need to replace that with a mock. For now we check the URL we are supposed to reach. try { networkService.resolveBindHostAddresses(null); @@ -169,8 +163,7 @@ public class Ec2NetworkTests extends ESTestCase { .put("network.host", "_local_") .build(); - NetworkService networkService = new NetworkService(nodeSettings); - networkService.addCustomNameResolver(new Ec2NameResolver(nodeSettings)); + NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new Ec2NameResolver(nodeSettings))); InetAddress[] addresses = networkService.resolveBindHostAddresses(null); assertThat(addresses, arrayContaining(networkService.resolveBindHostAddresses(new String[] { "_local_" }))); } diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java index efee5852bbc..3cc99cb8c23 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceDiscoveryTests.java @@ -34,6 +34,7 @@ import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; +import java.util.Collections; import java.util.List; import java.util.Locale; @@ -106,7 +107,7 @@ public class GceDiscoveryTests extends ESTestCase { protected List buildDynamicNodes(GceInstancesService gceInstancesService, Settings nodeSettings) { GceUnicastHostsProvider provider = new GceUnicastHostsProvider(nodeSettings, gceInstancesService, - transportService, new NetworkService(Settings.EMPTY)); + transportService, new NetworkService(Settings.EMPTY, Collections.emptyList())); List discoveryNodes = provider.buildDynamicNodes(); logger.info("--> nodes found: {}", discoveryNodes); diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceMockUtils.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceMockUtils.java index 86fa7f1cd6b..88a6fbd9e92 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceMockUtils.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceMockUtils.java @@ -37,7 +37,7 @@ import java.io.InputStream; import java.net.URL; public class GceMockUtils { - protected final static ESLogger logger = Loggers.getLogger(GceMockUtils.class); + protected static final ESLogger logger = Loggers.getLogger(GceMockUtils.class); public static final String GCE_METADATA_URL = "http://metadata.google.internal/computeMetadata/v1/instance"; diff --git a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceNetworkTests.java b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceNetworkTests.java index 6a2985f7d32..5b7b5e2e4d1 100644 --- a/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceNetworkTests.java +++ b/plugins/discovery-gce/src/test/java/org/elasticsearch/discovery/gce/GceNetworkTests.java @@ -81,7 +81,8 @@ public class GceNetworkTests extends ESTestCase { * network.host: _local_ */ public void networkHostCoreLocal() throws IOException { - resolveGce("_local_", new NetworkService(Settings.EMPTY).resolveBindHostAddresses(new String[] { NetworkService.DEFAULT_NETWORK_HOST })); + resolveGce("_local_", new NetworkService(Settings.EMPTY, Collections.emptyList()) + .resolveBindHostAddresses(new String[] { NetworkService.DEFAULT_NETWORK_HOST })); } /** @@ -105,9 +106,8 @@ public class GceNetworkTests extends ESTestCase { .put("network.host", gceNetworkSetting) .build(); - NetworkService networkService = new NetworkService(nodeSettings); GceMetadataServiceMock mock = new GceMetadataServiceMock(nodeSettings); - networkService.addCustomNameResolver(new GceNameResolver(nodeSettings, mock)); + NetworkService networkService = new NetworkService(nodeSettings, Collections.singletonList(new GceNameResolver(nodeSettings, mock))); try { InetAddress[] addresses = networkService.resolveBindHostAddresses(null); if (expected == null) { diff --git a/test/framework/src/test/java/org/elasticsearch/transport/MockTcpTransportTests.java b/test/framework/src/test/java/org/elasticsearch/transport/MockTcpTransportTests.java index f94bd11b00c..6cec62cb710 100644 --- a/test/framework/src/test/java/org/elasticsearch/transport/MockTcpTransportTests.java +++ b/test/framework/src/test/java/org/elasticsearch/transport/MockTcpTransportTests.java @@ -26,12 +26,14 @@ import org.elasticsearch.common.util.BigArrays; import org.elasticsearch.indices.breaker.NoneCircuitBreakerService; import org.elasticsearch.test.transport.MockTransportService; +import java.util.Collections; + public class MockTcpTransportTests extends AbstractSimpleTransportTestCase { @Override protected MockTransportService build(Settings settings, Version version) { NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(); Transport transport = new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE, - new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(settings), version); + new NoneCircuitBreakerService(), namedWriteableRegistry, new NetworkService(settings, Collections.emptyList()), version); MockTransportService mockTransportService = new MockTransportService(Settings.EMPTY, transport, threadPool); mockTransportService.start(); return mockTransportService;