Move custom name resolvers to NetworkService CTOR
Instead of using NetworkModule we can directly inject them in NetworkService CTOR. See https://github.com/elastic/elasticsearch/pull/15765#issuecomment-235307974
This commit is contained in:
parent
5e57febe53
commit
fde15ae470
|
@ -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<Closeable> 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<Setting<?>> 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(),
|
||||
|
|
|
@ -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<DiscoveryPlugin> 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<DiscoveryPlugin> discoveryPlugins) {
|
||||
for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) {
|
||||
NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings);
|
||||
if (customNameResolver != null) {
|
||||
this.networkService.addCustomNameResolver(customNameResolver);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The registry of allocation command parsers.
|
||||
*/
|
||||
|
|
|
@ -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<CustomNameResolver> customNameResolvers = new CopyOnWriteArrayList<>();;
|
||||
private final List<CustomNameResolver> customNameResolvers;
|
||||
|
||||
public NetworkService(Settings settings) {
|
||||
public NetworkService(Settings settings, List<CustomNameResolver> 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<CustomNameResolver> registerCustomNameResolvers(Settings settings, List<DiscoveryPlugin> discoveryPlugins) {
|
||||
List<CustomNameResolver> customNameResolvers = new ArrayList<>();
|
||||
for (DiscoveryPlugin discoveryPlugin : discoveryPlugins) {
|
||||
NetworkService.CustomNameResolver customNameResolver = discoveryPlugin.getCustomNameResolver(settings);
|
||||
if (customNameResolver != null) {
|
||||
customNameResolvers.add(customNameResolver);
|
||||
}
|
||||
}
|
||||
return customNameResolvers;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 (<tt>cluster.name</tt>). 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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_" })));
|
||||
}
|
||||
|
|
|
@ -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<DiscoveryNode> buildDynamicNodes(GceInstancesService gceInstancesService, Settings nodeSettings) {
|
||||
GceUnicastHostsProvider provider = new GceUnicastHostsProvider(nodeSettings, gceInstancesService,
|
||||
transportService, new NetworkService(Settings.EMPTY));
|
||||
transportService, new NetworkService(Settings.EMPTY, Collections.emptyList()));
|
||||
|
||||
List<DiscoveryNode> discoveryNodes = provider.buildDynamicNodes();
|
||||
logger.info("--> nodes found: {}", discoveryNodes);
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue