aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEirik Nygaard <eirik@yahoo-inc.com>2016-10-14 08:43:26 +0200
committerGitHub <noreply@github.com>2016-10-14 08:43:26 +0200
commit327fde0ff8a159ba142f23b5889c9ee8dcc3c29f (patch)
tree2d08b72b781aadf4044210955da5c17f5f631ca9
parentc09aadd28bed9cb485160a1cc046c6772d2db337 (diff)
Revert "Use HostName for message bus, but fix HostName to work with dev machines"
-rw-r--r--config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java3
-rw-r--r--config-model/src/main/java/com/yahoo/config/model/provision/SingleNodeProvisioner.java2
-rw-r--r--config-model/src/main/java/com/yahoo/vespa/model/container/configserver/ConfigserverCluster.java6
-rw-r--r--config-model/src/test/java/com/yahoo/config/model/deploy/SystemModelTestCase.java2
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/admin/AdminTestCase.java12
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/clients/test/Gateway20TestCase.java2
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java2
-rw-r--r--config-model/src/test/java/com/yahoo/vespa/model/test/VespaModelTestCase.java11
-rw-r--r--config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDBRegistry.java2
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/rpc/GetConfigProcessor.java2
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/rpc/TestWithRpc.java2
-rw-r--r--container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java2
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java2
-rw-r--r--container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java2
-rw-r--r--container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java2
-rw-r--r--container-search/src/test/java/com/yahoo/fs4/mplex/BackendTestCase.java34
-rw-r--r--container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTester.java2
-rw-r--r--docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java4
-rw-r--r--messagebus/src/main/java/com/yahoo/messagebus/network/Identity.java11
-rw-r--r--node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java2
-rw-r--r--standalone-container/src/main/scala/com/yahoo/container/standalone/LocalFileDb.scala2
-rw-r--r--vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java2
-rw-r--r--vespajlib/src/main/java/com/yahoo/net/HostName.java135
-rw-r--r--vespajlib/src/main/java/com/yahoo/net/LinuxInetAddress.java98
-rw-r--r--vespajlib/src/test/java/com/yahoo/net/HostNameTestCase.java9
-rwxr-xr-xvespajlib/src/test/java/com/yahoo/net/LinuxInetAddressTestCase.java42
27 files changed, 225 insertions, 172 deletions
diff --git a/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java b/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java
index fbd5e712d3d..6a5abee7cb3 100644
--- a/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java
+++ b/config-model/src/main/java/com/yahoo/config/model/provision/Hosts.java
@@ -2,6 +2,7 @@
package com.yahoo.config.model.provision;
import com.google.common.collect.ImmutableMap;
+import com.yahoo.cloud.config.ConfigserverConfig;
import com.yahoo.config.model.builder.xml.XmlHelper;
import com.yahoo.net.HostName;
import com.yahoo.text.XML;
@@ -75,7 +76,7 @@ public class Hosts {
throw new RuntimeException("Missing 'name' attribute for host.");
}
if ("localhost".equals(name)) {
- name = HostName.getHostName();
+ name = HostName.getLocalhost();
}
final List<String> hostAliases = VespaDomBuilder.getHostAliases(hostE.getChildNodes());
if (hostAliases.isEmpty()) {
diff --git a/config-model/src/main/java/com/yahoo/config/model/provision/SingleNodeProvisioner.java b/config-model/src/main/java/com/yahoo/config/model/provision/SingleNodeProvisioner.java
index fb706e7201f..fe8b3935fcf 100644
--- a/config-model/src/main/java/com/yahoo/config/model/provision/SingleNodeProvisioner.java
+++ b/config-model/src/main/java/com/yahoo/config/model/provision/SingleNodeProvisioner.java
@@ -26,7 +26,7 @@ public class SingleNodeProvisioner implements HostProvisioner {
public SingleNodeProvisioner() {
try {
- host = new Host(HostSystem.lookupCanonicalHostname(HostName.getHostName()));
+ host = new Host(HostSystem.lookupCanonicalHostname(HostName.getLocalhost()));
this.hostSpec = new HostSpec(host.hostname(), host.aliases());
}
catch (UnknownHostException e) {
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/configserver/ConfigserverCluster.java b/config-model/src/main/java/com/yahoo/vespa/model/container/configserver/ConfigserverCluster.java
index 96c80c57ab2..ef0f4882f1c 100644
--- a/config-model/src/main/java/com/yahoo/vespa/model/container/configserver/ConfigserverCluster.java
+++ b/config-model/src/main/java/com/yahoo/vespa/model/container/configserver/ConfigserverCluster.java
@@ -52,7 +52,7 @@ public class ConfigserverCluster extends AbstractConfigProducer
@Override
public void getConfig(ZookeeperServerConfig.Builder builder) {
- String myhostname = HostName.getHostName();
+ String myhostname = HostName.getLocalhost();
int myid = 0;
int i = 0;
for (ConfigServer server : getConfigServers()) {
@@ -115,7 +115,7 @@ public class ConfigserverCluster extends AbstractConfigProducer
builder.defaultContentFlavor(options.defaultContentFlavor().get());
}
- builder.serverId(HostName.getHostName());
+ builder.serverId(HostName.getLocalhost());
if (!containerCluster.getHttp().getHttpServer().getConnectorFactories().isEmpty()) {
builder.httpport(containerCluster.getHttp().getHttpServer().getConnectorFactories().get(0).getListenPort());
}
@@ -144,7 +144,7 @@ public class ConfigserverCluster extends AbstractConfigProducer
if (options.allConfigServers().length > 0) {
return options.allConfigServers();
} else {
- return new ConfigServer[]{new ConfigServer(HostName.getHostName(), Optional.<Integer>empty()) };
+ return new ConfigServer[]{new ConfigServer(HostName.getLocalhost(), Optional.<Integer>empty()) };
}
}
diff --git a/config-model/src/test/java/com/yahoo/config/model/deploy/SystemModelTestCase.java b/config-model/src/test/java/com/yahoo/config/model/deploy/SystemModelTestCase.java
index dc0ace32c1b..6be85fb19e4 100644
--- a/config-model/src/test/java/com/yahoo/config/model/deploy/SystemModelTestCase.java
+++ b/config-model/src/test/java/com/yahoo/config/model/deploy/SystemModelTestCase.java
@@ -78,7 +78,7 @@ public class SystemModelTestCase {
// Verify configIds from vespaModel
assertTrue(12 <= vespaModel.getConfigIds().size());
- String localhost = HostName.getHostName();
+ String localhost = HostName.getLocalhost();
String localhostConfigId = "hosts/" + localhost;
Set<String> configIds = vespaModel.getConfigIds();
assertTrue(configIds.contains("client"));
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/admin/AdminTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/admin/AdminTestCase.java
index f203fbce328..a8554c54867 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/admin/AdminTestCase.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/admin/AdminTestCase.java
@@ -8,6 +8,7 @@ import com.yahoo.cloud.config.SentinelConfig;
import com.yahoo.config.model.ApplicationConfigProducerRoot;
import com.yahoo.config.model.deploy.DeployProperties;
import com.yahoo.config.model.deploy.DeployState;
+import com.yahoo.config.model.test.MockApplicationPackage;
import com.yahoo.config.model.test.TestDriver;
import com.yahoo.config.model.test.TestRoot;
import com.yahoo.config.provision.ApplicationId;
@@ -23,7 +24,10 @@ import com.yahoo.vespa.model.container.component.Component;
import com.yahoo.vespa.model.container.component.StatisticsComponent;
import com.yahoo.vespa.model.test.utils.VespaModelCreatorWithFilePkg;
import org.junit.Test;
+import org.xml.sax.SAXException;
+import java.io.IOException;
+import java.util.List;
import java.util.Set;
import static org.hamcrest.CoreMatchers.is;
@@ -61,7 +65,7 @@ public class AdminTestCase {
// Verify configIds
Set<String> configIds = vespaModel.getConfigIds();
- String localhost = HostName.getHostName();
+ String localhost = HostName.getLocalhost();
String localhostConfigId = "hosts/" + localhost;
assertTrue(configIds.contains(localhostConfigId));
assertTrue(configIds.contains("admin/logserver"));
@@ -115,7 +119,7 @@ public class AdminTestCase {
// Verify configIds
Set<String> configIds = vespaModel.getConfigIds();
- String localhost = HostName.getHostName();
+ String localhost = HostName.getLocalhost();
String localhostConfigId = "hosts/" + localhost;
assertTrue(configIds.contains(localhostConfigId));
assertTrue(configIds.contains("admin/logserver"));
@@ -152,7 +156,7 @@ public class AdminTestCase {
tenant("quux").
applicationName("foo").instanceName("bim").build()).build()).build();
TestRoot root = new TestDriver().buildModel(state);
- String localhost = HostName.getHostName();
+ String localhost = HostName.getLocalhost();
SentinelConfig config = root.getConfig(SentinelConfig.class, "hosts/" + localhost);
assertThat(config.application().tenant(), is("quux"));
assertThat(config.application().name(), is("foo"));
@@ -175,7 +179,7 @@ public class AdminTestCase {
// Verify configIds
Set<String> configIds = vespaModel.getConfigIds();
- String localhost = HostName.getHostName();
+ String localhost = HostName.getLocalhost();
String localhostConfigId = "hosts/" + localhost;
assertTrue(configIds.contains(localhostConfigId));
assertTrue(configIds.contains("admin/logserver"));
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/clients/test/Gateway20TestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/clients/test/Gateway20TestCase.java
index 579abf6d2c6..5987ab8410a 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/clients/test/Gateway20TestCase.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/clients/test/Gateway20TestCase.java
@@ -21,7 +21,7 @@ import static org.junit.Assert.*;
* @author <a href="mailto:gunnarga@yahoo-inc.com">Gunnar Gauslaa Bergem</a>
*/
public class Gateway20TestCase {
- private static String hostname = HostName.getHostName(); // Using the same way of getting hostname as filedistribution model
+ private static String hostname = HostName.getLocalhost(); // Using the same way of getting hostname as filedistribution model
@Test
public void testSimpleDocprocV3() throws Exception {
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java b/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java
index d9fc3cd9007..170586bef85 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/container/configserver/ConfigserverClusterTest.java
@@ -71,7 +71,7 @@ public class ConfigserverClusterTest {
assertThat(config.configModelPluginDir().get(0), is(Defaults.getDefaults().vespaHome() + "lib/jars/config-models"));
assertThat(config.rpcport(), is(12345));
assertThat(config.httpport(), is(1337));
- assertThat(config.serverId(), is(HostName.getHostName()));
+ assertThat(config.serverId(), is(HostName.getLocalhost()));
assertTrue(config.useVespaVersionInRequest());
assertThat(config.numParallelTenantLoaders(), is(4));
assertFalse(config.multitenant());
diff --git a/config-model/src/test/java/com/yahoo/vespa/model/test/VespaModelTestCase.java b/config-model/src/test/java/com/yahoo/vespa/model/test/VespaModelTestCase.java
index 5bb01c87d0f..87fb5e567a5 100644
--- a/config-model/src/test/java/com/yahoo/vespa/model/test/VespaModelTestCase.java
+++ b/config-model/src/test/java/com/yahoo/vespa/model/test/VespaModelTestCase.java
@@ -23,6 +23,7 @@ import com.yahoo.container.core.ContainerHttpConfig;
import com.yahoo.document.config.DocumentmanagerConfig;
import com.yahoo.messagebus.MessagebusConfig;
import com.yahoo.net.HostName;
+import com.yahoo.net.LinuxInetAddress;
import com.yahoo.vespa.config.ConfigKey;
import com.yahoo.vespa.config.ConfigPayload;
import com.yahoo.vespa.config.ConfigPayloadBuilder;
@@ -101,7 +102,7 @@ public class VespaModelTestCase {
LogdConfig.Builder b = new LogdConfig.Builder();
b = (LogdConfig.Builder) model.getConfig(b, "");
LogdConfig c = new LogdConfig(b);
- assertEquals(HostSystem.lookupCanonicalHostname(HostName.getHostName()), c.logserver().host());
+ assertEquals(HostSystem.lookupCanonicalHostname(HostName.getLocalhost()), c.logserver().host());
SlobroksConfig.Builder sb = new SlobroksConfig.Builder();
sb = (com.yahoo.cloud.config.SlobroksConfig.Builder) model.getConfig(sb, "");
@@ -112,7 +113,7 @@ public class VespaModelTestCase {
zb = (ZookeepersConfig.Builder) model.getConfig(zb, "");
ZookeepersConfig zc = new ZookeepersConfig(zb);
assertEquals(zc.zookeeperserverlist().split(",").length, 2);
- assertTrue(zc.zookeeperserverlist().startsWith(HostSystem.lookupCanonicalHostname(HostName.getHostName())));
+ assertTrue(zc.zookeeperserverlist().startsWith(HostSystem.lookupCanonicalHostname(HostName.getLocalhost())));
ApplicationIdConfig.Builder appIdBuilder = new ApplicationIdConfig.Builder();
appIdBuilder = (ApplicationIdConfig.Builder) model.getConfig(appIdBuilder, "");
@@ -126,11 +127,11 @@ public class VespaModelTestCase {
public void testHostsConfig() {
VespaModel model = getVespaModel(TESTDIR + "app_qrserverandgw");
LogdConfig config = getLogdConfig(model, "");
- assertEquals(config.logserver().host(), HostName.getHostName());
+ assertEquals(config.logserver().host(), HostName.getLocalhost());
assertNotNull(config);
config = getLogdConfig(model, "hosts");
assertNotNull(config);
- assertEquals(config.logserver().host(), HostName.getHostName());
+ assertEquals(config.logserver().host(), HostName.getLocalhost());
}
private static LogdConfig getLogdConfig(VespaModel model, String configId) {
@@ -157,7 +158,7 @@ public class VespaModelTestCase {
LogdConfig config = getLogdConfig(model, "");
assertNotNull(config);
assertEquals(config.logserver().host(), "foo");
- config = getLogdConfig(model, "hosts/" + HostName.getHostName() + "/logd");
+ config = getLogdConfig(model, "hosts/" + HostName.getLocalhost() + "/logd");
assertNotNull(config);
assertEquals(config.logserver().host(), "foo");
}
diff --git a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java
index b1eb05fa76b..52df1cff117 100644
--- a/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java
+++ b/config/src/main/java/com/yahoo/vespa/config/util/ConfigUtils.java
@@ -424,7 +424,7 @@ public class ConfigUtils {
}
public static String getCanonicalHostName() {
- return HostName.getHostName();
+ return HostName.getLocalhost();
}
/**
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDBRegistry.java b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDBRegistry.java
index 307a0163331..37cea22e420 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDBRegistry.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/filedistribution/FileDBRegistry.java
@@ -35,7 +35,7 @@ public class FileDBRegistry implements FileRegistry {
@Override
public String fileSourceHost() {
- return HostName.getHostName();
+ return HostName.getLocalhost();
}
@Override
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/GetConfigProcessor.java b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/GetConfigProcessor.java
index 6d9e1a9e6c1..310c7ceeef7 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/GetConfigProcessor.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/rpc/GetConfigProcessor.java
@@ -27,7 +27,7 @@ import java.util.logging.Logger;
class GetConfigProcessor implements Runnable {
private static final Logger log = Logger.getLogger(GetConfigProcessor.class.getName());
- private static final String localHostName = HostName.getHostName();
+ private static final String localHostName = HostName.getLocalhost();
private final JRTServerConfigRequest request;
/* True only when this request has expired its server timeout and we need to respond to the client */
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/TestWithRpc.java b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/TestWithRpc.java
index 4348b587596..8f1754357b2 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/TestWithRpc.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/rpc/TestWithRpc.java
@@ -43,7 +43,7 @@ import static org.junit.Assert.assertTrue;
public class TestWithRpc {
private final ManualClock clock = new ManualClock(Instant.ofEpochMilli(100));
- private final String myHostname = HostName.getHostName();
+ private final String myHostname = HostName.getLocalhost();
private final HostLivenessTracker hostLivenessTracker = new ConfigRequestHostLivenessTracker(clock);
protected RpcServer rpcServer;
diff --git a/container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java b/container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java
index 3906e3a57ff..8b0ed41cd8c 100644
--- a/container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java
+++ b/container-core/src/main/java/com/yahoo/container/osgi/ContainerRpcAdaptor.java
@@ -43,7 +43,7 @@ public class ContainerRpcAdaptor extends AbstractRpcAdaptor {
public ContainerRpcAdaptor(Osgi osgi) {
this.osgi = osgi;
this.supervisor = new Supervisor(new Transport());
- this.hostname = HostName.getHostName();
+ this.hostname = HostName.getLocalhost();
bindCommands(supervisor);
}
diff --git a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java
index c7829dfde7f..36ae057b418 100644
--- a/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java
+++ b/container-search/src/main/java/com/yahoo/prelude/cluster/ClusterSearcher.java
@@ -192,7 +192,7 @@ public class ClusterSearcher extends Searcher {
if (InetAddress.getByName(host).isLoopbackAddress())
return false;
else
- return !host.equals(HostName.getHostName());
+ return !host.equals(HostName.getLocalhost());
}
private static ClusterParams makeClusterParams(int searchclusterIndex,
diff --git a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java
index ee059edb519..504c5dd363a 100644
--- a/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java
+++ b/container-search/src/main/java/com/yahoo/prelude/fastsearch/FastSearcher.java
@@ -94,7 +94,7 @@ public class FastSearcher extends VespaBackEndSearcher {
this.dispatchBackend = dispatchBackend;
this.fs4ResourcePool = fs4ResourcePool;
this.dispatcher = dispatcher;
- this.selfHostname = HostName.getHostName();
+ this.selfHostname = HostName.getLocalhost();
}
private static SimpleDateFormat isoDateFormat;
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java b/container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java
index c1a07759718..b6ee70802d8 100644
--- a/container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java
+++ b/container-search/src/main/java/com/yahoo/search/dispatch/SearchCluster.java
@@ -91,7 +91,7 @@ public class SearchCluster implements NodeManager<SearchCluster.Node> {
nodesByHostBuilder.put(node.hostname(), node);
this.nodesByHost = nodesByHostBuilder.build();
- this.directDispatchTarget = findDirectDispatchTarget(HostName.getHostName(), size, containerClusterSize,
+ this.directDispatchTarget = findDirectDispatchTarget(HostName.getLocalhost(), size, containerClusterSize,
nodesByHost, groups);
// Set up monitoring of the fs4 interface of the nodes
diff --git a/container-search/src/test/java/com/yahoo/fs4/mplex/BackendTestCase.java b/container-search/src/test/java/com/yahoo/fs4/mplex/BackendTestCase.java
index f9c14a81d13..52a66fa6db9 100644
--- a/container-search/src/test/java/com/yahoo/fs4/mplex/BackendTestCase.java
+++ b/container-search/src/test/java/com/yahoo/fs4/mplex/BackendTestCase.java
@@ -1,18 +1,9 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.fs4.mplex;
-import com.yahoo.container.search.Fs4Config;
-import com.yahoo.fs4.BasicPacket;
-import com.yahoo.fs4.ChannelTimeoutException;
-import com.yahoo.fs4.PacketListener;
-import com.yahoo.fs4.PingPacket;
-import com.yahoo.fs4.QueryPacket;
-import com.yahoo.fs4.mplex.Backend.BackendStatistics;
-import com.yahoo.prelude.fastsearch.FS4ResourcePool;
-import com.yahoo.search.Query;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.InetAddress;
@@ -22,9 +13,21 @@ import java.net.Socket;
import java.nio.ByteBuffer;
import java.util.logging.Logger;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
+import com.yahoo.container.search.Fs4Config;
+import com.yahoo.net.HostName;
+import com.yahoo.net.LinuxInetAddress;
+import com.yahoo.prelude.fastsearch.FS4ResourcePool;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import com.yahoo.fs4.BasicPacket;
+import com.yahoo.fs4.ChannelTimeoutException;
+import com.yahoo.fs4.PacketListener;
+import com.yahoo.fs4.PingPacket;
+import com.yahoo.fs4.QueryPacket;
+import com.yahoo.fs4.mplex.Backend.BackendStatistics;
+import com.yahoo.search.Query;
/**
* Test networking code for talking to dispatch.
@@ -111,6 +114,7 @@ public class BackendTestCase {
public MockServer() throws IOException {
ServerSocket socket = new ServerSocket(0, 50, InetAddress.getLoopbackAddress());
+ //ServerSocket socket = new ServerSocket(0, 50, LinuxInetAddress.getLocalHost());
host = (InetSocketAddress) socket.getLocalSocketAddress();
dispatch = new MockDispatch(socket);
worker = new Thread(dispatch);
diff --git a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTester.java b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTester.java
index 93b18da215a..d2638be4bc7 100644
--- a/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTester.java
+++ b/container-search/src/test/java/com/yahoo/prelude/fastsearch/test/FastSearcherTester.java
@@ -27,7 +27,7 @@ import static org.junit.Assert.assertEquals;
*/
class FastSearcherTester {
- public static final String selfHostname = HostName.getHostName();
+ public static final String selfHostname = HostName.getLocalhost();
private final MockFS4ResourcePool mockFS4ResourcePool;
private final FastSearcher fastSearcher;
diff --git a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java
index c0ffe367259..5e5185bc6be 100644
--- a/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java
+++ b/docker-api/src/main/java/com/yahoo/vespa/hosted/dockerapi/DockerImpl.java
@@ -124,7 +124,7 @@ public class DockerImpl implements Docker {
if (! dockerClient.listNetworksCmd().withNameFilter(DOCKER_CUSTOM_MACVLAN_NETWORK_NAME).exec().isEmpty()) return;
// Use IPv6 address if there is a mix of IP4 and IPv6 by taking the longest address.
- List<InetAddress> hostAddresses = Arrays.asList(InetAddress.getAllByName(com.yahoo.net.HostName.getHostName()));
+ List<InetAddress> hostAddresses = Arrays.asList(InetAddress.getAllByName(com.yahoo.net.HostName.getLocalhost()));
InetAddress hostAddress = Collections.max(hostAddresses,
(o1, o2) -> o1.getAddress().length - o2.getAddress().length);
@@ -563,7 +563,7 @@ public class DockerImpl implements Docker {
private void setMetrics(MetricReceiverWrapper metricReceiver) {
Dimensions dimensions = new Dimensions.Builder()
- .add("host", HostName.getHostName())
+ .add("host", HostName.getLocalhost())
.add("role", "docker").build();
numberOfRunningContainersGauge = metricReceiver.declareGauge(dimensions, "containers.running");
diff --git a/messagebus/src/main/java/com/yahoo/messagebus/network/Identity.java b/messagebus/src/main/java/com/yahoo/messagebus/network/Identity.java
index a10cd4b8a63..45887b072ab 100644
--- a/messagebus/src/main/java/com/yahoo/messagebus/network/Identity.java
+++ b/messagebus/src/main/java/com/yahoo/messagebus/network/Identity.java
@@ -1,7 +1,12 @@
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.messagebus.network;
+import com.yahoo.log.LogLevel;
import com.yahoo.net.HostName;
+import com.yahoo.net.LinuxInetAddress;
+
+import java.net.Inet6Address;
+import java.net.InetAddress;
/**
* This class encapsulates the identity of the application that uses this instance of message bus. This identity
@@ -23,7 +28,11 @@ public class Identity {
* @param configId The config identifier for the application.
*/
public Identity(String configId) {
- hostname = HostName.getHostName(); // ... but fallback to hostname if we get an IPv6 address
+ InetAddress addr = LinuxInetAddress.getLocalHost(); // try hard to get a resolvable address
+ if (addr instanceof Inet6Address) //
+ hostname = HostName.getLocalhost(); // ... but fallback to hostname if we get an IPv6 address
+ else
+ hostname = addr.getCanonicalHostName();
servicePrefix = configId;
}
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java
index b86a3c11f70..15a33dddd3c 100644
--- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java
+++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeadmin/NodeAdminImpl.java
@@ -75,7 +75,7 @@ public class NodeAdminImpl implements NodeAdmin {
this.nodeAgentScanIntervalMillis = nodeAgentScanIntervalMillis;
Dimensions dimensions = new Dimensions.Builder()
- .add("host", HostName.getHostName())
+ .add("host", HostName.getLocalhost())
.add("role", "docker").build();
this.numberOfContainersInActiveState = metricReceiver.declareGauge(dimensions, "nodes.state.active");
diff --git a/standalone-container/src/main/scala/com/yahoo/container/standalone/LocalFileDb.scala b/standalone-container/src/main/scala/com/yahoo/container/standalone/LocalFileDb.scala
index b1c7e9457ac..7af08a4685d 100644
--- a/standalone-container/src/main/scala/com/yahoo/container/standalone/LocalFileDb.scala
+++ b/standalone-container/src/main/scala/com/yahoo/container/standalone/LocalFileDb.scala
@@ -49,7 +49,7 @@ class LocalFileDb(appPath: Path) extends FileAcquirer with FileRegistry {
}
def fileSourceHost: String =
- HostName.getHostName
+ HostName.getLocalhost
def allRelativePaths: java.util.Set[String] = {
new java.util.HashSet(fileReferenceToFile.values.map(_.getPath))
diff --git a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java
index 78b33abedda..c37cb51d7ca 100644
--- a/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java
+++ b/vespaclient-container-plugin/src/main/java/com/yahoo/vespa/http/server/FeedHandler.java
@@ -270,7 +270,7 @@ public class FeedHandler extends LoggingRequestHandler {
}
private static String resolveLocalHostname() {
- String hostname = HostName.getHostName();
+ String hostname = HostName.getLocalhost();
if (hostname.equals("localhost")) {
return "";
}
diff --git a/vespajlib/src/main/java/com/yahoo/net/HostName.java b/vespajlib/src/main/java/com/yahoo/net/HostName.java
index 061b53216c0..4e791ca117a 100644
--- a/vespajlib/src/main/java/com/yahoo/net/HostName.java
+++ b/vespajlib/src/main/java/com/yahoo/net/HostName.java
@@ -2,139 +2,40 @@
package com.yahoo.net;
import java.io.BufferedReader;
-import java.io.IOException;
import java.io.InputStreamReader;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import java.util.Objects;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.util.stream.Collectors;
/**
- * Utilities for getting the hostname of the system running the JVM.
+ * Utilities for getting the hostname on a system running with the JVM. This is moved here from the old
+ * HostSystem#getHostName in config-model.
*
* @author lulf
- * @author bratseth
- * @author hakon
*/
public class HostName {
- private static final Logger logger = Logger.getLogger(HostName.class.getName());
-
- private static String cachedHostName = null;
+ private static String myHost = null;
/**
- * Return a fully qualified hostname that resolves to an IP address on a network interface.
- * Normally this is the same as the 'hostname' command, but on dev machines on WiFi,
- * that IP isn't configured so we prefer a WiFi network interface IP address which is both reachable and
- * has a DNS entry.
+ * Static method that returns the name of localhost using shell command "hostname".
+ * If you need a guaranteed resolvable name see LinuxINetAddress.
*
- * @return the preferred name of localhost
- * @throws RuntimeException if accessing the network or the 'hostname' command fails
+ * @return the name of localhost.
+ * @throws RuntimeException if executing the command 'hostname' fails.
*/
- public static synchronized String getHostName() {
- if (cachedHostName == null) {
+ public static synchronized String getLocalhost() {
+ if (myHost == null) {
try {
- cachedHostName = getPreferredAddress().canonicalHostName;
- } catch (Exception e) {
- throw new RuntimeException("Failed to find a preferred hostname", e);
- }
- }
- return cachedHostName;
- }
-
- private static Address getPreferredAddress() throws Exception {
- List<Address> addresses = getReachableNetworkInterfaceAddresses();
-
- // Prefer address matching the system hostname
- String systemHostName = getSystemHostName();
- List<Address> systemAddresses = addresses.stream()
- .filter(address -> Objects.equals(address.canonicalHostName, systemHostName))
- .collect(Collectors.toList());
- if (systemAddresses.size() >= 1) {
- return systemAddresses.iterator().next();
- }
-
- // Otherwise, prefer non-local address.
- List<Address> nonLocalAddresses = addresses.stream()
- .filter(address -> !address.ipAddress.isAnyLocalAddress())
- .collect(Collectors.toList());
- if (nonLocalAddresses.size() >= 1) {
- return nonLocalAddresses.iterator().next();
- }
-
- // Otherwise, pick a local address.
- List<Address> localAddresses = addresses.stream()
- .filter(address -> address.ipAddress.isAnyLocalAddress())
- .collect(Collectors.toList());
- if (localAddresses.size() >= 1) {
- return localAddresses.iterator().next();
- }
-
- throw new RuntimeException("Failed to find any addresses on the network interfaces that resolves to a DNS name");
- }
-
- // public for testing purposes (all testing machines should have a hostname
- public static String getSystemHostName() throws Exception {
- Process process = Runtime.getRuntime().exec("hostname");
- BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
- String hostname = in.readLine();
- process.waitFor();
- if (process.exitValue() != 0) {
- throw new RuntimeException("Command 'hostname' failed with exit code " + process.exitValue());
- }
-
- return hostname;
- }
-
- private static class Address {
-
- public final InetAddress ipAddress;
- public final String canonicalHostName;
-
- public Address(InetAddress ipAddress, String canonicalHostName) {
- this.ipAddress = ipAddress;
- this.canonicalHostName = canonicalHostName;
- }
-
- }
-
- private static List<Address> getReachableNetworkInterfaceAddresses() throws SocketException {
- List<Address> addresses = new ArrayList<>();
-
- for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces())) {
- for (InetAddress ipAddress : Collections.list(networkInterface.getInetAddresses())) {
- String hostname = ipAddress.getCanonicalHostName();
- if (Objects.equals(hostname, ipAddress.getHostAddress())) {
- // getCanonicalHostName() failed to get the fully qualified domain name
- continue;
- }
-
- try {
- // ping says ~50ms on my Fedora Lenovo, but that seems a lot for pinging oneself - hakon
- int timeoutMs = 100;
- if ( ! ipAddress.isReachable(timeoutMs)) {
- // The network interface may be down, ignore address
- logger.log(Level.INFO, ipAddress.toString() +
- " is unreachable w/" + timeoutMs + "ms timeout, ignoring address");
- continue;
- }
- } catch (IOException e) {
- // Why would this be different from !isReachable ?
- logger.log(Level.INFO, "Failed testing reachability of " + ipAddress + ", ignoring address", e);
- continue;
+ Process p = Runtime.getRuntime().exec("hostname");
+ BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
+ myHost = in.readLine();
+ p.waitFor();
+ if (p.exitValue() != 0) {
+ throw new RuntimeException("Command 'hostname' failed: exit("+p.exitValue()+")");
}
-
- addresses.add(new Address(ipAddress, hostname));
+ } catch (Exception e) {
+ throw new RuntimeException("Failed when executing command 'hostname'", e);
}
}
-
- return addresses;
+ return myHost;
}
}
diff --git a/vespajlib/src/main/java/com/yahoo/net/LinuxInetAddress.java b/vespajlib/src/main/java/com/yahoo/net/LinuxInetAddress.java
new file mode 100644
index 00000000000..9d50c99d77c
--- /dev/null
+++ b/vespajlib/src/main/java/com/yahoo/net/LinuxInetAddress.java
@@ -0,0 +1,98 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.net;
+
+import java.net.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.stream.Collectors;
+
+/**
+ * Utilities for returning localhost addresses on Linux.
+ * See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4665037 on why this is necessary.
+ *
+ * @author bratseth
+ */
+public class LinuxInetAddress {
+
+ /**
+ * Returns an InetAddress representing a resolvable localhost address.
+ * A non-loopback address is preferred if available.
+ * An address that resolves to a hostname is preferred among non-loopback addresses.
+ * IPv4 is preferred over IPv6 among resolving addresses.
+ *
+ * @return a localhost address
+ */
+ // Note: Checking resolvability of ipV6 addresses takes a long time on some systems (over 5 seconds
+ // for some addresses on my mac). This method is written to minimize the number of resolution checks done
+ // and to defer ip6 checks until necessary.
+ public static InetAddress getLocalHost() {
+ InetAddress fallback = InetAddress.getLoopbackAddress();
+ try {
+ fallback = InetAddress.getLocalHost();
+ List<InetAddress> nonLoopback =
+ getAllLocalFromNetwork().stream().filter(a -> ! a.isLoopbackAddress()).collect(Collectors.toList());
+ if (nonLoopback.isEmpty()) return fallback;
+
+ // Invariant: We got all addresses without exception
+
+ List<InetAddress> ipV4 = nonLoopback.stream().filter(a -> a instanceof Inet4Address).collect(Collectors.toList());
+ for (InetAddress address : ipV4)
+ if (doesResolve(address))
+ return address;
+
+ // Invariant: There are no resolving ip4 addresses
+
+ List<InetAddress> ipV6 = nonLoopback.stream().filter(a -> a instanceof Inet4Address).collect(Collectors.toList());
+ for (InetAddress address : ipV6)
+ if (doesResolve(address))
+ return address;
+
+ // Invariant: There are no resolving ip6 addresses either
+
+ if (! ipV4.isEmpty()) return ipV4.get(0);
+ return ipV6.get(0);
+ } catch (UnknownHostException e) {
+ return fallback;
+ }
+ }
+
+ /**
+ * Returns all local addresses of this host.
+ *
+ * @return an array of the addresses of this
+ * @throws UnknownHostException if we cannot access the network
+ */
+ public static InetAddress[] getAllLocal() throws UnknownHostException {
+ InetAddress[] localInetAddresses = InetAddress.getAllByName("127.0.0.1");
+ if ( ! localInetAddresses[0].isLoopbackAddress()) return localInetAddresses;
+ return getAllLocalFromNetwork().toArray(new InetAddress[0]);
+ }
+
+ /**
+ * Returns all local addresses of this host.
+ *
+ * @return a list of the addresses of this
+ * @throws UnknownHostException if we cannot access the network
+ */
+ private static List<InetAddress> getAllLocalFromNetwork() throws UnknownHostException {
+ try {
+ List<InetAddress> addresses = new ArrayList<>();
+ for (NetworkInterface networkInterface : Collections.list(NetworkInterface.getNetworkInterfaces()))
+ addresses.addAll(Collections.list(networkInterface.getInetAddresses()));
+ return addresses;
+ }
+ catch (SocketException ex) {
+ throw new UnknownHostException("127.0.0.1");
+ }
+ }
+
+ private static boolean doesResolve(InetAddress address) {
+ // The latter returns a name if resolvable to one and the host address otherwise
+ return ! address.getHostAddress().equals(address.getCanonicalHostName());
+ }
+
+}
diff --git a/vespajlib/src/test/java/com/yahoo/net/HostNameTestCase.java b/vespajlib/src/test/java/com/yahoo/net/HostNameTestCase.java
index 0534b02db60..98be9f0ef6f 100644
--- a/vespajlib/src/test/java/com/yahoo/net/HostNameTestCase.java
+++ b/vespajlib/src/test/java/com/yahoo/net/HostNameTestCase.java
@@ -9,15 +9,8 @@ import static org.junit.Assert.assertFalse;
* @author lulf
*/
public class HostNameTestCase {
-
@Test
public void testHostnameIsFound() {
- assertFalse(HostName.getHostName().isEmpty());
+ assertFalse(HostName.getLocalhost().isEmpty());
}
-
- @Test
- public void testSystemHostnameIsFound() throws Exception {
- assertFalse(HostName.getSystemHostName().isEmpty());
- }
-
}
diff --git a/vespajlib/src/test/java/com/yahoo/net/LinuxInetAddressTestCase.java b/vespajlib/src/test/java/com/yahoo/net/LinuxInetAddressTestCase.java
new file mode 100755
index 00000000000..27b85a0864c
--- /dev/null
+++ b/vespajlib/src/test/java/com/yahoo/net/LinuxInetAddressTestCase.java
@@ -0,0 +1,42 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.net;
+
+import java.net.UnknownHostException;
+import java.net.InetAddress;
+import java.net.Inet4Address;
+
+/**
+ * @author Simon Thoresen
+ */
+public class LinuxInetAddressTestCase extends junit.framework.TestCase {
+
+ @SuppressWarnings("deprecation")
+ public void testPreferIPv4() throws UnknownHostException {
+ try {
+ // This test only works if there is at least one inet address returned.
+ InetAddress[] arr = LinuxInetAddress.getAllLocal();
+ if (arr.length > 0) {
+ // System.out.println("Got " + arr.length + " addresses.");
+
+ // And it can only make sure it is preferred if there is at least one ip v4 address.
+ boolean ipv4 = false;
+ for (int i = 0; i < arr.length; ++i) {
+ // System.out.println("Address " + i + " is an instance of " + arr[i].getClass() + ".");
+ if (arr[i] instanceof Inet4Address) {
+ ipv4 = true;
+ }
+ }
+
+ // And the only thing we test is that an ip v4 address is preferred.
+ if (ipv4) {
+ InetAddress addr = LinuxInetAddress.getLocalHost();
+ assertNotNull("IPv4 is prefered", addr instanceof Inet4Address);
+ }
+ }
+ }
+ catch (java.net.UnknownHostException e) {
+ // We're on vpn or have no network
+ }
+ }
+
+}