diff options
Diffstat (limited to 'controller-api')
6 files changed, 175 insertions, 38 deletions
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 c0bebf54803..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,57 +1,54 @@ // 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; /** - * Application + zone. + * ApplicationId x ZoneId. * * @author smorgrav * @author bratseth */ public class DeploymentId { - private final com.yahoo.config.provision.ApplicationId application; - private final ZoneId zone; + private final com.yahoo.config.provision.ApplicationId applicationId; + private final ZoneId zoneId; - public DeploymentId(com.yahoo.config.provision.ApplicationId application, ZoneId zone) { - this.application = application; - this.zone = zone; + public DeploymentId(com.yahoo.config.provision.ApplicationId applicationId, ZoneId zoneId) { + this.applicationId = applicationId; + this.zoneId = zoneId; } public com.yahoo.config.provision.ApplicationId applicationId() { - return application; + return applicationId; } - public ZoneId zone() { return zone; } + public ZoneId zoneId() { + return zoneId; + } public String dottedString() { return unCapitalize(applicationId().tenant().value()) + "." - + unCapitalize(applicationId().application().value()) + "." - + unCapitalize(zone.environment().value()) + "." - + unCapitalize(zone.region().value()) + "." - + unCapitalize(application.instance().value()); + + unCapitalize(applicationId().application().value()) + "." + + unCapitalize(zoneId.environment().value()) + "." + + unCapitalize(zoneId.region().value()) + "." + + unCapitalize(applicationId.instance().value()); } @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - DeploymentId other = (DeploymentId) o; - if ( ! this.application.equals(other.application)) return false; - // TODO: Simplify when Zone implements equals - if ( ! this.zone.environment().equals(other.zone.environment())) return false; - if ( ! this.zone.region().equals(other.zone.region())) return false; - return true; + if ( ! (o instanceof DeploymentId)) return false; + DeploymentId id = (DeploymentId) o; + return Objects.equals(applicationId, id.applicationId) && + Objects.equals(zoneId, id.zoneId); } @Override public int hashCode() { - // TODO: Simplify when Zone implements hashCode - return application.hashCode() + - 7 * zone.environment().hashCode() + - 31 * zone.region().hashCode(); + return Objects.hash(applicationId, zoneId); } @Override @@ -60,10 +57,11 @@ public class DeploymentId { } public String toUserFriendlyString() { - return application + " in " + zone; + return applicationId + " in " + zoneId; } private static String unCapitalize(String str) { return str.toLowerCase().substring(0,1) + str.substring(1); } + } 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 3318bf783d8..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,10 @@ // 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; import java.time.Duration; @@ -19,14 +18,38 @@ import java.util.Optional; */ public interface ZoneRegistry { - SystemName system(); + /** Returns whether the system of this registry contains the given zone. */ + boolean hasZone(ZoneId zoneId); + + /** Returns a list containing the id of all zones in this registry. */ List<ZoneId> zones(); - Optional<ZoneId> getZone(Environment environment, RegionName region); - List<URI> getConfigServerUris(Environment environment, RegionName region); - Optional<URI> getLogServerUri(Environment environment, RegionName region); - Optional<Duration> getDeploymentTimeToLive(Environment environment, RegionName region); + + /** Returns the default region for the given environment, if one is configured. */ Optional<RegionName> getDefaultRegion(Environment environment); - URI getMonitoringSystemUri(Environment environment, RegionName name, ApplicationId application); + + /** Returns a list with all known config servers in the given zone. + * + * @deprecated Use {@link #getConfigServerSecureUris(ZoneId)} instead (requires that client trusts Athenz CA) + */ + @Deprecated + List<URI> getConfigServerUris(ZoneId zoneId); + + /** Returns a list with all known config servers in the given zone, with a secure connection URL. */ + List<URI> getConfigServerSecureUris(ZoneId zoneId); + + /** Returns a URL with the logs for the given deployment, if logging is configured for its zone. */ + Optional<URI> getLogServerUri(DeploymentId deploymentId); + + /** Returns the time to live for deployments in the given zone, or empty if this is infinite. */ + Optional<Duration> getDeploymentTimeToLive(ZoneId zoneId); + + /** Returns a URL pointing at monitoring resources for the given deployment. */ + URI getMonitoringSystemUri(DeploymentId deploymentId); + + /** Returns the URL of the dashboard for the system of this registry. */ URI getDashboardUri(); + /** Returns the system of this registry. */ + SystemName system(); + } 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<ZoneId> 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; |