make druid node bind address configurable (#6464)

* make druid node bind address configurable

* fix tests

* fix travis-ci
This commit is contained in:
QiuMM 2018-10-16 05:19:40 +08:00 committed by Gian Merlino
parent f537c0069a
commit 85a89e2703
40 changed files with 244 additions and 121 deletions

View File

@ -653,6 +653,7 @@ These coordinator static configurations can be defined in the `coordinator/runti
|Property|Description|Default|
|--------|-----------|-------|
|`druid.host`|The host for the current node. This is used to advertise the current processes location as reachable from another node and should generally be specified such that `http://${druid.host}/` could actually talk to this process|InetAddress.getLocalHost().getCanonicalHostName()|
|`druid.bindOnHost`|Indicating whether the node's internal jetty server bind on `druid.host`. Default is false, which means binding to all interfaces.|false|
|`druid.plaintextPort`|This is the port to actually listen on; unless port mapping is used, this will be the same port as is on `druid.host`|8081|
|`druid.tlsPort`|TLS port for HTTPS connector, if [druid.enableTlsPort](../operations/tls-support.html) is set then this config will be used. If `druid.host` contains port then that port will be ignored. This should be a non-negative Integer.|8281|
|`druid.service`|The name of the service. This is used as a dimension when emitting metrics and alerts to differentiate between the various services|druid/coordinator|
@ -816,6 +817,7 @@ These overlord static configurations can be defined in the `overlord/runtime.pro
|Property|Description|Default|
|--------|-----------|-------|
|`druid.host`|The host for the current node. This is used to advertise the current processes location as reachable from another node and should generally be specified such that `http://${druid.host}/` could actually talk to this process|InetAddress.getLocalHost().getCanonicalHostName()|
|`druid.bindOnHost`|Indicating whether the node's internal jetty server bind on `druid.host`. Default is false, which means binding to all interfaces.|false|
|`druid.plaintextPort`|This is the port to actually listen on; unless port mapping is used, this will be the same port as is on `druid.host`|8090|
|`druid.tlsPort`|TLS port for HTTPS connector, if [druid.enableTlsPort](../operations/tls-support.html) is set then this config will be used. If `druid.host` contains port then that port will be ignored. This should be a non-negative Integer.|8290|
|`druid.service`|The name of the service. This is used as a dimension when emitting metrics and alerts to differentiate between the various services|druid/overlord|
@ -1025,6 +1027,7 @@ These MiddleManager and Peon configurations can be defined in the `middleManager
|Property|Description|Default|
|--------|-----------|-------|
|`druid.host`|The host for the current node. This is used to advertise the current processes location as reachable from another node and should generally be specified such that `http://${druid.host}/` could actually talk to this process|InetAddress.getLocalHost().getCanonicalHostName()|
|`druid.bindOnHost`|Indicating whether the node's internal jetty server bind on `druid.host`. Default is false, which means binding to all interfaces.|false|
|`druid.plaintextPort`|This is the port to actually listen on; unless port mapping is used, this will be the same port as is on `druid.host`|8091|
|`druid.tlsPort`|TLS port for HTTPS connector, if [druid.enableTlsPort](../operations/tls-support.html) is set then this config will be used. If `druid.host` contains port then that port will be ignored. This should be a non-negative Integer.|8291|
|`druid.service`|The name of the service. This is used as a dimension when emitting metrics and alerts to differentiate between the various services|druid/middlemanager|
@ -1149,6 +1152,7 @@ These Broker configurations can be defined in the `broker/runtime.properties` fi
|Property|Description|Default|
|--------|-----------|-------|
|`druid.host`|The host for the current node. This is used to advertise the current processes location as reachable from another node and should generally be specified such that `http://${druid.host}/` could actually talk to this process|InetAddress.getLocalHost().getCanonicalHostName()|
|`druid.bindOnHost`|Indicating whether the node's internal jetty server bind on `druid.host`. Default is false, which means binding to all interfaces.|false|
|`druid.plaintextPort`|This is the port to actually listen on; unless port mapping is used, this will be the same port as is on `druid.host`|8082|
|`druid.tlsPort`|TLS port for HTTPS connector, if [druid.enableTlsPort](../operations/tls-support.html) is set then this config will be used. If `druid.host` contains port then that port will be ignored. This should be a non-negative Integer.|8282|
|`druid.service`|The name of the service. This is used as a dimension when emitting metrics and alerts to differentiate between the various services|druid/broker|
@ -1280,6 +1284,7 @@ These Historical configurations can be defined in the `historical/runtime.proper
|Property|Description|Default|
|--------|-----------|-------|
|`druid.host`|The host for the current node. This is used to advertise the current processes location as reachable from another node and should generally be specified such that `http://${druid.host}/` could actually talk to this process|InetAddress.getLocalHost().getCanonicalHostName()|
|`druid.bindOnHost`|Indicating whether the node's internal jetty server bind on `druid.host`. Default is false, which means binding to all interfaces.|false|
|`druid.plaintextPort`|This is the port to actually listen on; unless port mapping is used, this will be the same port as is on `druid.host`|8083|
|`druid.tlsPort`|TLS port for HTTPS connector, if [druid.enableTlsPort](../operations/tls-support.html) is set then this config will be used. If `druid.host` contains port then that port will be ignored. This should be a non-negative Integer.|8283|
|`druid.service`|The name of the service. This is used as a dimension when emitting metrics and alerts to differentiate between the various services|druid/historical|

View File

@ -524,7 +524,7 @@ public class NamespaceLookupExtractorFactoryTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false)
);
}
}

View File

@ -49,7 +49,7 @@ public class OffHeapNamespaceExtractionCacheManagerTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false)
);
}
}

View File

@ -49,7 +49,7 @@ public class OnHeapNamespaceExtractionCacheManagerTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false)
);
}
}

View File

@ -109,7 +109,7 @@ public class HadoopDruidIndexerConfig
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("hadoop-indexer", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("hadoop-indexer", null, false, null, null, true, false)
);
JsonConfigProvider.bind(binder, "druid.hadoop.security.kerberos", HadoopKerberosConfig.class);
}

View File

@ -64,7 +64,7 @@ public class HadoopDruidConverterConfig
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("hadoop-converter", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("hadoop-converter", null, false, null, null, true, false)
);
}
}

View File

@ -172,7 +172,7 @@ public class DatasourcePathSpecTest
JsonConfigProvider.bindInstance(
binder,
Key.get(DruidNode.class, Self.class),
new DruidNode("dummy-node", null, null, null, true, false)
new DruidNode("dummy-node", null, false, null, null, true, false)
);
}
}

View File

@ -68,7 +68,7 @@ public class SingleTaskBackgroundRunnerTest
public void setup() throws IOException
{
final TestUtils utils = new TestUtils();
final DruidNode node = new DruidNode("testServer", "testHost", 1000, null, true, false);
final DruidNode node = new DruidNode("testServer", "testHost", false, 1000, null, true, false);
final TaskConfig taskConfig = new TaskConfig(
temporaryFolder.newFile().toString(),
null,

View File

@ -638,7 +638,7 @@ public class TaskLifecycleTest
tb,
taskConfig,
emitter,
new DruidNode("dummy", "dummy", 10000, null, true, false),
new DruidNode("dummy", "dummy", false, 10000, null, true, false),
new ServerConfig()
);
}

View File

@ -129,7 +129,7 @@ public class HttpRemoteTaskRunnerTest
taskRunner.start();
DiscoveryDruidNode druidNode1 = new DiscoveryDruidNode(
new DruidNode("service", "host1", 8080, null, true, false),
new DruidNode("service", "host1", false, 8080, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip1", 2, "0")
@ -137,7 +137,7 @@ public class HttpRemoteTaskRunnerTest
);
DiscoveryDruidNode druidNode2 = new DiscoveryDruidNode(
new DruidNode("service", "host2", 8080, null, true, false),
new DruidNode("service", "host2", false, 8080, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip2", 2, "0")
@ -221,7 +221,7 @@ public class HttpRemoteTaskRunnerTest
taskRunner.start();
DiscoveryDruidNode druidNode1 = new DiscoveryDruidNode(
new DruidNode("service", "host1", 8080, null, true, false),
new DruidNode("service", "host1", false, 8080, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip1", 2, "0")
@ -229,7 +229,7 @@ public class HttpRemoteTaskRunnerTest
);
DiscoveryDruidNode druidNode2 = new DiscoveryDruidNode(
new DruidNode("service", "host2", 8080, null, true, false),
new DruidNode("service", "host2", false, 8080, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip2", 2, "0")
@ -324,7 +324,7 @@ public class HttpRemoteTaskRunnerTest
taskRunner.start();
DiscoveryDruidNode druidNode = new DiscoveryDruidNode(
new DruidNode("service", "host", 1234, null, true, false),
new DruidNode("service", "host", false, 1234, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip1", 2, "0")
@ -458,7 +458,7 @@ public class HttpRemoteTaskRunnerTest
Task task2 = NoopTask.create("task-id-2", 0);
DiscoveryDruidNode druidNode = new DiscoveryDruidNode(
new DruidNode("service", "host", 1234, null, true, false),
new DruidNode("service", "host", false, 1234, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip1", 2, "0")
@ -621,7 +621,7 @@ public class HttpRemoteTaskRunnerTest
Task task2 = NoopTask.create("task-id-2", 0);
DiscoveryDruidNode druidNode = new DiscoveryDruidNode(
new DruidNode("service", "host", 1234, null, true, false),
new DruidNode("service", "host", false, 1234, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip1", 2, "0")
@ -788,7 +788,7 @@ public class HttpRemoteTaskRunnerTest
AtomicInteger ticks = new AtomicInteger();
DiscoveryDruidNode druidNode1 = new DiscoveryDruidNode(
new DruidNode("service", "host1", 8080, null, true, false),
new DruidNode("service", "host1", false, 8080, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip1", 1, "0")
@ -832,7 +832,7 @@ public class HttpRemoteTaskRunnerTest
}
DiscoveryDruidNode druidNode2 = new DiscoveryDruidNode(
new DruidNode("service", "host2", 8080, null, true, false),
new DruidNode("service", "host2", false, 8080, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip2", 1, "0")
@ -865,7 +865,7 @@ public class HttpRemoteTaskRunnerTest
}
DiscoveryDruidNode druidNode3 = new DiscoveryDruidNode(
new DruidNode("service", "host3", 8080, null, true, false),
new DruidNode("service", "host3", false, 8080, null, true, false),
NodeType.MIDDLE_MANAGER,
ImmutableMap.of(
WorkerNodeService.DISCOVERY_SERVICE_KEY, new WorkerNodeService("ip2", 1, "0")

View File

@ -166,7 +166,7 @@ public class OverlordTest
setupServerAndCurator();
curator.start();
curator.blockUntilConnected();
druidNode = new DruidNode("hey", "what", 1234, null, true, false);
druidNode = new DruidNode("hey", "what", false, 1234, null, true, false);
ServiceEmitter serviceEmitter = new NoopServiceEmitter();
taskMaster = new TaskMaster(
new TaskQueueConfig(null, new Period(1), null, new Period(10)),

View File

@ -73,7 +73,7 @@ public class WorkerTaskMonitorTest
private static final String basePath = "/test/druid";
private static final String tasksPath = StringUtils.format("%s/indexer/tasks/worker", basePath);
private static final String statusPath = StringUtils.format("%s/indexer/status/worker", basePath);
private static final DruidNode DUMMY_NODE = new DruidNode("dummy", "dummy", 9000, null, true, false);
private static final DruidNode DUMMY_NODE = new DruidNode("dummy", "dummy", false, 9000, null, true, false);
private TestingCluster testingCluster;
private CuratorFramework cf;

View File

@ -57,7 +57,7 @@ public class DruidTestModule implements Module
// Bind DruidNode instance to make Guice happy. This instance is currently unused.
binder.bind(DruidNode.class).annotatedWith(Self.class).toInstance(
new DruidNode("integration-tests", "localhost", 9191, null, null, true, false)
new DruidNode("integration-tests", "localhost", false, 9191, null, null, true, false)
);
}

View File

@ -123,6 +123,6 @@ public class ServiceAnnouncingChatHandlerProvider implements ChatHandlerProvider
private DruidNode makeDruidNode(String key)
{
return new DruidNode(key, node.getHost(), node.getPlaintextPort(), node.getTlsPort(), node.isEnablePlaintextPort(), node.isEnableTlsPort());
return new DruidNode(key, node.getHost(), node.isBindOnHost(), node.getPlaintextPort(), node.getTlsPort(), node.isEnablePlaintextPort(), node.isEnableTlsPort());
}
}

View File

@ -47,6 +47,13 @@ public class DruidNode
@NotNull
private String host;
/**
* This property indicates whether the druid node's internal jetty server bind on {@link DruidNode#host}.
* Default is false, which means binding to all interfaces.
*/
@JsonProperty
private boolean bindOnHost = false;
/**
* This property is now deprecated, this is present just so that JsonConfigurator does not fail if this is set.
* Please use {@link DruidNode#plaintextPort} instead, which if set will be used and hence this has -1 as default value.
@ -73,13 +80,14 @@ public class DruidNode
public DruidNode(
String serviceName,
String host,
boolean bindOnHost,
Integer plaintextPort,
Integer tlsPort,
boolean enablePlaintextPort,
boolean enableTlsPort
)
{
this(serviceName, host, plaintextPort, null, tlsPort, enablePlaintextPort, enableTlsPort);
this(serviceName, host, bindOnHost, plaintextPort, null, tlsPort, enablePlaintextPort, enableTlsPort);
}
/**
@ -103,6 +111,7 @@ public class DruidNode
public DruidNode(
@JacksonInject @Named("serviceName") @JsonProperty("service") String serviceName,
@JsonProperty("host") String host,
@JsonProperty("bindOnHost") boolean bindOnHost,
@JsonProperty("plaintextPort") Integer plaintextPort,
@JacksonInject @Named("servicePort") @JsonProperty("port") Integer port,
@JacksonInject @Named("tlsServicePort") @JsonProperty("tlsPort") Integer tlsPort,
@ -113,6 +122,7 @@ public class DruidNode
init(
serviceName,
host,
bindOnHost,
plaintextPort != null ? plaintextPort : port,
tlsPort,
enablePlaintextPort == null ? true : enablePlaintextPort.booleanValue(),
@ -120,7 +130,7 @@ public class DruidNode
);
}
private void init(String serviceName, String host, Integer plainTextPort, Integer tlsPort, boolean enablePlaintextPort, boolean enableTlsPort)
private void init(String serviceName, String host, boolean bindOnHost, Integer plainTextPort, Integer tlsPort, boolean enablePlaintextPort, boolean enableTlsPort)
{
Preconditions.checkNotNull(serviceName);
@ -178,6 +188,7 @@ public class DruidNode
this.serviceName = serviceName;
this.host = host;
this.bindOnHost = bindOnHost;
}
public String getServiceName()
@ -190,6 +201,11 @@ public class DruidNode
return host;
}
public boolean isBindOnHost()
{
return bindOnHost;
}
public int getPlaintextPort()
{
return plaintextPort;
@ -212,7 +228,7 @@ public class DruidNode
public DruidNode withService(String service)
{
return new DruidNode(service, host, plaintextPort, tlsPort, enablePlaintextPort, enableTlsPort);
return new DruidNode(service, host, bindOnHost, plaintextPort, tlsPort, enablePlaintextPort, enableTlsPort);
}
public String getServiceScheme()
@ -278,6 +294,7 @@ public class DruidNode
}
DruidNode druidNode = (DruidNode) o;
return port == druidNode.port &&
bindOnHost == druidNode.bindOnHost &&
plaintextPort == druidNode.plaintextPort &&
enablePlaintextPort == druidNode.enablePlaintextPort &&
tlsPort == druidNode.tlsPort &&
@ -298,6 +315,7 @@ public class DruidNode
return "DruidNode{" +
"serviceName='" + serviceName + '\'' +
", host='" + host + '\'' +
", bindOnHost=" + bindOnHost +
", port=" + port +
", plaintextPort=" + plaintextPort +
", enablePlaintextPort=" + enablePlaintextPort +

View File

@ -223,6 +223,9 @@ public class JettyServerModule extends JerseyServletModule
HttpConfiguration httpConfiguration = new HttpConfiguration();
httpConfiguration.setRequestHeaderSize(config.getMaxRequestHeaderSize());
final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration));
if (node.isBindOnHost()) {
connector.setHost(node.getHost());
}
connector.setPort(node.getPlaintextPort());
serverConnectors.add(connector);
}
@ -304,6 +307,9 @@ public class JettyServerModule extends JerseyServletModule
new SslConnectionFactory(sslContextFactory, HTTP_1_1_STRING),
new HttpConnectionFactory(httpsConfiguration)
);
if (node.isBindOnHost()) {
connector.setHost(node.getHost());
}
connector.setPort(node.getTlsPort());
serverConnectors.add(connector);
} else {

View File

@ -167,7 +167,7 @@ public class HttpServerInventoryViewTest
);
DiscoveryDruidNode druidNode = new DiscoveryDruidNode(
new DruidNode("service", "host", 8080, null, true, false),
new DruidNode("service", "host", false, 8080, null, true, false),
NodeType.HISTORICAL,
ImmutableMap.of(
DataNodeService.DISCOVERY_SERVICE_KEY, new DataNodeService("tier", 1000, ServerType.HISTORICAL, 0)

View File

@ -43,7 +43,7 @@ public class CacheMonitorTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false)
);
}
}
@ -62,7 +62,7 @@ public class CacheMonitorTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false)
);
binder.bind(Cache.class).toInstance(MapCache.create(0));
}

View File

@ -59,7 +59,7 @@ public class CuratorDruidLeaderSelectorTest extends CuratorTestBase
CuratorDruidLeaderSelector leaderSelector1 = new CuratorDruidLeaderSelector(
curator,
new DruidNode("s1", "h1", 8080, null, true, false),
new DruidNode("s1", "h1", false, 8080, null, true, false),
latchPath
);
leaderSelector1.registerListener(
@ -91,7 +91,7 @@ public class CuratorDruidLeaderSelectorTest extends CuratorTestBase
CuratorDruidLeaderSelector leaderSelector2 = new CuratorDruidLeaderSelector(
curator,
new DruidNode("s2", "h2", 8080, null, true, false),
new DruidNode("s2", "h2", false, 8080, null, true, false),
latchPath
);
leaderSelector2.registerListener(
@ -131,7 +131,7 @@ public class CuratorDruidLeaderSelectorTest extends CuratorTestBase
CuratorDruidLeaderSelector leaderSelector3 = new CuratorDruidLeaderSelector(
curator,
new DruidNode("s3", "h3", 8080, null, true, false),
new DruidNode("s3", "h3", false, 8080, null, true, false),
latchPath
);
leaderSelector3.registerListener(

View File

@ -80,25 +80,25 @@ public class CuratorDruidNodeAnnouncerAndDiscoveryTest extends CuratorTestBase
);
DiscoveryDruidNode node1 = new DiscoveryDruidNode(
new DruidNode("s1", "h1", 8080, null, true, false),
new DruidNode("s1", "h1", false, 8080, null, true, false),
NodeType.COORDINATOR,
ImmutableMap.of()
);
DiscoveryDruidNode node2 = new DiscoveryDruidNode(
new DruidNode("s2", "h2", 8080, null, true, false),
new DruidNode("s2", "h2", false, 8080, null, true, false),
NodeType.COORDINATOR,
ImmutableMap.of()
);
DiscoveryDruidNode node3 = new DiscoveryDruidNode(
new DruidNode("s3", "h3", 8080, null, true, false),
new DruidNode("s3", "h3", false, 8080, null, true, false),
NodeType.OVERLORD,
ImmutableMap.of()
);
DiscoveryDruidNode node4 = new DiscoveryDruidNode(
new DruidNode("s4", "h4", 8080, null, true, false),
new DruidNode("s4", "h4", false, 8080, null, true, false),
NodeType.OVERLORD,
ImmutableMap.of()
);

View File

@ -79,7 +79,7 @@ public class DruidLeaderClientTest extends BaseJettyTest
@Override
protected Injector setupInjector()
{
final DruidNode node = new DruidNode("test", "localhost", null, null, true, false);
final DruidNode node = new DruidNode("test", "localhost", false, null, null, true, false);
discoveryDruidNode = new DiscoveryDruidNode(node, NodeType.PEON, ImmutableMap.of());
Injector injector = Initialization.makeInjectorWithModules(
@ -193,7 +193,7 @@ public class DruidLeaderClientTest extends BaseJettyTest
DruidNodeDiscovery druidNodeDiscovery = EasyMock.createMock(DruidNodeDiscovery.class);
DiscoveryDruidNode dummyNode = new DiscoveryDruidNode(
new DruidNode("test", "dummyhost", 64231, null, true, false),
new DruidNode("test", "dummyhost", false, 64231, null, true, false),
NodeType.PEON,
ImmutableMap.of()
);

View File

@ -86,7 +86,7 @@ public class DruidNodeDiscoveryProviderTest
Assert.assertTrue(lookupNodeDiscovery.getAllNodes().isEmpty());
DiscoveryDruidNode node1 = new DiscoveryDruidNode(
new DruidNode("s1", "h1", 8080, null, true, false),
new DruidNode("s1", "h1", false, 8080, null, true, false),
NodeType.HISTORICAL,
ImmutableMap.of(
DataNodeService.DISCOVERY_SERVICE_KEY, new DataNodeService("tier", 1000, ServerType.HISTORICAL, 0),
@ -94,21 +94,21 @@ public class DruidNodeDiscoveryProviderTest
);
DiscoveryDruidNode node2 = new DiscoveryDruidNode(
new DruidNode("s2", "h2", 8080, null, true, false),
new DruidNode("s2", "h2", false, 8080, null, true, false),
NodeType.HISTORICAL,
ImmutableMap.of(
DataNodeService.DISCOVERY_SERVICE_KEY, new DataNodeService("tier", 1000, ServerType.HISTORICAL, 0))
);
DiscoveryDruidNode node3 = new DiscoveryDruidNode(
new DruidNode("s3", "h3", 8080, null, true, false),
new DruidNode("s3", "h3", false, 8080, null, true, false),
NodeType.HISTORICAL,
ImmutableMap.of(
LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier"))
);
DiscoveryDruidNode node4 = new DiscoveryDruidNode(
new DruidNode("s4", "h4", 8080, null, true, false),
new DruidNode("s4", "h4", false, 8080, null, true, false),
NodeType.PEON,
ImmutableMap.of(
DataNodeService.DISCOVERY_SERVICE_KEY, new DataNodeService("tier", 1000, ServerType.HISTORICAL, 0),
@ -116,35 +116,35 @@ public class DruidNodeDiscoveryProviderTest
);
DiscoveryDruidNode node5 = new DiscoveryDruidNode(
new DruidNode("s5", "h5", 8080, null, true, false),
new DruidNode("s5", "h5", false, 8080, null, true, false),
NodeType.PEON,
ImmutableMap.of(
DataNodeService.DISCOVERY_SERVICE_KEY, new DataNodeService("tier", 1000, ServerType.HISTORICAL, 0))
);
DiscoveryDruidNode node6 = new DiscoveryDruidNode(
new DruidNode("s6", "h6", 8080, null, true, false),
new DruidNode("s6", "h6", false, 8080, null, true, false),
NodeType.PEON,
ImmutableMap.of(
LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier"))
);
DiscoveryDruidNode node7 = new DiscoveryDruidNode(
new DruidNode("s7", "h7", 8080, null, true, false),
new DruidNode("s7", "h7", false, 8080, null, true, false),
NodeType.BROKER,
ImmutableMap.of(
LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier"))
);
DiscoveryDruidNode node7Clone = new DiscoveryDruidNode(
new DruidNode("s7", "h7", 8080, null, true, false),
new DruidNode("s7", "h7", false, 8080, null, true, false),
NodeType.BROKER,
ImmutableMap.of(
LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier"))
);
DiscoveryDruidNode node8 = new DiscoveryDruidNode(
new DruidNode("s8", "h8", 8080, null, true, false),
new DruidNode("s8", "h8", false, 8080, null, true, false),
NodeType.COORDINATOR,
ImmutableMap.of()
);

View File

@ -141,7 +141,7 @@ public class InitializationTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false)
);
}
}

View File

@ -50,7 +50,7 @@ public class LookupListeningAnnouncerConfigTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false)
);
binder.bind(Key.get(
String.class,

View File

@ -88,6 +88,7 @@ public class ServiceAnnouncingChatHandlerProviderTest extends EasyMockSupport
Capture<DruidNode> captured = Capture.newInstance();
EasyMock.expect(node.getHost()).andReturn(TEST_HOST);
EasyMock.expect(node.isBindOnHost()).andReturn(false);
EasyMock.expect(node.getPlaintextPort()).andReturn(TEST_PORT);
EasyMock.expect(node.isEnablePlaintextPort()).andReturn(true);
EasyMock.expect(node.isEnableTlsPort()).andReturn(false);
@ -116,6 +117,7 @@ public class ServiceAnnouncingChatHandlerProviderTest extends EasyMockSupport
captured.reset();
resetAll();
EasyMock.expect(node.getHost()).andReturn(TEST_HOST);
EasyMock.expect(node.isBindOnHost()).andReturn(false);
EasyMock.expect(node.getPlaintextPort()).andReturn(TEST_PORT);
EasyMock.expect(node.isEnablePlaintextPort()).andReturn(true);
EasyMock.expect(node.getTlsPort()).andReturn(-1);

View File

@ -124,7 +124,7 @@ public class AsyncManagementForwardingServletTest extends BaseJettyTest
{
return Initialization.makeInjectorWithModules(GuiceInjectors.makeStartupInjector(), ImmutableList.of((binder) -> {
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", false, null, null, true, false)
);
binder.bind(JettyServerInitializer.class).to(ProxyJettyServerInit.class).in(LazySingleton.class);
LifecycleModule.register(binder, Server.class);

View File

@ -118,7 +118,7 @@ public class AsyncQueryForwardingServletTest extends BaseJettyTest
JsonConfigProvider.bindInstance(
binder,
Key.get(DruidNode.class, Self.class),
new DruidNode("test", "localhost", null, null, true, false)
new DruidNode("test", "localhost", false, null, null, true, false)
);
binder.bind(JettyServerInitializer.class).to(ProxyJettyServerInit.class).in(LazySingleton.class);
binder.bind(AuthorizerMapper.class).toInstance(

View File

@ -47,135 +47,135 @@ public class DruidNodeTest
DruidNode node;
node = new DruidNode(service, null, null, null, true, false);
node = new DruidNode(service, null, false, null, null, true, false);
Assert.assertEquals(DruidNode.getDefaultHost(), node.getHost());
Assert.assertEquals(-1, node.getPlaintextPort());
// Hosts which report only ipv6 will have getDefaultHost() report something like fe80::6e40:8ff:fe93:9230
// but getHostAndPort() reports [fe80::6e40:8ff:fe93:9230]
Assert.assertEquals(HostAndPort.fromString(DruidNode.getDefaultHost()).toString(), node.getHostAndPort());
node = new DruidNode(service, "2001:db8:85a3::8a2e:370:7334", -1, null, true, false);
node = new DruidNode(service, "2001:db8:85a3::8a2e:370:7334", false, -1, null, true, false);
Assert.assertEquals("2001:db8:85a3::8a2e:370:7334", node.getHost());
Assert.assertEquals(-1, node.getPlaintextPort());
Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]", node.getHostAndPort());
node = new DruidNode(service, "abc:123", null, null, true, false);
node = new DruidNode(service, "abc:123", false, null, null, true, false);
Assert.assertEquals("abc", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals("abc:123", node.getHostAndPort());
node = new DruidNode(service, "2001:db8:85a3::8a2e:370:7334", null, null, true, false);
node = new DruidNode(service, "2001:db8:85a3::8a2e:370:7334", false, null, null, true, false);
Assert.assertEquals("2001:db8:85a3::8a2e:370:7334", node.getHost());
Assert.assertTrue(8080 <= node.getPlaintextPort());
node = new DruidNode(service, "[2001:db8:85a3::8a2e:370:7334]", null, null, true, false);
node = new DruidNode(service, "[2001:db8:85a3::8a2e:370:7334]", false, null, null, true, false);
Assert.assertEquals("2001:db8:85a3::8a2e:370:7334", node.getHost());
Assert.assertTrue(8080 <= node.getPlaintextPort());
node = new DruidNode(service, "abc", null, null, true, false);
node = new DruidNode(service, "abc", false, null, null, true, false);
Assert.assertEquals("abc", node.getHost());
Assert.assertTrue(8080 <= node.getPlaintextPort());
node = new DruidNode(service, "abc", 123, null, true, false);
node = new DruidNode(service, "abc", false, 123, null, true, false);
Assert.assertEquals("abc", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals("abc:123", node.getHostAndPort());
node = new DruidNode(service, "abc:123", 123, null, true, false);
node = new DruidNode(service, "abc:123", false, 123, null, true, false);
Assert.assertEquals("abc", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals("abc:123", node.getHostAndPort());
node = new DruidNode(service, "[2001:db8:85a3::8a2e:370:7334]:123", null, null, true, false);
node = new DruidNode(service, "[2001:db8:85a3::8a2e:370:7334]:123", false, null, null, true, false);
Assert.assertEquals("2001:db8:85a3::8a2e:370:7334", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]:123", node.getHostAndPort());
node = new DruidNode(service, "2001:db8:85a3::8a2e:370:7334", 123, null, true, false);
node = new DruidNode(service, "2001:db8:85a3::8a2e:370:7334", false, 123, null, true, false);
Assert.assertEquals("2001:db8:85a3::8a2e:370:7334", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]:123", node.getHostAndPort());
node = new DruidNode(service, "[2001:db8:85a3::8a2e:370:7334]", 123, null, true, false);
node = new DruidNode(service, "[2001:db8:85a3::8a2e:370:7334]", false, 123, null, true, false);
Assert.assertEquals("2001:db8:85a3::8a2e:370:7334", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]:123", node.getHostAndPort());
node = new DruidNode(service, null, 123, null, true, false);
node = new DruidNode(service, null, false, 123, null, true, false);
Assert.assertEquals(DruidNode.getDefaultHost(), node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
node = new DruidNode(service, null, 123, 123, true, false);
node = new DruidNode(service, null, false, 123, 123, true, false);
Assert.assertEquals(DruidNode.getDefaultHost(), node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals(-1, node.getTlsPort());
node = new DruidNode(service, "host", 123, 123, true, false);
node = new DruidNode(service, "host", false, 123, 123, true, false);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals(-1, node.getTlsPort());
node = new DruidNode(service, "host:123", null, 123, true, false);
node = new DruidNode(service, "host:123", false, null, 123, true, false);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals(-1, node.getTlsPort());
node = new DruidNode("test", "host:123", null, 214, true, true);
node = new DruidNode("test", "host:123", false, null, 214, true, true);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals(214, node.getTlsPort());
node = new DruidNode("test", "host", 123, 214, true, true);
node = new DruidNode("test", "host", false, 123, 214, true, true);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals(214, node.getTlsPort());
node = new DruidNode("test", "host:123", 123, 214, true, true);
node = new DruidNode("test", "host:123", false, 123, 214, true, true);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals(214, node.getTlsPort());
node = new DruidNode("test", null, 123, 214, true, true);
node = new DruidNode("test", null, false, 123, 214, true, true);
Assert.assertEquals(DruidNode.getDefaultHost(), node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals(214, node.getTlsPort());
node = new DruidNode("test", "host:123", null, 214, false, true);
node = new DruidNode("test", "host:123", false, null, 214, false, true);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(-1, node.getPlaintextPort());
Assert.assertEquals(214, node.getTlsPort());
node = new DruidNode("test", "host:123", null, 123, false, true);
node = new DruidNode("test", "host:123", false, null, 123, false, true);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(-1, node.getPlaintextPort());
Assert.assertEquals(123, node.getTlsPort());
node = new DruidNode("test", null, null, 123, false, true);
node = new DruidNode("test", null, false, null, 123, false, true);
Assert.assertEquals(DruidNode.getDefaultHost(), node.getHost());
Assert.assertEquals(-1, node.getPlaintextPort());
Assert.assertEquals(123, node.getTlsPort());
node = new DruidNode("test", null, -1, 123, false, true);
node = new DruidNode("test", null, false, -1, 123, false, true);
Assert.assertEquals(DruidNode.getDefaultHost(), node.getHost());
Assert.assertEquals(-1, node.getPlaintextPort());
Assert.assertEquals(123, node.getTlsPort());
node = new DruidNode("test", "host", -1, 123, false, true);
node = new DruidNode("test", "host", false, -1, 123, false, true);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(-1, node.getPlaintextPort());
Assert.assertEquals(123, node.getTlsPort());
node = new DruidNode("test", "host", -1, 123, true, false);
node = new DruidNode("test", "host", false, -1, 123, true, false);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(-1, node.getPlaintextPort());
Assert.assertEquals(-1, node.getTlsPort());
node = new DruidNode("test", "host:123", 123, null, true, false);
node = new DruidNode("test", "host:123", false, 123, null, true, false);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals(-1, node.getTlsPort());
node = new DruidNode("test", "host:123", null, 123, true, false);
node = new DruidNode("test", "host:123", false, null, 123, true, false);
Assert.assertEquals("host", node.getHost());
Assert.assertEquals(123, node.getPlaintextPort());
Assert.assertEquals(-1, node.getTlsPort());
@ -184,73 +184,73 @@ public class DruidNodeTest
@Test(expected = IllegalArgumentException.class)
public void testConflictingPorts()
{
new DruidNode("test/service", "abc:123", 456, null, true, false);
new DruidNode("test/service", "abc:123", false, 456, null, true, false);
}
@Test(expected = IllegalArgumentException.class)
public void testAtLeastTlsOrPlainTextIsSet()
{
new DruidNode("test", "host:123", null, 123, false, false);
new DruidNode("test", "host:123", false, null, 123, false, false);
}
@Test(expected = IllegalArgumentException.class)
public void testSamePlainTextAndTlsPort()
{
new DruidNode("test", "host:123", null, 123, true, true);
new DruidNode("test", "host:123", false, null, 123, true, true);
}
@Test(expected = IllegalArgumentException.class)
public void testSamePlainTextAndTlsPort1()
{
new DruidNode("test", "host", 123, 123, true, true);
new DruidNode("test", "host", false, 123, 123, true, true);
}
@Test(expected = IllegalArgumentException.class)
public void testNullTlsPort()
{
new DruidNode("test", "host:123", null, null, true, true);
new DruidNode("test", "host:123", false, null, null, true, true);
}
@Test(expected = IllegalArgumentException.class)
public void testNullPlainTextAndTlsPort1()
{
new DruidNode("test", "host", null, null, true, true);
new DruidNode("test", "host", false, null, null, true, true);
}
@Test(expected = IllegalArgumentException.class)
public void testNullTlsPort1()
{
new DruidNode("test", "host:123", 123, null, true, true);
new DruidNode("test", "host:123", false, 123, null, true, true);
}
@Test(expected = IllegalArgumentException.class)
public void testNullPlainTextAndTlsPort()
{
new DruidNode("test", null, null, null, true, true);
new DruidNode("test", null, false, null, null, true, true);
}
@Test(expected = IllegalArgumentException.class)
public void testConflictingPlainTextPort()
{
new DruidNode("test", "host:123", 321, null, true, true);
new DruidNode("test", "host:123", false, 321, null, true, true);
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidIPv6WithPort()
{
new DruidNode("test/service", "[abc:fff]:123", 456, null, true, false);
new DruidNode("test/service", "[abc:fff]:123", false, 456, null, true, false);
}
@Test(expected = IllegalArgumentException.class)
public void testInvalidIPv6()
{
new DruidNode("test/service", "abc:fff", 456, null, true, false);
new DruidNode("test/service", "abc:fff", false, 456, null, true, false);
}
@Test(expected = IllegalArgumentException.class)
public void testConflictingPortsNonsense()
{
new DruidNode("test/service", "[2001:db8:85a3::8a2e:370:7334]:123", 456, null, true, false);
new DruidNode("test/service", "[2001:db8:85a3::8a2e:370:7334]:123", false, 456, null, true, false);
}
@Test
@ -259,10 +259,10 @@ public class DruidNodeTest
final String serviceName = "serviceName";
final String host = "some.host";
final int port = 9898;
Assert.assertEquals(new DruidNode(serviceName, host, port, null, true, false), new DruidNode(serviceName, host, port, null, true, false));
Assert.assertNotEquals(new DruidNode(serviceName, host, port, null, true, false), new DruidNode(serviceName, host, -1, null, true, false));
Assert.assertNotEquals(new DruidNode(serviceName, host, port, null, true, false), new DruidNode(serviceName, "other.host", port, null, true, false));
Assert.assertNotEquals(new DruidNode(serviceName, host, port, null, true, false), new DruidNode("otherServiceName", host, port, null, true, false));
Assert.assertEquals(new DruidNode(serviceName, host, false, port, null, true, false), new DruidNode(serviceName, host, false, port, null, true, false));
Assert.assertNotEquals(new DruidNode(serviceName, host, false, port, null, true, false), new DruidNode(serviceName, host, false, -1, null, true, false));
Assert.assertNotEquals(new DruidNode(serviceName, host, false, port, null, true, false), new DruidNode(serviceName, "other.host", false, port, null, true, false));
Assert.assertNotEquals(new DruidNode(serviceName, host, false, port, null, true, false), new DruidNode("otherServiceName", host, false, port, null, true, false));
}
@Test
@ -272,11 +272,11 @@ public class DruidNodeTest
final String serviceName = "serviceName";
final String host = "some.host";
final int port = 9898;
Assert.assertEquals(new DruidNode(serviceName, host, port, null, true, false).hashCode(), new DruidNode(serviceName, host, port, null, true, false).hashCode());
Assert.assertEquals(new DruidNode(serviceName, host, false, port, null, true, false).hashCode(), new DruidNode(serviceName, host, false, port, null, true, false).hashCode());
// Potential hash collision if hashCode method ever changes
Assert.assertNotEquals(new DruidNode(serviceName, host, port, null, true, false).hashCode(), new DruidNode(serviceName, host, -1, null, true, false).hashCode());
Assert.assertNotEquals(new DruidNode(serviceName, host, port, null, true, false).hashCode(), new DruidNode(serviceName, "other.host", port, null, true, false).hashCode());
Assert.assertNotEquals(new DruidNode(serviceName, host, port, null, true, false).hashCode(), new DruidNode("otherServiceName", host, port, null, true, false).hashCode());
Assert.assertNotEquals(new DruidNode(serviceName, host, false, port, null, true, false).hashCode(), new DruidNode(serviceName, host, false, -1, null, true, false).hashCode());
Assert.assertNotEquals(new DruidNode(serviceName, host, false, port, null, true, false).hashCode(), new DruidNode(serviceName, "other.host", false, port, null, true, false).hashCode());
Assert.assertNotEquals(new DruidNode(serviceName, host, false, port, null, true, false).hashCode(), new DruidNode("otherServiceName", host, false, port, null, true, false).hashCode());
}
@ -284,11 +284,12 @@ public class DruidNodeTest
public void testSerde1() throws Exception
{
DruidNode actual = mapper.readValue(
mapper.writeValueAsString(new DruidNode("service", "host", 1234, null, 5678, true, true)),
mapper.writeValueAsString(new DruidNode("service", "host", true, 1234, null, 5678, true, true)),
DruidNode.class
);
Assert.assertEquals("service", actual.getServiceName());
Assert.assertEquals("host", actual.getHost());
Assert.assertTrue(actual.isBindOnHost());
Assert.assertTrue(actual.isEnablePlaintextPort());
Assert.assertTrue(actual.isEnableTlsPort());
Assert.assertEquals(1234, actual.getPlaintextPort());
@ -299,11 +300,12 @@ public class DruidNodeTest
public void testSerde2() throws Exception
{
DruidNode actual = mapper.readValue(
mapper.writeValueAsString(new DruidNode("service", "host", 1234, null, 5678, null, false)),
mapper.writeValueAsString(new DruidNode("service", "host", false, 1234, null, 5678, null, false)),
DruidNode.class
);
Assert.assertEquals("service", actual.getServiceName());
Assert.assertEquals("host", actual.getHost());
Assert.assertFalse(actual.isBindOnHost());
Assert.assertTrue(actual.isEnablePlaintextPort());
Assert.assertFalse(actual.isEnableTlsPort());
Assert.assertEquals(1234, actual.getPlaintextPort());
@ -314,11 +316,12 @@ public class DruidNodeTest
public void testSerde3() throws Exception
{
DruidNode actual = mapper.readValue(
mapper.writeValueAsString(new DruidNode("service", "host", 1234, null, 5678, false, true)),
mapper.writeValueAsString(new DruidNode("service", "host", true, 1234, null, 5678, false, true)),
DruidNode.class
);
Assert.assertEquals("service", actual.getServiceName());
Assert.assertEquals("host", actual.getHost());
Assert.assertTrue(actual.isBindOnHost());
Assert.assertFalse(actual.isEnablePlaintextPort());
Assert.assertTrue(actual.isEnableTlsPort());
Assert.assertEquals(-1, actual.getPlaintextPort());
@ -331,6 +334,7 @@ public class DruidNodeTest
String json = "{\n"
+ " \"service\":\"service\",\n"
+ " \"host\":\"host\",\n"
+ " \"bindOnHost\":true,\n"
+ " \"plaintextPort\":1234,\n"
+ " \"tlsPort\":5678,\n"
+ " \"enablePlaintextPort\":true,\n"
@ -339,7 +343,7 @@ public class DruidNodeTest
DruidNode actual = mapper.readValue(json, DruidNode.class);
Assert.assertEquals(new DruidNode("service", "host", 1234, null, 5678, true, true), actual);
Assert.assertEquals(new DruidNode("service", "host", true, 1234, null, 5678, true, true), actual);
Assert.assertEquals("https", actual.getServiceScheme());
Assert.assertEquals("host:1234", actual.getHostAndPort());
@ -360,7 +364,7 @@ public class DruidNodeTest
DruidNode actual = mapper.readValue(json, DruidNode.class);
Assert.assertEquals(new DruidNode("service", "host", 1234, null, 5678, true, false), actual);
Assert.assertEquals(new DruidNode("service", "host", false, 1234, null, 5678, true, false), actual);
Assert.assertEquals("http", actual.getServiceScheme());
Assert.assertEquals("host:1234", actual.getHostAndPort());
@ -380,7 +384,7 @@ public class DruidNodeTest
DruidNode actual = mapper.readValue(json, DruidNode.class);
Assert.assertEquals(new DruidNode("service", "host", 1234, null, 5678, null, false), actual);
Assert.assertEquals(new DruidNode("service", "host", false, 1234, null, 5678, null, false), actual);
Assert.assertEquals("http", actual.getServiceScheme());
Assert.assertEquals("host:1234", actual.getHostAndPort());
@ -400,7 +404,7 @@ public class DruidNodeTest
DruidNode actual = mapper.readValue(json, DruidNode.class);
Assert.assertEquals(new DruidNode("service", "host", null, 1234, 5678, null, false), actual);
Assert.assertEquals(new DruidNode("service", "host", false, null, 1234, 5678, null, false), actual);
Assert.assertEquals("http", actual.getServiceScheme());
Assert.assertEquals("host:1234", actual.getHostAndPort());

View File

@ -190,7 +190,7 @@ public class CuratorDruidCoordinatorTest extends CuratorTestBase
Execs.singleThreaded("coordinator_test_load_queue_peon_dest-%d"),
druidCoordinatorConfig
);
druidNode = new DruidNode("hey", "what", 1234, null, true, false);
druidNode = new DruidNode("hey", "what", false, 1234, null, true, false);
loadManagementPeons = new ConcurrentHashMap<>();
scheduledExecutorFactory = (corePoolSize, nameFormat) -> Executors.newSingleThreadScheduledExecutor();
leaderAnnouncerLatch = new CountDownLatch(1);

View File

@ -160,7 +160,7 @@ public class DruidCoordinatorTest extends CuratorTestBase
druidCoordinatorConfig
);
loadQueuePeon.start();
druidNode = new DruidNode("hey", "what", 1234, null, true, false);
druidNode = new DruidNode("hey", "what", false, 1234, null, true, false);
loadManagementPeons = new ConcurrentHashMap<>();
scheduledExecutorFactory = new ScheduledExecutorFactory()
{

View File

@ -0,0 +1,88 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF 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.apache.druid.server.initialization;
import com.google.common.collect.ImmutableList;
import com.google.inject.Binder;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Module;
import org.apache.commons.io.IOUtils;
import org.apache.druid.guice.GuiceInjectors;
import org.apache.druid.guice.Jerseys;
import org.apache.druid.guice.JsonConfigProvider;
import org.apache.druid.guice.LazySingleton;
import org.apache.druid.guice.LifecycleModule;
import org.apache.druid.guice.annotations.Self;
import org.apache.druid.initialization.Initialization;
import org.apache.druid.server.DruidNode;
import org.apache.druid.server.initialization.jetty.JettyServerInitializer;
import org.apache.druid.server.security.AuthTestUtils;
import org.apache.druid.server.security.AuthorizerMapper;
import org.eclipse.jetty.server.Server;
import org.junit.Assert;
import org.junit.Test;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
public class JettyBindOnHostTest extends BaseJettyTest
{
@Override
protected Injector setupInjector()
{
return Initialization.makeInjectorWithModules(
GuiceInjectors.makeStartupInjector(),
ImmutableList.<Module>of(
new Module()
{
@Override
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder,
Key.get(DruidNode.class, Self.class),
new DruidNode("test", "localhost", true, null, null, true, false)
);
binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
Jerseys.addResource(binder, DefaultResource.class);
binder.bind(AuthorizerMapper.class).toInstance(AuthTestUtils.TEST_AUTHORIZER_MAPPER);
LifecycleModule.register(binder, Server.class);
}
}
)
);
}
@Test
public void testBindOnHost() throws Exception
{
Assert.assertEquals("localhost", server.getURI().getHost());
final URL url = new URL("http://localhost:" + port + "/default");
final HttpURLConnection get = (HttpURLConnection) url.openConnection();
Assert.assertEquals(DEFAULT_RESPONSE_CONTENT, IOUtils.toString(get.getInputStream(), StandardCharsets.UTF_8));
final HttpURLConnection post = (HttpURLConnection) url.openConnection();
post.setRequestMethod("POST");
Assert.assertEquals(DEFAULT_RESPONSE_CONTENT, IOUtils.toString(post.getInputStream(), StandardCharsets.UTF_8));
}
}

View File

@ -71,7 +71,7 @@ public class JettyQosTest extends BaseJettyTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", false, null, null, true, false)
);
binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);
Jerseys.addResource(binder, SlowResource.class);

View File

@ -87,7 +87,7 @@ public class JettyTest extends BaseJettyTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test", "localhost", false, null, null, true, false)
);
binder.bind(JettyServerInitializer.class).to(JettyServerInit.class).in(LazySingleton.class);

View File

@ -53,21 +53,21 @@ public class LookupNodeDiscoveryTest
.andReturn(druidNodeDiscovery);
DiscoveryDruidNode node1 = new DiscoveryDruidNode(
new DruidNode("s1", "h1", 8080, null, true, false),
new DruidNode("s1", "h1", false, 8080, null, true, false),
NodeType.HISTORICAL,
ImmutableMap.of(
LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier1"))
);
DiscoveryDruidNode node2 = new DiscoveryDruidNode(
new DruidNode("s2", "h2", 8080, null, true, false),
new DruidNode("s2", "h2", false, 8080, null, true, false),
NodeType.PEON,
ImmutableMap.of(
LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier1"))
);
DiscoveryDruidNode node3 = new DiscoveryDruidNode(
new DruidNode("s3", "h3", 8080, null, true, false),
new DruidNode("s3", "h3", false, 8080, null, true, false),
NodeType.PEON,
ImmutableMap.of(
LookupNodeService.DISCOVERY_SERVICE_KEY, new LookupNodeService("tier2"))

View File

@ -47,7 +47,7 @@ public class MetricsModuleTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false)
);
}
})
@ -72,7 +72,7 @@ public class MetricsModuleTest
public void configure(Binder binder)
{
JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, null, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("test-inject", null, false, null, null, true, false)
);
binder.bind(Key.get(
String.class,

View File

@ -74,19 +74,19 @@ public class TieredBrokerHostSelectorTest
druidNodeDiscoveryProvider = EasyMock.createStrictMock(DruidNodeDiscoveryProvider.class);
node1 = new DiscoveryDruidNode(
new DruidNode("hotBroker", "hotHost", 8080, null, true, false),
new DruidNode("hotBroker", "hotHost", false, 8080, null, true, false),
NodeType.BROKER,
ImmutableMap.of()
);
node2 = new DiscoveryDruidNode(
new DruidNode("coldBroker", "coldHost1", 8080, null, true, false),
new DruidNode("coldBroker", "coldHost1", false, 8080, null, true, false),
NodeType.BROKER,
ImmutableMap.of()
);
node3 = new DiscoveryDruidNode(
new DruidNode("coldBroker", "coldHost2", 8080, null, true, false),
new DruidNode("coldBroker", "coldHost2", false, 8080, null, true, false),
NodeType.BROKER,
ImmutableMap.of()
);

View File

@ -106,7 +106,7 @@ public class CreateTables extends GuiceRunnable
JsonConfigProvider.bindInstance(
binder,
Key.get(DruidNode.class, Self.class),
new DruidNode("tools", "localhost", -1, null, true, false)
new DruidNode("tools", "localhost", false, -1, null, true, false)
);
}
);

View File

@ -77,7 +77,7 @@ public class InsertSegment extends GuiceRunnable
new QueryableModule(),
new QueryRunnerFactoryModule(),
binder -> JsonConfigProvider.bindInstance(
binder, Key.get(DruidNode.class, Self.class), new DruidNode("tools", "localhost", -1, null, true, false)
binder, Key.get(DruidNode.class, Self.class), new DruidNode("tools", "localhost", false, -1, null, true, false)
)
);
}

View File

@ -88,7 +88,7 @@ public class ResetCluster extends GuiceRunnable
JsonConfigProvider.bindInstance(
binder,
Key.get(DruidNode.class, Self.class),
new DruidNode("tools", "localhost", -1, null, true, false)
new DruidNode("tools", "localhost", false, -1, null, true, false)
);
JsonConfigProvider.bind(binder, "druid.indexer.task", TaskConfig.class);
},

View File

@ -192,7 +192,7 @@ public class DruidAvaticaHandlerTest extends CalciteTestBase
);
final DruidAvaticaHandler handler = new DruidAvaticaHandler(
druidMeta,
new DruidNode("dummy", "dummy", 1, null, true, false),
new DruidNode("dummy", "dummy", false, 1, null, true, false),
new AvaticaMonitor()
);
final int port = ThreadLocalRandom.current().nextInt(9999) + 10000;
@ -798,7 +798,7 @@ public class DruidAvaticaHandlerTest extends CalciteTestBase
final DruidAvaticaHandler handler = new DruidAvaticaHandler(
smallFrameDruidMeta,
new DruidNode("dummy", "dummy", 1, null, true, false),
new DruidNode("dummy", "dummy", false, 1, null, true, false),
new AvaticaMonitor()
);
final int port = ThreadLocalRandom.current().nextInt(9999) + 20000;