Skip to content

Commit

Permalink
Merge pull request #24355 from vespa-engine/bratseth/cluster-id
Browse files Browse the repository at this point in the history
Add id() to Cluster
  • Loading branch information
bratseth authored Oct 8, 2022
2 parents 36bc9cc + 7b0ddd4 commit 14e1b2f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public SystemInfoProvider(ConfigserverConfig csConfig,
applicationIdConfig.instance()),
new Zone(Environment.valueOf(csConfig.environment()), csConfig.region()),
new Cloud(csConfig.cloud()),
new Cluster(ciConfig.nodeCount(), ciConfig.nodeIndices()),
new Cluster(ciConfig.clusterId(), ciConfig.nodeCount(), ciConfig.nodeIndices()),
new Node(qrConfig.nodeIndex()));
}

Expand Down
2 changes: 2 additions & 0 deletions hosted-zone-api/abi-spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
],
"methods": [
"public void <init>(int, java.util.List)",
"public void <init>(java.lang.String, int, java.util.List)",
"public java.lang.String id()",
"public int size()",
"public java.util.List indices()",
"public boolean equals(java.lang.Object)",
Expand Down
25 changes: 18 additions & 7 deletions hosted-zone-api/src/main/java/ai/vespa/cloud/Cluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
*/
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; }

Expand All @@ -32,15 +42,16 @@ public List<Integer> indices() {
@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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ void testSystemInfo() {
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);
Expand Down Expand Up @@ -59,9 +59,11 @@ void testZone() {

@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());
}
Expand Down

0 comments on commit 14e1b2f

Please sign in to comment.