summaryrefslogtreecommitdiffstats
path: root/vespajlib
diff options
context:
space:
mode:
authorjonmv <venstad@gmail.com>2022-04-08 19:08:33 +0200
committerjonmv <venstad@gmail.com>2022-04-08 19:08:33 +0200
commitdfbdd8f1593d16031e8d1adbda79d4d58c49164b (patch)
tree3027cfdefe8e30734bd51da3d3d5ee8488747b93 /vespajlib
parent0ee94a18e5420f7f77aec110c8ff0a67a661a7ef (diff)
Move ID part to HostName in config-provisioning
Diffstat (limited to 'vespajlib')
-rw-r--r--vespajlib/abi-spec.json4
-rw-r--r--vespajlib/src/main/java/com/yahoo/net/HostName.java60
-rw-r--r--vespajlib/src/test/java/com/yahoo/net/HostNameTest.java25
3 files changed, 2 insertions, 87 deletions
diff --git a/vespajlib/abi-spec.json b/vespajlib/abi-spec.json
index 45f7e395da6..6044666ebf8 100644
--- a/vespajlib/abi-spec.json
+++ b/vespajlib/abi-spec.json
@@ -350,13 +350,13 @@
"fields": []
},
"com.yahoo.net.HostName": {
- "superClass": "ai.vespa.http.DomainName",
+ "superClass": "java.lang.Object",
"interfaces": [],
"attributes": [
"public"
],
"methods": [
- "public static com.yahoo.net.HostName of(java.lang.String)",
+ "public void <init>()",
"public static synchronized java.lang.String getLocalhost()",
"public static void setHostNameForTestingOnly(java.lang.String)"
],
diff --git a/vespajlib/src/main/java/com/yahoo/net/HostName.java b/vespajlib/src/main/java/com/yahoo/net/HostName.java
deleted file mode 100644
index 0348197a704..00000000000
--- a/vespajlib/src/main/java/com/yahoo/net/HostName.java
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.net;
-
-import ai.vespa.http.DomainName;
-import ai.vespa.validation.PatternedStringWrapper;
-
-import java.util.Optional;
-import java.util.regex.Pattern;
-
-import static ai.vespa.validation.Validation.requireLength;
-
-/**
- * Hostnames match {@link #domainNamePattern}, and are restricted to 64 characters in length.
- *
- * This class also has utilities for getting the hostname of the system running the JVM.
- * Detection of the hostname is now done before starting any Vespa
- * programs and provided in the environment variable VESPA_HOSTNAME;
- * if that variable isn't set a default of "localhost" is always returned.
- *
- * @author arnej
- * @author jonmv
- */
-public class HostName extends DomainName {
-
- private static HostName preferredHostName = null;
-
- private HostName(String value) {
- super(requireLength(value, "hostname length", 1, 64));
- }
-
- public static HostName of(String value) {
- return new HostName(value);
- }
-
- /**
- * Return a public and fully qualified hostname for localhost that
- * resolves to an IP address on a network interface.
- *
- * @return the preferred name of localhost
- */
- public static synchronized String getLocalhost() {
- if (preferredHostName == null) {
- preferredHostName = getPreferredHostName();
- }
- return preferredHostName.value();
- }
-
- static private HostName getPreferredHostName() {
- Optional<String> vespaHostEnv = Optional.ofNullable(System.getenv("VESPA_HOSTNAME"));
- if (vespaHostEnv.isPresent() && ! vespaHostEnv.get().trim().isEmpty()) {
- return of(vespaHostEnv.get().trim());
- }
- return of("localhost");
- }
-
- public static void setHostNameForTestingOnly(String hostName) {
- preferredHostName = HostName.of(hostName);
- }
-
-}
diff --git a/vespajlib/src/test/java/com/yahoo/net/HostNameTest.java b/vespajlib/src/test/java/com/yahoo/net/HostNameTest.java
index fa756b31616..2548c3cea60 100644
--- a/vespajlib/src/test/java/com/yahoo/net/HostNameTest.java
+++ b/vespajlib/src/test/java/com/yahoo/net/HostNameTest.java
@@ -1,39 +1,14 @@
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.net;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
-/**
- * @author jonmv
- */
public class HostNameTest {
@Test
- void testNames() {
- HostName.of("name-123.0.321-eman");
- HostName.of(("." + "a".repeat(32)).repeat(2).substring(1, 65));
- HostName.of("123");
-
- assertThrows(IllegalArgumentException.class, () -> HostName.of("_"));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("-"));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("."));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("-foo"));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("foo-"));
- assertThrows(IllegalArgumentException.class, () -> HostName.of(".foo"));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("foo."));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("foo..bar"));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("foo.-.bar"));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("foo/"));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("foo%"));
- assertThrows(IllegalArgumentException.class, () -> HostName.of(("." + "a".repeat(32)).repeat(2).substring(1, 66)));
- assertThrows(IllegalArgumentException.class, () -> HostName.of("a".repeat(64)));
- }
-
- @Test
void testHostnameIsFound() {
assertFalse(HostName.getLocalhost().isEmpty());
}