From dfbdd8f1593d16031e8d1adbda79d4d58c49164b Mon Sep 17 00:00:00 2001 From: jonmv Date: Fri, 8 Apr 2022 19:08:33 +0200 Subject: Move ID part to HostName in config-provisioning --- vespajlib/abi-spec.json | 4 +- .../src/main/java/com/yahoo/net/HostName.java | 60 ---------------------- .../src/test/java/com/yahoo/net/HostNameTest.java | 25 --------- 3 files changed, 2 insertions(+), 87 deletions(-) delete mode 100644 vespajlib/src/main/java/com/yahoo/net/HostName.java (limited to 'vespajlib') 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 ()", "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 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,38 +1,13 @@ // 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()); -- cgit v1.2.3