summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@oath.com>2020-03-12 16:01:56 +0100
committerGitHub <noreply@github.com>2020-03-12 16:01:56 +0100
commit55125063dd1b73a378dc8a03bb91d13be93834c8 (patch)
tree7153fc214982d1e2672676e654e2e4416ae58a82
parentb771a3631ebf6658e940b1eb96df310f60e2266f (diff)
parent2b67e1f8234dc0914c43d56e76dadc2b5ae3e9dc (diff)
Merge pull request #12549 from vespa-engine/bratseth/system-info
Bratseth/system info
-rw-r--r--container-core/abi-spec.json50
-rw-r--r--container-core/src/main/java/ai/vespa/cloud/Environment.java13
-rw-r--r--container-core/src/main/java/ai/vespa/cloud/SystemInfo.java31
-rw-r--r--container-core/src/main/java/ai/vespa/cloud/Zone.java61
-rw-r--r--container-core/src/main/java/ai/vespa/cloud/package-info.java10
-rw-r--r--container-core/src/main/java/com/yahoo/container/Server.java45
-rw-r--r--container-core/src/test/java/ai/vespa/cloud/SystemInfoTest.java49
7 files changed, 214 insertions, 45 deletions
diff --git a/container-core/abi-spec.json b/container-core/abi-spec.json
index fe8fb91d71f..f0d7f4068be 100644
--- a/container-core/abi-spec.json
+++ b/container-core/abi-spec.json
@@ -871,5 +871,55 @@
"public bridge synthetic java.lang.Object clone()"
],
"fields": []
+ },
+ "ai.vespa.cloud.Environment": {
+ "superClass": "java.lang.Enum",
+ "interfaces": [],
+ "attributes": [
+ "public",
+ "final",
+ "enum"
+ ],
+ "methods": [
+ "public static ai.vespa.cloud.Environment[] values()",
+ "public static ai.vespa.cloud.Environment valueOf(java.lang.String)"
+ ],
+ "fields": [
+ "public static final enum ai.vespa.cloud.Environment dev",
+ "public static final enum ai.vespa.cloud.Environment perf",
+ "public static final enum ai.vespa.cloud.Environment test",
+ "public static final enum ai.vespa.cloud.Environment staging",
+ "public static final enum ai.vespa.cloud.Environment prod"
+ ]
+ },
+ "ai.vespa.cloud.SystemInfo": {
+ "superClass": "java.lang.Object",
+ "interfaces": [],
+ "attributes": [
+ "public"
+ ],
+ "methods": [
+ "public void <init>(com.yahoo.cloud.config.ConfigserverConfig)",
+ "public void <init>(ai.vespa.cloud.Zone)",
+ "public ai.vespa.cloud.Zone zone()"
+ ],
+ "fields": []
+ },
+ "ai.vespa.cloud.Zone": {
+ "superClass": "java.lang.Object",
+ "interfaces": [],
+ "attributes": [
+ "public"
+ ],
+ "methods": [
+ "public void <init>(ai.vespa.cloud.Environment, java.lang.String)",
+ "public ai.vespa.cloud.Environment environment()",
+ "public java.lang.String region()",
+ "public java.lang.String toString()",
+ "public int hashCode()",
+ "public boolean equals(java.lang.Object)",
+ "public static ai.vespa.cloud.Zone from(java.lang.String)"
+ ],
+ "fields": []
}
} \ No newline at end of file
diff --git a/container-core/src/main/java/ai/vespa/cloud/Environment.java b/container-core/src/main/java/ai/vespa/cloud/Environment.java
new file mode 100644
index 00000000000..8f1d9fc962a
--- /dev/null
+++ b/container-core/src/main/java/ai/vespa/cloud/Environment.java
@@ -0,0 +1,13 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.cloud;
+
+/**
+ * The environments of a Vespa cloud instance
+ *
+ * @author bratseth
+ */
+public enum Environment {
+
+ dev, perf, test, staging, prod
+
+}
diff --git a/container-core/src/main/java/ai/vespa/cloud/SystemInfo.java b/container-core/src/main/java/ai/vespa/cloud/SystemInfo.java
new file mode 100644
index 00000000000..0524ae072cd
--- /dev/null
+++ b/container-core/src/main/java/ai/vespa/cloud/SystemInfo.java
@@ -0,0 +1,31 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.cloud;
+
+import com.google.inject.Inject;
+import com.yahoo.cloud.config.ConfigserverConfig;
+
+/**
+ * Provides information about the system in which this container is running.
+ * This is available and can be injected when running in a cloud environment.
+ *
+ * @author bratseth
+ */
+public class SystemInfo {
+
+ private final Zone zone;
+
+ /** Do not use */
+ @Inject
+ public SystemInfo(ConfigserverConfig config) {
+ this.zone = new Zone(Environment.valueOf(config.environment()), config.region());
+ }
+
+ /** Create an instance for testing */
+ public SystemInfo(Zone zone) {
+ this.zone = zone;
+ }
+
+ /** Returns the zone this is running in */
+ public Zone zone() { return zone; }
+
+}
diff --git a/container-core/src/main/java/ai/vespa/cloud/Zone.java b/container-core/src/main/java/ai/vespa/cloud/Zone.java
new file mode 100644
index 00000000000..48293aa7908
--- /dev/null
+++ b/container-core/src/main/java/ai/vespa/cloud/Zone.java
@@ -0,0 +1,61 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.cloud;
+
+import java.util.Objects;
+
+/**
+ * The zone in which a cloud deployment may be running.
+ * A zone is a combination of an environment and a region.
+ *
+ * @author bratseth
+ */
+public class Zone {
+
+ private final Environment environment;
+
+ private final String region;
+
+ public Zone(Environment environment, String region) {
+ this.environment = environment;
+ this.region = region;
+ }
+
+ public Environment environment() { return environment; }
+ public String region() { return region; }
+
+ /** Returns the string environment.region */
+ @Override
+ public String toString() { return environment + "." + region; }
+
+ @Override
+ public int hashCode() { return Objects.hash(environment, region); }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if ( ! (o instanceof Zone)) return false;
+ Zone other = (Zone)o;
+ return this.environment.equals(other.environment) && this.region.equals(other.region);
+ }
+
+ /**
+ * Creates a zone from a string on the form environment.region
+ *
+ * @throws IllegalArgumentException if the given string is not a valid zone
+ */
+ public static Zone from(String zoneString) {
+ String[] parts = zoneString.split("\\.");
+ if (parts.length != 2)
+ throw new IllegalArgumentException("A zone string must be on the form [environment].[region], but was '" + zoneString + "'");
+
+ Environment environment;
+ try {
+ environment = Environment.valueOf(parts[0]);
+ }
+ catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid zone '" + zoneString + "': No environment named '" + parts[0] + "'");
+ }
+ return new Zone(environment, parts[1]);
+ }
+
+}
diff --git a/container-core/src/main/java/ai/vespa/cloud/package-info.java b/container-core/src/main/java/ai/vespa/cloud/package-info.java
new file mode 100644
index 00000000000..259a2bda258
--- /dev/null
+++ b/container-core/src/main/java/ai/vespa/cloud/package-info.java
@@ -0,0 +1,10 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+/**
+ * Public API to the Vespa cloud, available when this container runs in a cloud.
+ */
+@ExportPackage
+@PublicApi
+package ai.vespa.cloud;
+
+import com.yahoo.api.annotations.PublicApi;
+import com.yahoo.osgi.annotation.ExportPackage;
diff --git a/container-core/src/main/java/com/yahoo/container/Server.java b/container-core/src/main/java/com/yahoo/container/Server.java
deleted file mode 100644
index a4dec6de5a2..00000000000
--- a/container-core/src/main/java/com/yahoo/container/Server.java
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-package com.yahoo.container;
-
-import com.yahoo.config.subscription.ConfigSubscriber;
-import com.yahoo.container.QrConfig.Rpc;
-
-/**
- * The http server singleton managing listeners for various ports,
- * and the threads used to respond to requests on the ports
- *
- * @author bratseth
- * @deprecated
- */
-@SuppressWarnings("deprecation")
-@Deprecated // TODO: Remove this when the last usage og getServerDiscriminator is removed
-public class Server {
-
- //TODO: Make this final again.
- private static final Server instance = new Server();
-
- /** A short string which is different for all the qrserver instances on a given node. */
- private String localServerDiscriminator = "qrserver.0";
-
- private Server() { }
-
- public static Server get() {
- return instance;
- }
-
- public void initialize(QrConfig config) {
- localServerDiscriminator = config.discriminator();
- }
-
- /**
- * A string unique for this QRS on this server.
- *
- * @return a server specific string
- * @deprecated do not use
- */
- @Deprecated
- public String getServerDiscriminator() {
- return localServerDiscriminator;
- }
-
-}
diff --git a/container-core/src/test/java/ai/vespa/cloud/SystemInfoTest.java b/container-core/src/test/java/ai/vespa/cloud/SystemInfoTest.java
new file mode 100644
index 00000000000..6bc8b395e00
--- /dev/null
+++ b/container-core/src/test/java/ai/vespa/cloud/SystemInfoTest.java
@@ -0,0 +1,49 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package ai.vespa.cloud;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * @author bratseth
+ */
+public class SystemInfoTest {
+
+ @Test
+ public void testSystemInfo() {
+ Zone zone = new Zone(Environment.dev, "us-west-1");
+ SystemInfo info = new SystemInfo(zone);
+ assertEquals(zone, info.zone());
+ }
+
+ @Test
+ public void testZone() {
+ Zone zone = Zone.from("dev.us-west-1");
+ zone = Zone.from(zone.toString());
+ assertEquals(Environment.dev, zone.environment());
+ assertEquals("us-west-1", zone.region());
+ Zone sameZone = Zone.from("dev.us-west-1");
+ assertEquals(sameZone.hashCode(), zone.hashCode());
+ assertEquals(sameZone, zone);
+
+ try {
+ Zone.from("invalid");
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("A zone string must be on the form [environment].[region], but was 'invalid'",
+ e.getMessage());
+ }
+
+ try {
+ Zone.from("invalid.us-west-1");
+ fail("Expected exception");
+ }
+ catch (IllegalArgumentException e) {
+ assertEquals("Invalid zone 'invalid.us-west-1': No environment named 'invalid'", e.getMessage());
+ }
+ }
+
+}