mirror of https://github.com/apache/druid.git
default to canonical hostname instead of localhost
This commit is contained in:
parent
b42b41cca7
commit
53d2b961c5
|
@ -18,6 +18,7 @@
|
||||||
package io.druid.indexing.worker.config;
|
package io.druid.indexing.worker.config;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import io.druid.server.DruidNode;
|
||||||
|
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
@ -28,7 +29,7 @@ public class WorkerConfig
|
||||||
{
|
{
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
@NotNull
|
@NotNull
|
||||||
private String ip = "localhost";
|
private String ip = DruidNode.getDefaultHost();
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
@NotNull
|
@NotNull
|
||||||
|
|
|
@ -24,18 +24,19 @@ import com.google.common.base.Preconditions;
|
||||||
import com.google.common.net.HostAndPort;
|
import com.google.common.net.HostAndPort;
|
||||||
import com.google.inject.name.Named;
|
import com.google.inject.name.Named;
|
||||||
import com.metamx.common.IAE;
|
import com.metamx.common.IAE;
|
||||||
|
import com.metamx.common.ISE;
|
||||||
import io.druid.common.utils.SocketUtil;
|
import io.druid.common.utils.SocketUtil;
|
||||||
|
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.Max;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
|
import java.net.InetAddress;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class DruidNode
|
public class DruidNode
|
||||||
{
|
{
|
||||||
public static final String DEFAULT_HOST = "localhost";
|
|
||||||
|
|
||||||
@JsonProperty("service")
|
@JsonProperty("service")
|
||||||
@NotNull
|
@NotNull
|
||||||
private String serviceName;
|
private String serviceName;
|
||||||
|
@ -81,7 +82,7 @@ public class DruidNode
|
||||||
this.serviceName = serviceName;
|
this.serviceName = serviceName;
|
||||||
|
|
||||||
if(host == null && port == null) {
|
if(host == null && port == null) {
|
||||||
host = DEFAULT_HOST;
|
host = getDefaultHost();
|
||||||
port = -1;
|
port = -1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -92,7 +93,7 @@ public class DruidNode
|
||||||
throw new IAE("Conflicting host:port [%s] and port [%d] settings", host, port);
|
throw new IAE("Conflicting host:port [%s] and port [%d] settings", host, port);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
hostAndPort = HostAndPort.fromParts(DEFAULT_HOST, port);
|
hostAndPort = HostAndPort.fromParts(getDefaultHost(), port);
|
||||||
}
|
}
|
||||||
|
|
||||||
host = hostAndPort.getHostText();
|
host = hostAndPort.getHostText();
|
||||||
|
@ -136,6 +137,14 @@ public class DruidNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getDefaultHost() {
|
||||||
|
try {
|
||||||
|
return InetAddress.getLocalHost().getCanonicalHostName();
|
||||||
|
} catch(UnknownHostException e) {
|
||||||
|
throw new ISE(e, "Unable to determine host name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
|
|
|
@ -30,9 +30,9 @@ public class DruidNodeTest
|
||||||
DruidNode node;
|
DruidNode node;
|
||||||
|
|
||||||
node = new DruidNode(service, null, null);
|
node = new DruidNode(service, null, null);
|
||||||
Assert.assertEquals(DruidNode.DEFAULT_HOST, node.getHost());
|
Assert.assertEquals(DruidNode.getDefaultHost(), node.getHost());
|
||||||
Assert.assertEquals(-1, node.getPort());
|
Assert.assertEquals(-1, node.getPort());
|
||||||
Assert.assertEquals("localhost", node.getHostAndPort());
|
Assert.assertEquals(DruidNode.getDefaultHost(), node.getHostAndPort());
|
||||||
|
|
||||||
node = new DruidNode(service, "2001:db8:85a3::8a2e:370:7334", -1);
|
node = new DruidNode(service, "2001:db8:85a3::8a2e:370:7334", -1);
|
||||||
Assert.assertEquals("2001:db8:85a3::8a2e:370:7334", node.getHost());
|
Assert.assertEquals("2001:db8:85a3::8a2e:370:7334", node.getHost());
|
||||||
|
@ -82,7 +82,7 @@ public class DruidNodeTest
|
||||||
Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]:123", node.getHostAndPort());
|
Assert.assertEquals("[2001:db8:85a3::8a2e:370:7334]:123", node.getHostAndPort());
|
||||||
|
|
||||||
node = new DruidNode(service, null, 123);
|
node = new DruidNode(service, null, 123);
|
||||||
Assert.assertEquals(DruidNode.DEFAULT_HOST, node.getHost());
|
Assert.assertEquals(DruidNode.getDefaultHost(), node.getHost());
|
||||||
Assert.assertEquals(123, node.getPort());
|
Assert.assertEquals(123, node.getPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue