diff options
Diffstat (limited to 'hosted-zone-api')
6 files changed, 121 insertions, 4 deletions
diff --git a/hosted-zone-api/abi-spec.json b/hosted-zone-api/abi-spec.json index e5d1db476c2..e3b68d09135 100644 --- a/hosted-zone-api/abi-spec.json +++ b/hosted-zone-api/abi-spec.json @@ -1,4 +1,16 @@ { + "ai.vespa.cloud.Cluster": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ + "public" + ], + "methods": [ + "public void <init>(int)", + "public int size()" + ], + "fields": [] + }, "ai.vespa.cloud.Environment": { "superClass": "java.lang.Enum", "interfaces": [], @@ -19,6 +31,20 @@ "public static final enum ai.vespa.cloud.Environment prod" ] }, + "ai.vespa.cloud.Node": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ + "public" + ], + "methods": [ + "public void <init>(int)", + "public int index()", + "public boolean equals(java.lang.Object)", + "public int hashCode()" + ], + "fields": [] + }, "ai.vespa.cloud.SystemInfo": { "superClass": "java.lang.Object", "interfaces": [], @@ -26,8 +52,10 @@ "public" ], "methods": [ - "public void <init>(ai.vespa.cloud.Zone)", - "public ai.vespa.cloud.Zone zone()" + "public void <init>(ai.vespa.cloud.Zone, ai.vespa.cloud.Cluster, ai.vespa.cloud.Node)", + "public ai.vespa.cloud.Zone zone()", + "public ai.vespa.cloud.Cluster cluster()", + "public ai.vespa.cloud.Node node()" ], "fields": [] }, diff --git a/hosted-zone-api/src/main/java/ai/vespa/cloud/Cluster.java b/hosted-zone-api/src/main/java/ai/vespa/cloud/Cluster.java new file mode 100644 index 00000000000..6e064b09d7a --- /dev/null +++ b/hosted-zone-api/src/main/java/ai/vespa/cloud/Cluster.java @@ -0,0 +1,19 @@ +package ai.vespa.cloud; + +/** + * The properties of a cluster of nodes. + * + * @author gjoranv + */ +public class Cluster { + + private final int size; + + public Cluster(int size) { + this.size = size; + } + + /** Returns the number of nodes in this cluster. */ + public int size() { return size; } + +} diff --git a/hosted-zone-api/src/main/java/ai/vespa/cloud/Node.java b/hosted-zone-api/src/main/java/ai/vespa/cloud/Node.java new file mode 100644 index 00000000000..19ef2757b6c --- /dev/null +++ b/hosted-zone-api/src/main/java/ai/vespa/cloud/Node.java @@ -0,0 +1,34 @@ +package ai.vespa.cloud; + +import java.util.Objects; + +/** + * A node that is part of a cluster of e.g. Jdisc containers. + * + * @author gjoranv + */ +public class Node { + + private final int index; + + public Node(int index) { + this.index = index; + } + + /** Returns the unique index for this node in the cluster. + * Indices are non-negative, but not necessarily contiguous or starting from zero. */ + public int index() { return index; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Node node = (Node) o; + return index == node.index; + } + + @Override + public int hashCode() { + return Objects.hash(index); + } +} diff --git a/hosted-zone-api/src/main/java/ai/vespa/cloud/SystemInfo.java b/hosted-zone-api/src/main/java/ai/vespa/cloud/SystemInfo.java index 0ac93861275..c9500df4d7f 100644 --- a/hosted-zone-api/src/main/java/ai/vespa/cloud/SystemInfo.java +++ b/hosted-zone-api/src/main/java/ai/vespa/cloud/SystemInfo.java @@ -1,6 +1,8 @@ // 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; + /** * Provides information about the system in which this container is running. * This is available and can be injected when running in a cloud environment. @@ -10,12 +12,25 @@ package ai.vespa.cloud; public class SystemInfo { private final Zone zone; + private final Cluster cluster; + private final Node node; - public SystemInfo(Zone zone) { + public SystemInfo(Zone zone, Cluster cluster, Node node) { + Objects.requireNonNull(zone, "Zone cannot be null!"); + Objects.requireNonNull(cluster, "Cluster cannot be null!"); + Objects.requireNonNull(node, "Node cannot be null!"); this.zone = zone; + this.cluster = cluster; + this.node = node; } /** Returns the zone this is running in */ public Zone zone() { return zone; } + /** Returns the cluster this is part of */ + public Cluster cluster() { return cluster; } + + /** Returns the node this is running on */ + public Node node() { return node; } + } diff --git a/hosted-zone-api/src/main/java/ai/vespa/cloud/Zone.java b/hosted-zone-api/src/main/java/ai/vespa/cloud/Zone.java index 48293aa7908..a6b69d12608 100644 --- a/hosted-zone-api/src/main/java/ai/vespa/cloud/Zone.java +++ b/hosted-zone-api/src/main/java/ai/vespa/cloud/Zone.java @@ -16,6 +16,8 @@ public class Zone { private final String region; public Zone(Environment environment, String region) { + Objects.requireNonNull(environment, "Environment cannot be null!"); + Objects.requireNonNull(region, "Region cannot be null!"); this.environment = environment; this.region = region; } diff --git a/hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java b/hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java index 6bc8b395e00..6bdb38eb735 100644 --- a/hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java +++ b/hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java @@ -14,8 +14,13 @@ public class SystemInfoTest { @Test public void testSystemInfo() { Zone zone = new Zone(Environment.dev, "us-west-1"); - SystemInfo info = new SystemInfo(zone); + Cluster cluster = new Cluster(1); + Node node = new Node(0); + + SystemInfo info = new SystemInfo(zone, cluster, node); assertEquals(zone, info.zone()); + assertEquals(cluster, info.cluster()); + assertEquals(node, info.node()); } @Test @@ -46,4 +51,18 @@ public class SystemInfoTest { } } + @Test + public void testCluster() { + int size = 1; + Cluster cluster = new Cluster(size); + assertEquals(size, cluster.size()); + } + + @Test + public void testNode() { + int index = 0; + Node node = new Node(index); + assertEquals(index, node.index()); + } + } |