From c403f41f013ca98726b4c34a1be1c6ec5924ec7f Mon Sep 17 00:00:00 2001 From: Jon Marius Venstad Date: Thu, 14 Dec 2017 09:23:23 +0100 Subject: Moved ZoneId to controller-api and added Zones --- .../controller/api/identifiers/DeploymentId.java | 2 +- .../controller/api/integration/MetricsService.java | 2 +- .../controller/api/integration/zone/ZoneId.java | 73 ++++++++++++++++++++++ .../api/integration/zone/ZoneRegistry.java | 4 +- .../controller/api/integration/zone/Zones.java | 45 +++++++++++++ .../controller/api/identifiers/IdentifierTest.java | 4 +- 6 files changed, 122 insertions(+), 8 deletions(-) create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java create mode 100644 controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/Zones.java (limited to 'controller-api/src') diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/DeploymentId.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/DeploymentId.java index f1c584c7a3c..04dd91670c1 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/DeploymentId.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/identifiers/DeploymentId.java @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.identifiers; -import com.yahoo.config.provision.ZoneId; +import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId; import java.util.Objects; diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java index d3e1b881bbd..20e9710f092 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/MetricsService.java @@ -2,7 +2,7 @@ package com.yahoo.vespa.hosted.controller.api.integration; import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.ZoneId; +import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId; import java.util.Map; diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java new file mode 100644 index 00000000000..818f57ec44d --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneId.java @@ -0,0 +1,73 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.controller.api.integration.zone; + +import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.RegionName; + +import java.util.Objects; + +/** + * Unique identifier for a Zone; use when referencing them. + * + * Serialised form is 'environment.region'. + * + * @author jvenstad + */ +public class ZoneId { + // TODO: Replace usages of zone + region with usages of this. + + private final Environment environment; + private final RegionName region; + + private ZoneId(Environment environment, RegionName region) { + this.environment = Objects.requireNonNull(environment); + this.region = Objects.requireNonNull(region); + } + + public static ZoneId from(Environment environment, RegionName region) { + return new ZoneId(environment, region); + } + + public static ZoneId from(String environment, String region) { + return from(Environment.from(environment), RegionName.from(region)); + } + /** Create from a serialised ZoneId. Inverse of {@code ZoneId.value()}. */ + public static ZoneId from(String value) { + String[] parts = value.split("\\."); + return from(parts[0], parts[1]); + } + + public Environment environment() { + return environment; + } + + public RegionName region() { + return region; + } + + /** Returns the serialised value of this. Inverse of {@code ZoneId.from(String value)}. */ + public String value() { + return environment + "." + region; + } + + @Override + public String toString() { + return "zone " + value(); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if ( ! (o instanceof ZoneId)) return false; + ZoneId id = (ZoneId) o; + return environment == id.environment && + Objects.equals(region, id.region); + } + + @Override + public int hashCode() { + return Objects.hash(environment, region); + } + +} + diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java index af7c464b8d7..18212001992 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/ZoneRegistry.java @@ -1,11 +1,9 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.integration.zone; -import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Environment; import com.yahoo.config.provision.RegionName; import com.yahoo.config.provision.SystemName; -import com.yahoo.config.provision.ZoneId; import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId; import java.net.URI; @@ -39,7 +37,7 @@ public interface ZoneRegistry { /** Returns a list with all known config servers in the given zone, with a secure connection URL. */ List getConfigServerSecureUris(ZoneId zoneId); - /** Returns a URL with the logs for the given deployment, if loggin is configured for its zone. */ + /** Returns a URL with the logs for the given deployment, if logging is configured for its zone. */ Optional getLogServerUri(DeploymentId deploymentId); /** Returns the time to live for deployments in the given zone, or empty if this is infinite. */ diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/Zones.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/Zones.java new file mode 100644 index 00000000000..74e2d43a308 --- /dev/null +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/zone/Zones.java @@ -0,0 +1,45 @@ +package com.yahoo.vespa.hosted.controller.api.integration.zone; + +import com.yahoo.config.provision.Environment; +import com.yahoo.config.provision.RegionName; + +/** + * A ZoneId list which can be filtered in various ways; elements can be accessed after at least one filter. + * + * @author jvenstad + */ +public interface Zones { + + /** Negates the next filter. */ + Zones not(); + + /** All zones from the initial pool. */ + Zones.List all(); + + /** Zones where which are managed by the controller. */ + Zones.List controllerManaged(); + + // TODO: Move to implementation in hosted? + /** Zones where auto provisioning of nodes is possible. */ + Zones.List autoProvisioned(); + + // TODO: Move to implementation in hosted? + /** Zones where the nodes should be kept track of in an inventory. */ + Zones.List inventoried(); + + /** Zones in the given environment. */ + Zones.List in(Environment environment); + + /** Zones in the given region. */ + Zones.List in(RegionName region); + + + /** Wraps access to the zones; this forces the user to consider which zones to access. */ + interface List extends Zones { + + /** Returns the id of all zones in this list as — you guessed it — a list. */ + java.util.List ids(); + + } + +} diff --git a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java index aa3d1be879e..0ba607a235b 100644 --- a/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java +++ b/controller-api/src/test/java/com/yahoo/vespa/hosted/controller/api/identifiers/IdentifierTest.java @@ -1,9 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.api.identifiers; -import com.yahoo.config.provision.Environment; -import com.yahoo.config.provision.RegionName; -import com.yahoo.config.provision.ZoneId; +import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneId; import org.junit.Test; import static org.junit.Assert.assertEquals; -- cgit v1.2.3