diff options
6 files changed, 43 insertions, 2 deletions
diff --git a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainer.java b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainer.java index 9997b20d205..64608e3adea 100644 --- a/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainer.java +++ b/config-model/src/main/java/com/yahoo/vespa/model/container/ApplicationContainer.java @@ -41,6 +41,7 @@ public final class ApplicationContainer extends Container implements addComponent(new SimpleComponent("com.yahoo.container.jdisc.messagebus.SessionCache")); addComponent(new SimpleComponent("com.yahoo.container.jdisc.SystemInfoProvider")); addComponent(new SimpleComponent("com.yahoo.container.jdisc.ZoneInfoProvider")); + addComponent(new SimpleComponent("com.yahoo.container.jdisc.ClusterInfoProvider")); } @Override diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/ClusterInfoProvider.java b/container-disc/src/main/java/com/yahoo/container/jdisc/ClusterInfoProvider.java new file mode 100644 index 00000000000..3b40e87777d --- /dev/null +++ b/container-disc/src/main/java/com/yahoo/container/jdisc/ClusterInfoProvider.java @@ -0,0 +1,29 @@ + +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.container.jdisc; + +import ai.vespa.cloud.Cluster; +import com.yahoo.cloud.config.ClusterInfoConfig; +import com.yahoo.component.annotation.Inject; +import com.yahoo.component.AbstractComponent; +import com.yahoo.container.di.componentgraph.Provider; + +/** + * Provides information about the zone in which this container is running. + * This is available and can be injected when running in a cloud environment. + * + * @author bratseth + */ +public class ClusterInfoProvider extends AbstractComponent implements Provider<Cluster> { + + private final Cluster instance; + + @Inject + public ClusterInfoProvider(ClusterInfoConfig cfg) { + this.instance = new Cluster(cfg.clusterId(), cfg.nodeCount(), cfg.nodeIndices()); + } + + @Override + public Cluster get() { return instance; } + +} diff --git a/hosted-zone-api/abi-spec.json b/hosted-zone-api/abi-spec.json index 6a79a5aecf4..b7c2b5b4455 100644 --- a/hosted-zone-api/abi-spec.json +++ b/hosted-zone-api/abi-spec.json @@ -97,6 +97,7 @@ "public ai.vespa.cloud.Zone zone()", "public ai.vespa.cloud.Cloud cloud()", "public ai.vespa.cloud.Cluster cluster()", + "public java.lang.String clusterName()", "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 index ce278848f29..bb96423af01 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 @@ -1,7 +1,6 @@ // Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package ai.vespa.cloud; -import java.util.Collections; import java.util.List; import java.util.Objects; 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 325f62cd7f8..2ace2e7872b 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 @@ -42,9 +42,18 @@ public class SystemInfo { return cloud; } - /** Returns the cluster this is part of */ + /** + * Returns the cluster this is part of + * @deprecated This will shortly be removed as it breaks the intention of SystemInfo + * Use clusterName() as replacement for cluster().id(). + * If you need cluster size or node indices you should have Cluster injected directly. + */ + @Deprecated(forRemoval = true) public Cluster cluster() { return cluster; } + /** Returns the name of the cluster it is running in */ + public String clusterName() { return cluster.id(); } + /** Returns the node this is running on */ public Node node() { return node; } 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 d97bba51c71..c3f8624b456 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,6 +14,7 @@ import static org.junit.jupiter.api.Assertions.fail; public class SystemInfoTest { @Test + @SuppressWarnings("removal") void testSystemInfo() { ApplicationId application = new ApplicationId("tenant1", "application1", "instance1"); Zone zone = new Zone(Environment.dev, "us-west-1"); @@ -26,6 +27,7 @@ public class SystemInfoTest { assertEquals(zone, info.zone()); assertEquals(cloud, info.cloud()); assertEquals(cluster, info.cluster()); + assertEquals(cluster.id(), info.clusterName()); assertEquals(node, info.node()); } |