diff options
6 files changed, 32 insertions, 24 deletions
diff --git a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java index 578be18c4d7..3d04c239798 100644 --- a/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java +++ b/controller-api/src/main/java/com/yahoo/vespa/hosted/controller/api/integration/ServiceRegistry.java @@ -20,6 +20,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient import com.yahoo.vespa.hosted.controller.api.integration.resource.TenantCost; import com.yahoo.vespa.hosted.controller.api.integration.routing.GlobalRoutingService; import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator; +import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry; import java.time.Clock; @@ -77,4 +78,6 @@ public interface ServiceRegistry { TenantCost tenantCost(); + ZoneRegistry zoneRegistry(); + } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java index dcadd992b32..4f6fe2ac2db 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/Controller.java @@ -78,19 +78,17 @@ public class Controller extends AbstractComponent implements ApplicationIdSource */ @Inject public Controller(CuratorDb curator, RotationsConfig rotationsConfig, - ZoneRegistry zoneRegistry, AccessControl accessControl, FlagSource flagSource, MavenRepository mavenRepository, ServiceRegistry serviceRegistry) { - this(curator, rotationsConfig, zoneRegistry, + this(curator, rotationsConfig, accessControl, com.yahoo.net.HostName::getLocalhost, flagSource, mavenRepository, serviceRegistry); } public Controller(CuratorDb curator, RotationsConfig rotationsConfig, - ZoneRegistry zoneRegistry, AccessControl accessControl, Supplier<String> hostnameSupplier, FlagSource flagSource, MavenRepository mavenRepository, @@ -98,8 +96,8 @@ public class Controller extends AbstractComponent implements ApplicationIdSource this.hostnameSupplier = Objects.requireNonNull(hostnameSupplier, "HostnameSupplier cannot be null"); this.curator = Objects.requireNonNull(curator, "Curator cannot be null"); - this.zoneRegistry = Objects.requireNonNull(zoneRegistry, "ZoneRegistry cannot be null"); this.serviceRegistry = Objects.requireNonNull(serviceRegistry, "ServiceRegistry cannot be null"); + this.zoneRegistry = Objects.requireNonNull(serviceRegistry.zoneRegistry(), "ZoneRegistry cannot be null"); this.clock = Objects.requireNonNull(serviceRegistry.clock(), "Clock cannot be null"); this.flagSource = Objects.requireNonNull(flagSource, "FlagSource cannot be null"); this.mavenRepository = Objects.requireNonNull(mavenRepository, "MavenRepository cannot be null"); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v1/ZoneApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v1/ZoneApiHandler.java index 53373bb228a..abbbbef82c7 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v1/ZoneApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v1/ZoneApiHandler.java @@ -9,6 +9,7 @@ import com.yahoo.container.jdisc.HttpResponse; import com.yahoo.container.jdisc.LoggingRequestHandler; import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; +import com.yahoo.vespa.hosted.controller.api.integration.ServiceRegistry; import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry; import com.yahoo.restapi.ErrorResponse; import com.yahoo.restapi.Path; @@ -32,9 +33,9 @@ public class ZoneApiHandler extends LoggingRequestHandler { private final ZoneRegistry zoneRegistry; - public ZoneApiHandler(LoggingRequestHandler.Context parentCtx, ZoneRegistry zoneRegistry) { + public ZoneApiHandler(LoggingRequestHandler.Context parentCtx, ServiceRegistry serviceRegistry) { super(parentCtx); - this.zoneRegistry = zoneRegistry; + this.zoneRegistry = serviceRegistry.zoneRegistry(); } @Override diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v2/ZoneApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v2/ZoneApiHandler.java index 1a7002c5759..a127a44efb2 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v2/ZoneApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/zone/v2/ZoneApiHandler.java @@ -12,6 +12,7 @@ import com.yahoo.restapi.SlimeJsonResponse; import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; import com.yahoo.vespa.hosted.controller.Controller; +import com.yahoo.vespa.hosted.controller.api.integration.ServiceRegistry; import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry; import com.yahoo.vespa.hosted.controller.auditlog.AuditLoggingRequestHandler; import com.yahoo.vespa.hosted.controller.proxy.ConfigServerRestExecutor; @@ -36,10 +37,10 @@ public class ZoneApiHandler extends AuditLoggingRequestHandler { private final ZoneRegistry zoneRegistry; private final ConfigServerRestExecutor proxy; - public ZoneApiHandler(LoggingRequestHandler.Context parentCtx, ZoneRegistry zoneRegistry, + public ZoneApiHandler(LoggingRequestHandler.Context parentCtx, ServiceRegistry serviceRegistry, ConfigServerRestExecutor proxy, Controller controller) { super(parentCtx, controller.auditLogger()); - this.zoneRegistry = zoneRegistry; + this.zoneRegistry = serviceRegistry.zoneRegistry(); this.proxy = proxy; } @@ -121,4 +122,5 @@ public class ZoneApiHandler extends AuditLoggingRequestHandler { return zoneRegistry.getConfigServerUris(zoneId); } } + } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTester.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTester.java index 35b79cdbf8f..6fd07708c2d 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTester.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTester.java @@ -37,7 +37,6 @@ import com.yahoo.vespa.hosted.controller.integration.ServiceRegistryMock; import com.yahoo.vespa.hosted.controller.integration.ZoneRegistryMock; import com.yahoo.vespa.hosted.controller.persistence.CuratorDb; import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb; -import com.yahoo.vespa.hosted.controller.restapi.ContainerControllerTester; import com.yahoo.vespa.hosted.controller.restapi.ContainerTester; import com.yahoo.vespa.hosted.controller.security.AthenzCredentials; import com.yahoo.vespa.hosted.controller.security.AthenzTenantSpec; @@ -78,7 +77,6 @@ public final class ControllerTester { private final boolean inContainer; private final AthenzDbMock athenzDb; private final ManualClock clock; - private final ZoneRegistryMock zoneRegistry; private final ServiceRegistryMock serviceRegistry; private final CuratorDb curator; private final RotationsConfig rotationsConfig; @@ -91,7 +89,6 @@ public final class ControllerTester { public ControllerTester(RotationsConfig rotationsConfig, MockCuratorDb curatorDb) { this(new AthenzDbMock(), - new ZoneRegistryMock(), curatorDb, rotationsConfig, new ServiceRegistryMock()); @@ -110,13 +107,11 @@ public final class ControllerTester { } private ControllerTester(AthenzDbMock athenzDb, boolean inContainer, - ZoneRegistryMock zoneRegistry, CuratorDb curator, RotationsConfig rotationsConfig, ServiceRegistryMock serviceRegistry, Controller controller) { this.athenzDb = athenzDb; this.inContainer = inContainer; this.clock = serviceRegistry.clock(); - this.zoneRegistry = zoneRegistry; this.serviceRegistry = serviceRegistry; this.curator = curator; this.rotationsConfig = rotationsConfig; @@ -131,18 +126,16 @@ public final class ControllerTester { } private ControllerTester(AthenzDbMock athenzDb, - ZoneRegistryMock zoneRegistry, CuratorDb curator, RotationsConfig rotationsConfig, ServiceRegistryMock serviceRegistry) { - this(athenzDb, false, zoneRegistry, curator, rotationsConfig, serviceRegistry, - createController(curator, rotationsConfig, zoneRegistry, athenzDb, serviceRegistry)); + this(athenzDb, false, curator, rotationsConfig, serviceRegistry, + createController(curator, rotationsConfig, athenzDb, serviceRegistry)); } /** Creates a ControllerTester built on the ContainerTester's controller. This controller can not be recreated. */ public ControllerTester(ContainerTester tester) { this(tester.athenzClientFactory().getSetup(), true, - tester.serviceRegistry().zoneRegistryMock(), tester.controller().curator(), null, tester.serviceRegistry(), @@ -174,7 +167,7 @@ public final class ControllerTester { public MemoryNameService nameService() { return serviceRegistry.nameServiceMock(); } - public ZoneRegistryMock zoneRegistry() { return zoneRegistry; } + public ZoneRegistryMock zoneRegistry() { return serviceRegistry.zoneRegistry(); } public ConfigServerMock configServer() { return serviceRegistry.configServerMock(); } @@ -197,7 +190,7 @@ public final class ControllerTester { public final void createNewController() { if (inContainer) throw new UnsupportedOperationException("Cannot recreate this controller"); - controller = createController(curator, rotationsConfig, zoneRegistry, athenzDb, serviceRegistry); + controller = createController(curator, rotationsConfig, athenzDb, serviceRegistry); } /** Creates the given tenant and application and deploys it */ @@ -371,12 +364,10 @@ public final class ControllerTester { } private static Controller createController(CuratorDb curator, RotationsConfig rotationsConfig, - ZoneRegistryMock zoneRegistryMock, AthenzDbMock athensDb, ServiceRegistryMock serviceRegistry) { Controller controller = new Controller(curator, rotationsConfig, - zoneRegistryMock, new AthenzFacade(new AthenzClientFactoryMock(athensDb)), () -> "test-controller", new InMemoryFlagSource(), diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java index 9cbfa54798e..976f2dead8f 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ServiceRegistryMock.java @@ -1,6 +1,7 @@ // Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.integration; +import com.google.inject.Inject; import com.yahoo.component.AbstractComponent; import com.yahoo.test.ManualClock; import com.yahoo.vespa.hosted.controller.api.integration.BuildService; @@ -42,6 +43,7 @@ import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockMailer; import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockMeteringClient; import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockRunDataStore; import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockTesterCloud; +import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry; import java.time.Clock; @@ -53,8 +55,8 @@ import java.time.Clock; public class ServiceRegistryMock extends AbstractComponent implements ServiceRegistry { private final ManualClock clock = new ManualClock(); - private final ZoneRegistryMock zoneRegistryMock = new ZoneRegistryMock(); - private final ConfigServerMock configServerMock = new ConfigServerMock(zoneRegistryMock); + private final ZoneRegistryMock zoneRegistryMock; + private final ConfigServerMock configServerMock; private final MemoryNameService memoryNameService = new MemoryNameService(); private final MemoryGlobalRoutingService memoryGlobalRoutingService = new MemoryGlobalRoutingService(); private final RoutingGeneratorMock routingGeneratorMock = new RoutingGeneratorMock(RoutingGeneratorMock.TEST_ENDPOINTS); @@ -76,6 +78,16 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg private final MockBuildService mockBuildService = new MockBuildService(); private final MockTenantCost mockTenantCost = new MockTenantCost(); + @Inject + public ServiceRegistryMock(ZoneRegistryMock zoneRegistry) { + this.zoneRegistryMock = zoneRegistry; + this.configServerMock = new ConfigServerMock(zoneRegistry); + } + + public ServiceRegistryMock() { + this(new ZoneRegistryMock()); + } + @Override public ConfigServer configServer() { return configServerMock; @@ -184,7 +196,8 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg @Override public MockTenantCost tenantCost() { return mockTenantCost;} - public ZoneRegistryMock zoneRegistryMock() { + @Override + public ZoneRegistryMock zoneRegistry() { return zoneRegistryMock; } |