diff options
author | Martin Polden <mpolden@mpolden.no> | 2021-03-23 15:01:13 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2021-03-23 15:07:52 +0100 |
commit | cecf532fed31d60473c0241342502c9aefec5466 (patch) | |
tree | 69daac0cf2964784d3eb4fcb907bc6bb84f534fd | |
parent | f711bc2b7effd55589652e4a572b1fbd99579d06 (diff) |
Expose system as zone through ZoneRegistry
5 files changed, 27 insertions, 5 deletions
diff --git a/config-provisioning/src/main/java/com/yahoo/config/provision/zone/ZoneApi.java b/config-provisioning/src/main/java/com/yahoo/config/provision/zone/ZoneApi.java index 08f9b81fec7..45d6bfbe370 100644 --- a/config-provisioning/src/main/java/com/yahoo/config/provision/zone/ZoneApi.java +++ b/config-provisioning/src/main/java/com/yahoo/config/provision/zone/ZoneApi.java @@ -10,14 +10,26 @@ import com.yahoo.config.provision.SystemName; * @author hakonhall */ public interface ZoneApi { + SystemName getSystemName(); ZoneId getId(); + + /** + * Returns the virtual ID of this zone. For ordinary zones this is the same as {@link ZoneApi#getId()}, for a + * system represented as a zone this is a fixed ID that is independent of the actual zone ID. + */ + default ZoneId getVirtualId() { + return getId(); + } + default Environment getEnvironment() { return getId().environment(); } + default RegionName getRegionName() { return getId().region(); } CloudName getCloudName(); /** Returns the region name within the cloud, e.g. 'us-east-1' in AWS */ String getCloudNativeRegionName(); + } 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 b9ee696431b..3e5606ac278 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 @@ -10,6 +10,7 @@ import com.yahoo.config.provision.RegionName; import com.yahoo.config.provision.SystemName; import com.yahoo.config.provision.zone.RoutingMethod; import com.yahoo.config.provision.zone.UpgradePolicy; +import com.yahoo.config.provision.zone.ZoneApi; import com.yahoo.config.provision.zone.ZoneFilter; import com.yahoo.config.provision.zone.ZoneId; import com.yahoo.vespa.athenz.api.AthenzIdentity; @@ -55,6 +56,9 @@ public interface ZoneRegistry { /** Returns the system of this registry */ SystemName system(); + /** Returns the system of this registry as a zone */ + ZoneApi systemZone(); + /** Return the configserver's Athenz service identity */ AthenzIdentity getConfigServerHttpsIdentity(ZoneId zoneId); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/InfrastructureUpgrader.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/InfrastructureUpgrader.java index 7952355d5fb..f61ae5ec077 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/InfrastructureUpgrader.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/InfrastructureUpgrader.java @@ -101,7 +101,7 @@ public abstract class InfrastructureUpgrader<VERSION> extends ControllerMaintain try { return controller().serviceRegistry().configServer() .nodeRepository() - .list(zone.getId(), application.id()) + .list(zone.getVirtualId(), application.id()) .stream() .filter(node -> expectUpgradeOf(node, application, zone)) .map(versionField) diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/configserver/ConfigServerApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/configserver/ConfigServerApiHandler.java index 1bb3b1c5de8..8b5280a0e8c 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/configserver/ConfigServerApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/configserver/ConfigServerApiHandler.java @@ -31,17 +31,18 @@ import java.util.stream.Stream; @SuppressWarnings("unused") public class ConfigServerApiHandler extends AuditLoggingRequestHandler { - private static final ZoneId CONTROLLER_ZONE = ZoneId.from("prod", "controller"); private static final URI CONTROLLER_URI = URI.create("https://localhost:4443/"); private static final List<String> WHITELISTED_APIS = List.of("/flags/v1/", "/nodes/v2/", "/orchestrator/v1/"); private final ZoneRegistry zoneRegistry; private final ConfigServerRestExecutor proxy; + private final ZoneId controllerZone; public ConfigServerApiHandler(Context parentCtx, ServiceRegistry serviceRegistry, ConfigServerRestExecutor proxy, Controller controller) { super(parentCtx, controller.auditLogger()); this.zoneRegistry = serviceRegistry.zoneRegistry(); + this.controllerZone = zoneRegistry.systemZone().getVirtualId(); this.proxy = proxy; } @@ -83,7 +84,7 @@ public class ConfigServerApiHandler extends AuditLoggingRequestHandler { } ZoneId zoneId = ZoneId.from(path.get("environment"), path.get("region")); - if (! zoneRegistry.hasZone(zoneId) && ! CONTROLLER_ZONE.equals(zoneId)) { + if (! zoneRegistry.hasZone(zoneId) && ! controllerZone.equals(zoneId)) { throw new IllegalArgumentException("No such zone: " + zoneId.value()); } @@ -102,7 +103,7 @@ public class ConfigServerApiHandler extends AuditLoggingRequestHandler { ZoneList zoneList = zoneRegistry.zones().reachable(); Cursor zones = root.setArray("zones"); - Stream.concat(Stream.of(CONTROLLER_ZONE), zoneRegistry.zones().reachable().ids().stream()) + Stream.concat(Stream.of(controllerZone), zoneRegistry.zones().reachable().ids().stream()) .forEach(zone -> { Cursor object = zones.addObject(); object.setString("environment", zone.environment().value()); @@ -118,7 +119,7 @@ public class ConfigServerApiHandler extends AuditLoggingRequestHandler { } private URI getEndpoint(ZoneId zoneId) { - return CONTROLLER_ZONE.equals(zoneId) ? CONTROLLER_URI : zoneRegistry.getConfigServerVipUri(zoneId); + return controllerZone.equals(zoneId) ? CONTROLLER_URI : zoneRegistry.getConfigServerVipUri(zoneId); } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ZoneRegistryMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ZoneRegistryMock.java index 8fcd9527517..a03ab8b677a 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ZoneRegistryMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ZoneRegistryMock.java @@ -141,6 +141,11 @@ public class ZoneRegistryMock extends AbstractComponent implements ZoneRegistry } @Override + public ZoneApi systemZone() { + return ZoneApiMock.fromId("prod.controller"); + } + + @Override public ZoneFilter zones() { return ZoneFilterMock.from(zones, zoneRoutingMethods, reprovisionToUpgradeOs); } |