diff options
4 files changed, 70 insertions, 0 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 d51427abd90..9ad257fad04 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 @@ -36,6 +36,7 @@ public final class ApplicationContainer extends Container implements addComponent(new SimpleComponent("com.yahoo.container.jdisc.messagebus.NetworkMultiplexerProvider")); 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")); } @Override diff --git a/container-disc/src/main/java/com/yahoo/container/jdisc/ZoneInfoProvider.java b/container-disc/src/main/java/com/yahoo/container/jdisc/ZoneInfoProvider.java new file mode 100644 index 00000000000..30a4c740ff0 --- /dev/null +++ b/container-disc/src/main/java/com/yahoo/container/jdisc/ZoneInfoProvider.java @@ -0,0 +1,30 @@ +// 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.Environment; +import ai.vespa.cloud.Zone; +import ai.vespa.cloud.ZoneInfo; +import com.google.inject.Inject; +import com.yahoo.cloud.config.ConfigserverConfig; +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 ZoneInfoProvider extends AbstractComponent implements Provider<ZoneInfo> { + + private final ZoneInfo instance; + + @Inject + public ZoneInfoProvider(ConfigserverConfig csConfig) { + this.instance = new ZoneInfo(new Zone(Environment.valueOf(csConfig.environment()), csConfig.region())); + } + + @Override + public ZoneInfo get() { return instance; } + +} diff --git a/hosted-zone-api/abi-spec.json b/hosted-zone-api/abi-spec.json index 4195fd5f10c..6a6da57a2a1 100644 --- a/hosted-zone-api/abi-spec.json +++ b/hosted-zone-api/abi-spec.json @@ -78,5 +78,17 @@ "public static ai.vespa.cloud.Zone from(java.lang.String)" ], "fields": [] + }, + "ai.vespa.cloud.ZoneInfo": { + "superClass": "java.lang.Object", + "interfaces": [], + "attributes": [ + "public" + ], + "methods": [ + "public void <init>(ai.vespa.cloud.Zone)", + "public ai.vespa.cloud.Zone zone()" + ], + "fields": [] } }
\ No newline at end of file diff --git a/hosted-zone-api/src/main/java/ai/vespa/cloud/ZoneInfo.java b/hosted-zone-api/src/main/java/ai/vespa/cloud/ZoneInfo.java new file mode 100644 index 00000000000..d9af2421ab9 --- /dev/null +++ b/hosted-zone-api/src/main/java/ai/vespa/cloud/ZoneInfo.java @@ -0,0 +1,27 @@ +// 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.Objects; + +/** + * Provides information about the zone in which this container is running. + * This is available and can be injected when running in a cloud environment. + * If you don't need any other information than the zone this should be preferred + * to SystemInfo as it will never change at runtime and therefore does not + * cause unnecessary reconstruction. + * + * @author bratseth + */ +public class ZoneInfo { + + private final Zone zone; + + public ZoneInfo(Zone zone) { + Objects.requireNonNull(zone, "Zone cannot be null!"); + this.zone = zone; + } + + /** Returns the zone this is running in */ + public Zone zone() { return zone; } + +} |