summaryrefslogtreecommitdiffstats
path: root/hosted-zone-api
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2022-10-07 12:26:31 +0200
committerJon Bratseth <bratseth@gmail.com>2022-10-07 12:26:31 +0200
commit2d4a98b1b3e1d4c99a805e16118b53a5a20c9378 (patch)
treeccf3647d535e6e4ba5d1b181772c83fc9f05a3a3 /hosted-zone-api
parent67afeb4c00ba1530a40bfcf1d7a863e276331871 (diff)
Add id() to Cluster
Diffstat (limited to 'hosted-zone-api')
-rw-r--r--hosted-zone-api/src/main/java/ai/vespa/cloud/Cluster.java25
-rw-r--r--hosted-zone-api/src/test/java/ai/vespa/cloud/SystemInfoTest.java6
2 files changed, 22 insertions, 9 deletions
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
index 218545383e6..ce278848f29 100644
--- a/hosted-zone-api/src/main/java/ai/vespa/cloud/Cluster.java
+++ b/hosted-zone-api/src/main/java/ai/vespa/cloud/Cluster.java
@@ -12,15 +12,25 @@ import java.util.Objects;
*/
public class Cluster {
+ private final String id;
private final int size;
private final List<Integer> indices;
+ // TODO: Remove on Vespa 9
+ @Deprecated(forRemoval = true)
public Cluster(int size, List<Integer> indices) {
- Objects.requireNonNull(indices, "Indices cannot be null!");
+ this("default", size, indices);
+ }
+
+ public Cluster(String id, int size, List<Integer> indices) {
+ this.id = Objects.requireNonNull(id);
this.size = size;
- this.indices = Collections.unmodifiableList(indices);
+ this.indices = List.copyOf(Objects.requireNonNull(indices));
}
+ /** Returns the id of this cluster set in services.xml */
+ public String id() { return id; }
+
/** Returns the number of nodes in this cluster. */
public int size() { return size; }
@@ -32,15 +42,16 @@ public class Cluster {
@Override
public boolean equals(Object o) {
if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- Cluster cluster = (Cluster) o;
- return size == cluster.size &&
- indices.equals(cluster.indices);
+ if ( ! (o instanceof Cluster other)) return false;
+ if ( ! this.id.equals(other.id)) return false;
+ if ( this.size != other.size) return false;
+ if ( ! this.indices.equals(other.indices)) return false;
+ return true;
}
@Override
public int hashCode() {
- return Objects.hash(size, indices);
+ return Objects.hash(id, size, indices);
}
}
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 2bae9f0c9e2..d97bba51c71 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
@@ -18,7 +18,7 @@ public class SystemInfoTest {
ApplicationId application = new ApplicationId("tenant1", "application1", "instance1");
Zone zone = new Zone(Environment.dev, "us-west-1");
Cloud cloud = new Cloud("aws");
- Cluster cluster = new Cluster(1, List.of());
+ Cluster cluster = new Cluster("clusterId", 1, List.of());
Node node = new Node(0);
SystemInfo info = new SystemInfo(application, zone, cloud, cluster, node);
@@ -59,9 +59,11 @@ public class SystemInfoTest {
@Test
void testCluster() {
+ String id = "clusterId";
int size = 1;
var indices = List.of(1);
- Cluster cluster = new Cluster(size, indices);
+ Cluster cluster = new Cluster("clusterId", size, indices);
+ assertEquals(id, cluster.id());
assertEquals(size, cluster.size());
assertEquals(indices, cluster.indices());
}