From 296e91de1079912b77fc3a18587b45ce07afb1c6 Mon Sep 17 00:00:00 2001 From: Jon Bratseth Date: Tue, 9 Nov 2021 22:53:14 +0100 Subject: Add application to systeminfo --- .../main/java/ai/vespa/cloud/ApplicationId.java | 46 ++++++++++++++++++++++ .../src/main/java/ai/vespa/cloud/SystemInfo.java | 20 +++++++--- .../test/java/ai/vespa/cloud/SystemInfoTest.java | 4 +- 3 files changed, 63 insertions(+), 7 deletions(-) create mode 100644 hosted-zone-api/src/main/java/ai/vespa/cloud/ApplicationId.java (limited to 'hosted-zone-api') diff --git a/hosted-zone-api/src/main/java/ai/vespa/cloud/ApplicationId.java b/hosted-zone-api/src/main/java/ai/vespa/cloud/ApplicationId.java new file mode 100644 index 00000000000..46780d17a13 --- /dev/null +++ b/hosted-zone-api/src/main/java/ai/vespa/cloud/ApplicationId.java @@ -0,0 +1,46 @@ +// 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; + +/** + * The application id this is running as. + * This is a combination of a tenant, application, and instance name. + * + * @author bratseth + */ +public class ApplicationId { + + private final String tenant; + private final String application; + private final String instance; + + public ApplicationId(String tenant, String application, String instance) { + this.tenant = tenant; + this.application = application; + this.instance = instance; + } + + public String tenant() { return tenant; } + public String application() { return application; } + public String instance() { return instance; } + + @Override + public boolean equals(Object o) { + if (o == this) return true; + if ( ! (o instanceof ApplicationId)) return false; + ApplicationId other = (ApplicationId)o; + if ( ! other.tenant.equals(this.tenant)) return false; + if ( ! other.application.equals(this.application)) return false; + if ( ! other.instance.equals(this.instance)) return false; + return true; + } + + @Override + public int hashCode() { return Objects.hash(tenant, application, instance); } + + /** Returns the string tenant.application.instance */ + @Override + public String toString() { return tenant + "." + application + "." + instance; } + +} 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 15b06d40948..3789c49fe82 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 @@ -11,19 +11,27 @@ import java.util.Objects; */ public class SystemInfo { + private final ApplicationId application; private final Zone zone; private final Cluster cluster; private final Node node; + public SystemInfo(ApplicationId application, Zone zone, Cluster cluster, Node node) { + this.application = Objects.requireNonNull(application, "Application cannot be null"); + this.zone = Objects.requireNonNull(zone, "Zone cannot be null"); + this.cluster = Objects.requireNonNull(cluster, "Cluster cannot be null"); + this.node = Objects.requireNonNull(node, "Node cannot be null"); + } + + /** @deprecated pass an application id */ + @Deprecated // Remove on Vespa 8 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; + this(new ApplicationId("default", "default", "default"), zone, cluster, node); } + /** Returns the application this is running as a part of */ + public ApplicationId application() { return application; } + /** Returns the zone this is running in */ public Zone zone() { return zone; } 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 7f6921ab114..c14955d6614 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 @@ -15,11 +15,13 @@ public class SystemInfoTest { @Test public void testSystemInfo() { + ApplicationId application = new ApplicationId("tenant1", "application1", "instance1"); Zone zone = new Zone(Environment.dev, "us-west-1"); Cluster cluster = new Cluster(1, List.of()); Node node = new Node(0); - SystemInfo info = new SystemInfo(zone, cluster, node); + SystemInfo info = new SystemInfo(application, zone, cluster, node); + assertEquals(application, info.application()); assertEquals(zone, info.zone()); assertEquals(cluster, info.cluster()); assertEquals(node, info.node()); -- cgit v1.2.3