diff options
author | Martin Polden <mpolden@mpolden.no> | 2019-09-06 08:50:18 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-06 08:50:18 +0200 |
commit | 8ddea5bd559774c2aa11fef876ec32c0d6e8da40 (patch) | |
tree | b96a7a0017862c584d36f364769d5506252af620 /controller-server | |
parent | 0584e536fa4ba962f909c03722ce26e871682005 (diff) | |
parent | 7de52d84f91839a0d12e706ebc5c4796281d5ba2 (diff) |
Merge pull request #10515 from vespa-engine/mpolden/service-registry-3
Move services to ServiceRegistry part III
Diffstat (limited to 'controller-server')
21 files changed, 157 insertions, 163 deletions
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 6e3870e6715..5d3ae7cb753 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 @@ -19,7 +19,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.deployment.ArtifactRepo import com.yahoo.vespa.hosted.controller.api.integration.deployment.TesterCloud; import com.yahoo.vespa.hosted.controller.api.integration.maven.MavenRepository; import com.yahoo.vespa.hosted.controller.api.integration.metrics.MetricsService; -import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient; import com.yahoo.vespa.hosted.controller.api.integration.user.Roles; import com.yahoo.vespa.hosted.controller.api.integration.zone.ZoneRegistry; import com.yahoo.vespa.hosted.controller.api.role.ApplicationRole; @@ -79,7 +78,6 @@ public class Controller extends AbstractComponent { private final FlagSource flagSource; private final NameServiceForwarder nameServiceForwarder; private final MavenRepository mavenRepository; - private final MeteringClient meteringClient; /** * Creates a controller @@ -93,12 +91,12 @@ public class Controller extends AbstractComponent { ArtifactRepository artifactRepository, ApplicationStore applicationStore, TesterCloud testerCloud, BuildService buildService, RunDataStore runDataStore, FlagSource flagSource, MavenRepository mavenRepository, - MeteringClient meteringClient, ServiceRegistry serviceRegistry) { + ServiceRegistry serviceRegistry) { this(curator, rotationsConfig, zoneRegistry, metricsService, Clock.systemUTC(), accessControl, artifactRepository, applicationStore, testerCloud, buildService, runDataStore, com.yahoo.net.HostName::getLocalhost, flagSource, - mavenRepository, meteringClient, serviceRegistry); + mavenRepository, serviceRegistry); } public Controller(CuratorDb curator, RotationsConfig rotationsConfig, @@ -109,7 +107,6 @@ public class Controller extends AbstractComponent { ArtifactRepository artifactRepository, ApplicationStore applicationStore, TesterCloud testerCloud, BuildService buildService, RunDataStore runDataStore, Supplier<String> hostnameSupplier, FlagSource flagSource, MavenRepository mavenRepository, - MeteringClient meteringClient, ServiceRegistry serviceRegistry) { this.hostnameSupplier = Objects.requireNonNull(hostnameSupplier, "HostnameSupplier cannot be null"); @@ -120,7 +117,6 @@ public class Controller extends AbstractComponent { this.clock = Objects.requireNonNull(clock, "Clock cannot be null"); this.flagSource = Objects.requireNonNull(flagSource, "FlagSource cannot be null"); this.mavenRepository = Objects.requireNonNull(mavenRepository, "MavenRepository cannot be null"); - this.meteringClient = Objects.requireNonNull(meteringClient, "MeteringClient cannot be null"); nameServiceForwarder = new NameServiceForwarder(curator); jobController = new JobController(this, runDataStore, Objects.requireNonNull(testerCloud)); @@ -286,10 +282,6 @@ public class Controller extends AbstractComponent { return auditLogger; } - public MeteringClient meteringClient() { - return meteringClient; - } - /** Returns all other roles the given tenant role implies. */ public Set<Role> impliedRoles(TenantRole role) { return Stream.concat(Roles.tenantRoles(role.tenant()).stream(), diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainer.java index 0080d7c23c2..cbe9d8c70c1 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainer.java @@ -11,7 +11,6 @@ import com.yahoo.vespa.hosted.controller.tenant.Tenant; import com.yahoo.yolean.Exceptions; import java.time.Duration; -import java.util.Objects; import java.util.Optional; import java.util.function.Predicate; import java.util.logging.Logger; @@ -27,9 +26,9 @@ public class ContactInformationMaintainer extends Maintainer { private final ContactRetriever contactRetriever; - public ContactInformationMaintainer(Controller controller, Duration interval, JobControl jobControl, ContactRetriever contactRetriever) { + public ContactInformationMaintainer(Controller controller, Duration interval, JobControl jobControl) { super(controller, interval, jobControl, null, SystemName.allOf(Predicate.not(SystemName::isPublic))); - this.contactRetriever = Objects.requireNonNull(contactRetriever, "organization must be non-null"); + this.contactRetriever = controller.serviceRegistry().contactRetriever(); } @Override diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java index 23c2db843d3..2fdee305f3d 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintenance.java @@ -7,16 +7,9 @@ import com.yahoo.jdisc.Metric; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.integration.aws.AwsEventFetcher; import com.yahoo.vespa.hosted.controller.api.integration.organization.Billing; -import com.yahoo.vespa.hosted.controller.api.integration.organization.ContactRetriever; -import com.yahoo.vespa.hosted.controller.api.integration.organization.DeploymentIssues; -import com.yahoo.vespa.hosted.controller.api.integration.organization.IssueHandler; -import com.yahoo.vespa.hosted.controller.api.integration.organization.OwnershipIssues; -import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient; import com.yahoo.vespa.hosted.controller.authority.config.ApiAuthorityConfig; import com.yahoo.vespa.hosted.controller.maintenance.config.MaintainerConfig; import com.yahoo.vespa.hosted.controller.persistence.CuratorDb; -import com.yahoo.vespa.hosted.controller.restapi.cost.CostReportConsumer; -import com.yahoo.vespa.hosted.controller.restapi.cost.config.SelfHostedCostConfig; import java.time.Duration; import java.util.Collections; @@ -57,20 +50,18 @@ public class ControllerMaintenance extends AbstractComponent { private final RotationStatusUpdater rotationStatusUpdater; @SuppressWarnings("unused") // instantiated by Dependency Injection - public ControllerMaintenance(MaintainerConfig maintainerConfig, ApiAuthorityConfig apiAuthorityConfig, Controller controller, CuratorDb curator, - JobControl jobControl, Metric metric, - DeploymentIssues deploymentIssues, OwnershipIssues ownershipIssues, - ContactRetriever contactRetriever, - CostReportConsumer reportConsumer, - MeteringClient meteringClient, + public ControllerMaintenance(MaintainerConfig maintainerConfig, + ApiAuthorityConfig apiAuthorityConfig, + Controller controller, + CuratorDb curator, + JobControl jobControl, + Metric metric, Billing billing, - SelfHostedCostConfig selfHostedCostConfig, - IssueHandler issueHandler, AwsEventFetcher awsEventFetcher) { Duration maintenanceInterval = Duration.ofMinutes(maintainerConfig.intervalMinutes()); this.jobControl = jobControl; deploymentExpirer = new DeploymentExpirer(controller, maintenanceInterval, jobControl); - deploymentIssueReporter = new DeploymentIssueReporter(controller, deploymentIssues, maintenanceInterval, jobControl); + deploymentIssueReporter = new DeploymentIssueReporter(controller, controller.serviceRegistry().deploymentIssues(), maintenanceInterval, jobControl); metricsReporter = new MetricsReporter(controller, metric, jobControl); outstandingChangeDeployer = new OutstandingChangeDeployer(controller, Duration.ofMinutes(1), jobControl); versionStatusUpdater = new VersionStatusUpdater(controller, Duration.ofMinutes(1), jobControl); @@ -78,17 +69,17 @@ public class ControllerMaintenance extends AbstractComponent { readyJobsTrigger = new ReadyJobsTrigger(controller, Duration.ofMinutes(1), jobControl); clusterInfoMaintainer = new ClusterInfoMaintainer(controller, Duration.ofHours(2), jobControl); deploymentMetricsMaintainer = new DeploymentMetricsMaintainer(controller, Duration.ofMinutes(5), jobControl); - applicationOwnershipConfirmer = new ApplicationOwnershipConfirmer(controller, Duration.ofHours(12), jobControl, ownershipIssues); + applicationOwnershipConfirmer = new ApplicationOwnershipConfirmer(controller, Duration.ofHours(12), jobControl, controller.serviceRegistry().ownershipIssues()); systemUpgrader = new SystemUpgrader(controller, Duration.ofMinutes(1), jobControl); jobRunner = new JobRunner(controller, Duration.ofMinutes(2), jobControl); osUpgraders = osUpgraders(controller, jobControl); osVersionStatusUpdater = new OsVersionStatusUpdater(controller, maintenanceInterval, jobControl); - contactInformationMaintainer = new ContactInformationMaintainer(controller, Duration.ofHours(12), jobControl, contactRetriever); + contactInformationMaintainer = new ContactInformationMaintainer(controller, Duration.ofHours(12), jobControl); nameServiceDispatcher = new NameServiceDispatcher(controller, Duration.ofSeconds(10), jobControl); - costReportMaintainer = new CostReportMaintainer(controller, Duration.ofHours(2), reportConsumer, jobControl, selfHostedCostConfig); - resourceMeterMaintainer = new ResourceMeterMaintainer(controller, Duration.ofMinutes(30), jobControl, metric, meteringClient); + costReportMaintainer = new CostReportMaintainer(controller, Duration.ofHours(2), jobControl, controller.serviceRegistry().costReportConsumer()); + resourceMeterMaintainer = new ResourceMeterMaintainer(controller, Duration.ofMinutes(30), jobControl, metric, controller.serviceRegistry().meteringService()); billingMaintainer = new BillingMaintainer(controller, Duration.ofDays(3), jobControl, billing); - awsEventReporterMaintainer = new AwsEventReporterMaintainer(controller, Duration.ofDays(1), jobControl, issueHandler, awsEventFetcher); + awsEventReporterMaintainer = new AwsEventReporterMaintainer(controller, Duration.ofDays(1), jobControl, controller.serviceRegistry().issueHandler(), awsEventFetcher); rotationStatusUpdater = new RotationStatusUpdater(controller, maintenanceInterval, jobControl); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java index 20339b814a8..9c70f734baf 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainer.java @@ -1,14 +1,12 @@ // 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.maintenance; -import com.google.inject.Inject; import com.yahoo.config.provision.CloudName; import com.yahoo.config.provision.SystemName; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.integration.configserver.NodeRepository; +import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumer; import com.yahoo.vespa.hosted.controller.restapi.cost.CostCalculator; -import com.yahoo.vespa.hosted.controller.restapi.cost.CostReportConsumer; -import com.yahoo.vespa.hosted.controller.restapi.cost.config.SelfHostedCostConfig; import java.time.Clock; import java.time.Duration; @@ -25,24 +23,18 @@ public class CostReportMaintainer extends Maintainer { private final CostReportConsumer consumer; private final NodeRepository nodeRepository; private final Clock clock; - private final SelfHostedCostConfig selfHostedCostConfig; - @Inject - @SuppressWarnings("WeakerAccess") public CostReportMaintainer(Controller controller, Duration interval, - CostReportConsumer consumer, - JobControl jobControl, - SelfHostedCostConfig selfHostedCostConfig) { + JobControl jobControl, CostReportConsumer costReportConsumer) { super(controller, interval, jobControl, "CostReportMaintainer", EnumSet.of(SystemName.main)); - this.consumer = consumer; + this.consumer = costReportConsumer; this.nodeRepository = controller.serviceRegistry().configServer().nodeRepository(); this.clock = controller.clock(); - this.selfHostedCostConfig = selfHostedCostConfig; } @Override protected void maintain() { - consumer.Consume(CostCalculator.resourceShareByPropertyToCsv(nodeRepository, controller(), clock, selfHostedCostConfig, CloudName.from("yahoo"))); + consumer.consume(CostCalculator.resourceShareByPropertyToCsv(nodeRepository, controller(), clock, consumer.fixedAllocations(), CloudName.from("yahoo"))); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java index fbc8f06bd38..5edc78c2005 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiHandler.java @@ -809,7 +809,7 @@ public class ApplicationApiHandler extends LoggingRequestHandler { Slime slime = new Slime(); Cursor root = slime.setObject(); - MeteringInfo meteringInfo = controller.meteringClient().getResourceSnapshots(tenant, application); + MeteringInfo meteringInfo = controller.serviceRegistry().meteringService().getResourceSnapshots(tenant, application); ResourceAllocation currentSnapshot = meteringInfo.getCurrentSnapshot(); Cursor currentRate = root.setObject("currentrate"); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/athenz/AthenzApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/athenz/AthenzApiHandler.java index e048c963641..61e5dc359d2 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/athenz/AthenzApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/athenz/AthenzApiHandler.java @@ -9,6 +9,7 @@ import com.yahoo.restapi.Path; import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; import com.yahoo.vespa.athenz.api.AthenzDomain; +import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.identifiers.Property; import com.yahoo.vespa.hosted.controller.api.identifiers.PropertyId; import com.yahoo.vespa.hosted.controller.api.integration.entity.EntityService; @@ -35,10 +36,10 @@ public class AthenzApiHandler extends LoggingRequestHandler { private final AthenzFacade athenz; private final EntityService properties; - public AthenzApiHandler(Context parentCtx, AthenzFacade athenz, EntityService properties) { + public AthenzApiHandler(Context parentCtx, AthenzFacade athenz, Controller controller) { super(parentCtx); this.athenz = athenz; - this.properties = properties; + this.properties = controller.serviceRegistry().entityService(); } @Override diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiHandler.java index ee633a19bfc..6ed9db7455c 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostApiHandler.java @@ -7,9 +7,9 @@ import com.yahoo.container.jdisc.LoggingRequestHandler; import com.yahoo.restapi.Path; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.integration.configserver.NodeRepository; +import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumer; import com.yahoo.vespa.hosted.controller.restapi.ErrorResponse; import com.yahoo.vespa.hosted.controller.restapi.StringResponse; -import com.yahoo.vespa.hosted.controller.restapi.cost.config.SelfHostedCostConfig; import java.time.Clock; import java.util.Optional; @@ -23,13 +23,13 @@ public class CostApiHandler extends LoggingRequestHandler { private final Controller controller; private final NodeRepository nodeRepository; - private final SelfHostedCostConfig selfHostedCostConfig; + private final CostReportConsumer costReportConsumer; - public CostApiHandler(Context ctx, Controller controller, SelfHostedCostConfig selfHostedCostConfig) { + public CostApiHandler(Context ctx, Controller controller) { super(ctx); this.controller = controller; this.nodeRepository = controller.serviceRegistry().configServer().nodeRepository(); - this.selfHostedCostConfig = selfHostedCostConfig; + this.costReportConsumer = controller.serviceRegistry().costReportConsumer(); } @Override @@ -43,7 +43,7 @@ public class CostApiHandler extends LoggingRequestHandler { if (path.matches("/cost/v1/csv")) { Optional<String> cloudProperty = Optional.ofNullable(request.getProperty("cloud")); CloudName cloud = cloudProperty.map(CloudName::from).orElse(CloudName.defaultName()); - return new StringResponse(CostCalculator.resourceShareByPropertyToCsv(nodeRepository, controller, Clock.systemUTC(), selfHostedCostConfig, cloud)); + return new StringResponse(CostCalculator.resourceShareByPropertyToCsv(nodeRepository, controller, Clock.systemUTC(), costReportConsumer.fixedAllocations(), cloud)); } return ErrorResponse.notFoundError("Nothing at " + path); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostCalculator.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostCalculator.java index 50c7732bf76..5cce865eb30 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostCalculator.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostCalculator.java @@ -7,7 +7,6 @@ import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.identifiers.Property; import com.yahoo.vespa.hosted.controller.api.integration.configserver.NodeRepository; import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation; -import com.yahoo.vespa.hosted.controller.restapi.cost.config.SelfHostedCostConfig; import com.yahoo.vespa.hosted.controller.tenant.AthenzTenant; import com.yahoo.vespa.hosted.controller.tenant.Tenant; @@ -32,7 +31,7 @@ public class CostCalculator { public static String resourceShareByPropertyToCsv(NodeRepository nodeRepository, Controller controller, Clock clock, - SelfHostedCostConfig selfHostedCostConfig, + Map<Property, ResourceAllocation> fixedAllocations, CloudName cloudName) { var date = new SimpleDateFormat("yyyy-MM-dd").format(Date.from(clock.instant())); @@ -62,14 +61,12 @@ public class CostCalculator { // Add fixed allocations from config if (cloudName.equals(CloudName.from("yahoo"))) { - for (var propertyEntry : selfHostedCostConfig.properties()) { - var property = new Property(propertyEntry.name()); + for (var kv : fixedAllocations.entrySet()) { + var property = kv.getKey(); var allocation = allocationByProperty.getOrDefault(property, ResourceAllocation.ZERO); - var fixedAllocation = new ResourceAllocation(propertyEntry.cpuCores() * SELF_HOSTED_DISCOUNT, - propertyEntry.memoryGb() * SELF_HOSTED_DISCOUNT, - propertyEntry.diskGb() * SELF_HOSTED_DISCOUNT); - allocationByProperty.put(property, allocation.plus(fixedAllocation)); - totalAllocation = totalAllocation.plus(fixedAllocation); + var discountedFixedAllocation = kv.getValue().multiply(SELF_HOSTED_DISCOUNT); + allocationByProperty.put(property, allocation.plus(discountedFixedAllocation)); + totalAllocation = totalAllocation.plus(discountedFixedAllocation); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostReportConsumer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostReportConsumer.java deleted file mode 100644 index 51a664160ab..00000000000 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostReportConsumer.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.yahoo.vespa.hosted.controller.restapi.cost; - -public interface CostReportConsumer { - void Consume(String csv); -} diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostReportConsumerMock.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostReportConsumerMock.java new file mode 100644 index 00000000000..5c16560b509 --- /dev/null +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/CostReportConsumerMock.java @@ -0,0 +1,38 @@ +package com.yahoo.vespa.hosted.controller.restapi.cost; + +import com.yahoo.vespa.hosted.controller.api.identifiers.Property; +import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumer; +import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation; + +import java.util.Map; +import java.util.function.Consumer; + +/** + * @author ldalves + */ +public class CostReportConsumerMock implements CostReportConsumer { + + private final Consumer<String> csvConsumer; + private final Map<Property, ResourceAllocation> fixedAllocations; + + public CostReportConsumerMock() { + this.csvConsumer = (ignored) -> {}; + this.fixedAllocations = Map.of(); + } + + public CostReportConsumerMock(Consumer<String> csvConsumer, Map<Property, ResourceAllocation> fixedAllocations) { + this.csvConsumer = csvConsumer; + this.fixedAllocations = Map.copyOf(fixedAllocations); + } + + @Override + public void consume(String csv) { + csvConsumer.accept(csv); + } + + @Override + public Map<Property, ResourceAllocation> fixedAllocations() { + return fixedAllocations; + } + +} diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/NoopCostReportConsumer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/NoopCostReportConsumer.java deleted file mode 100644 index f1406da1d4b..00000000000 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/cost/NoopCostReportConsumer.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.yahoo.vespa.hosted.controller.restapi.cost; - -import com.google.inject.Inject; -import com.yahoo.component.AbstractComponent; - -public class NoopCostReportConsumer implements CostReportConsumer { - - @Inject - public NoopCostReportConsumer() {} - - @Override - public void Consume(String csv) { - // discard into the void - } -} diff --git a/controller-server/src/main/resources/configdefinitions/self-hosted-cost.def b/controller-server/src/main/resources/configdefinitions/self-hosted-cost.def deleted file mode 100644 index 059af1558a4..00000000000 --- a/controller-server/src/main/resources/configdefinitions/self-hosted-cost.def +++ /dev/null @@ -1,7 +0,0 @@ -# Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -namespace=vespa.hosted.controller.restapi.cost.config - -properties[].name string -properties[].cpuCores int -properties[].memoryGb int -properties[].diskGb int
\ No newline at end of file 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 19a152a5ba0..9d04d6950f7 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 @@ -26,10 +26,8 @@ import com.yahoo.vespa.hosted.controller.api.integration.dns.MemoryNameService; import com.yahoo.vespa.hosted.controller.api.integration.dns.Record; import com.yahoo.vespa.hosted.controller.api.integration.dns.RecordName; import com.yahoo.vespa.hosted.controller.api.integration.organization.Contact; -import com.yahoo.vespa.hosted.controller.api.integration.organization.MockContactRetriever; import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockBuildService; import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockMavenRepository; -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.application.ApplicationPackage; @@ -83,7 +81,6 @@ public final class ControllerTester { private final ApplicationStoreMock applicationStore; private final MockBuildService buildService; private final MetricsServiceMock metricsService; - private final MockContactRetriever contactRetriever; private Controller controller; @@ -98,7 +95,6 @@ public final class ControllerTester { new ApplicationStoreMock(), new MockBuildService(), metricsService, - new MockContactRetriever(), new ServiceRegistryMock()); } @@ -124,7 +120,6 @@ public final class ControllerTester { ArtifactRepositoryMock artifactRepository, ApplicationStoreMock appStoreMock, MockBuildService buildService, MetricsServiceMock metricsService, - MockContactRetriever contactRetriever, ServiceRegistryMock serviceRegistry) { this.athenzDb = athenzDb; this.clock = clock; @@ -136,7 +131,6 @@ public final class ControllerTester { this.applicationStore = appStoreMock; this.buildService = buildService; this.metricsService = metricsService; - this.contactRetriever = contactRetriever; this.controller = createController(curator, rotationsConfig, clock, zoneRegistry, athenzDb, artifactRepository, appStoreMock, buildService, metricsService, serviceRegistry); @@ -185,10 +179,6 @@ public final class ControllerTester { public MetricsServiceMock metricsService() { return metricsService; } - public MockContactRetriever contactRetriever() { - return contactRetriever; - } - public Optional<Record> findCname(String name) { return serviceRegistry.nameService().findRecords(Record.Type.CNAME, RecordName.from(name)).stream().findFirst(); } @@ -346,7 +336,6 @@ public final class ControllerTester { () -> "test-controller", new InMemoryFlagSource(), new MockMavenRepository(), - new MockMeteringClient(), serviceRegistry); // Calculate initial versions controller.updateVersionStatus(VersionStatus.compute(controller)); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ApplicationCertificateMock.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ApplicationCertificateMock.java deleted file mode 100644 index f3bee70db4c..00000000000 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/integration/ApplicationCertificateMock.java +++ /dev/null @@ -1,22 +0,0 @@ -// 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.yahoo.config.provision.ApplicationId; -import com.yahoo.vespa.hosted.controller.api.integration.certificates.ApplicationCertificate; -import com.yahoo.vespa.hosted.controller.api.integration.certificates.ApplicationCertificateProvider; - -import java.util.UUID; - -/** - * @author tokle - */ -public class ApplicationCertificateMock implements ApplicationCertificateProvider { - - @Override - public ApplicationCertificate requestCaSignedCertificate(ApplicationId applicationId) { - return new ApplicationCertificate(String.format("vespa.tls.%s.%s@%s", applicationId.tenant(), - applicationId.application(), - UUID.randomUUID().toString())); - } - -} 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 19b359c3851..4aba394da4a 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 @@ -3,15 +3,30 @@ package com.yahoo.vespa.hosted.controller.integration; import com.yahoo.component.AbstractComponent; import com.yahoo.vespa.hosted.controller.api.integration.ServiceRegistry; +import com.yahoo.vespa.hosted.controller.api.integration.certificates.ApplicationCertificateMock; import com.yahoo.vespa.hosted.controller.api.integration.certificates.ApplicationCertificateProvider; import com.yahoo.vespa.hosted.controller.api.integration.configserver.ConfigServer; import com.yahoo.vespa.hosted.controller.api.integration.dns.MemoryNameService; import com.yahoo.vespa.hosted.controller.api.integration.dns.NameService; +import com.yahoo.vespa.hosted.controller.api.integration.entity.EntityService; +import com.yahoo.vespa.hosted.controller.api.integration.entity.MemoryEntityService; +import com.yahoo.vespa.hosted.controller.api.integration.organization.ContactRetriever; +import com.yahoo.vespa.hosted.controller.api.integration.organization.IssueHandler; +import com.yahoo.vespa.hosted.controller.api.integration.organization.DeploymentIssues; import com.yahoo.vespa.hosted.controller.api.integration.organization.Mailer; +import com.yahoo.vespa.hosted.controller.api.integration.organization.MockContactRetriever; +import com.yahoo.vespa.hosted.controller.api.integration.organization.MockIssueHandler; +import com.yahoo.vespa.hosted.controller.api.integration.organization.OwnershipIssues; +import com.yahoo.vespa.hosted.controller.api.integration.resource.CostReportConsumer; +import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringClient; import com.yahoo.vespa.hosted.controller.api.integration.routing.GlobalRoutingService; import com.yahoo.vespa.hosted.controller.api.integration.routing.MemoryGlobalRoutingService; import com.yahoo.vespa.hosted.controller.api.integration.routing.RoutingGenerator; +import com.yahoo.vespa.hosted.controller.api.integration.stubs.DummyOwnershipIssues; +import com.yahoo.vespa.hosted.controller.api.integration.stubs.LoggingDeploymentIssues; 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.restapi.cost.CostReportConsumerMock; /** * A mock implementation of a {@link ServiceRegistry} for testing purposes. @@ -27,6 +42,13 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg private final RoutingGeneratorMock routingGeneratorMock = new RoutingGeneratorMock(); private final MockMailer mockMailer = new MockMailer(); private final ApplicationCertificateMock applicationCertificateMock = new ApplicationCertificateMock(); + private final MockMeteringClient mockMeteringClient = new MockMeteringClient(); + private final MockContactRetriever mockContactRetriever = new MockContactRetriever(); + private final MockIssueHandler mockIssueHandler = new MockIssueHandler(); + private final DummyOwnershipIssues dummyOwnershipIssues = new DummyOwnershipIssues(); + private final LoggingDeploymentIssues loggingDeploymentIssues = new LoggingDeploymentIssues(); + private final MemoryEntityService memoryEntityService = new MemoryEntityService(); + private final CostReportConsumerMock costReportConsumerMock = new CostReportConsumerMock(); @Override public ConfigServer configServer() { @@ -54,6 +76,41 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg } @Override + public MeteringClient meteringService() { + return mockMeteringClient; + } + + @Override + public ContactRetriever contactRetriever() { + return mockContactRetriever; + } + + @Override + public IssueHandler issueHandler() { + return mockIssueHandler; + } + + @Override + public OwnershipIssues ownershipIssues() { + return dummyOwnershipIssues; + } + + @Override + public DeploymentIssues deploymentIssues() { + return loggingDeploymentIssues; + } + + @Override + public EntityService entityService() { + return memoryEntityService; + } + + @Override + public CostReportConsumer costReportConsumer() { + return costReportConsumerMock; + } + + @Override public NameService nameService() { return memoryNameService; } @@ -78,4 +135,8 @@ public class ServiceRegistryMock extends AbstractComponent implements ServiceReg return routingGeneratorMock; } + public MockContactRetriever contactRetrieverMock() { + return mockContactRetriever; + } + } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ApplicationOwnershipConfirmerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ApplicationOwnershipConfirmerTest.java index 9eedc49022c..f9c8b66acda 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ApplicationOwnershipConfirmerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ApplicationOwnershipConfirmerTest.java @@ -41,7 +41,7 @@ public class ApplicationOwnershipConfirmerTest { @Test public void testConfirmation() { - Optional<Contact> contact = Optional.of(tester.controllerTester().contactRetriever().contact()); + Optional<Contact> contact = Optional.of(tester.controllerTester().serviceRegistry().contactRetrieverMock().contact()); TenantName property = tester.controllerTester().createTenant("property", "domain", 1L, contact); tester.createAndDeploy(property, "application", 1, "default"); Supplier<Application> propertyApp = () -> tester.controller().applications().require(ApplicationId.from("property", "application", "default")); @@ -69,7 +69,7 @@ public class ApplicationOwnershipConfirmerTest { assertEquals("Confirmation issue has been filed for property owned application.", issueId, propertyApp.get().ownershipIssueId()); assertEquals("Confirmation issue has been filed for user owned application.", issueId, userApp.get().ownershipIssueId()); assertTrue(issues.escalatedToTerminator); - assertTrue("Both applications have had their responses ensured.", issues.escalatedToContact && issues.escalatedToTerminator); + assertTrue("Both applications have had their responses ensured.", issues.escalatedToContact); // No new issue is created, so return empty now. issues.response = Optional.empty(); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainerTest.java index a794940c8c1..0db718080c2 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ContactInformationMaintainerTest.java @@ -32,8 +32,7 @@ public class ContactInformationMaintainerTest { public void before() { tester = new ControllerTester(); maintainer = new ContactInformationMaintainer(tester.controller(), Duration.ofDays(1), - new JobControl(tester.controller().curator()), - tester.contactRetriever()); + new JobControl(tester.controller().curator())); } @Test @@ -53,7 +52,7 @@ public class ContactInformationMaintainerTest { private void registerContact(long propertyId, Contact contact) { PropertyId p = new PropertyId(String.valueOf(propertyId)); - tester.contactRetriever().addContact(p, contact); + tester.serviceRegistry().contactRetrieverMock().addContact(p, contact); } private static Contact testContact() { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainerTest.java index 892da281667..bc68491d8dd 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CostReportMaintainerTest.java @@ -1,13 +1,15 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.vespa.hosted.controller.ControllerTester; +import com.yahoo.vespa.hosted.controller.api.identifiers.Property; +import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation; import com.yahoo.vespa.hosted.controller.integration.ZoneApiMock; -import com.yahoo.vespa.hosted.controller.restapi.cost.CostReportConsumer; -import com.yahoo.vespa.hosted.controller.restapi.cost.config.SelfHostedCostConfig; +import com.yahoo.vespa.hosted.controller.restapi.cost.CostReportConsumerMock; import org.junit.Test; import java.time.Duration; import java.time.Instant; +import java.util.Map; import static org.junit.Assert.assertEquals; @@ -28,21 +30,15 @@ public class CostReportMaintainerTest { ZoneApiMock.newBuilder().withId("prod.eu-west-1").withCloud("yahoo").build()); addNodes(); - CostReportConsumer mockConsumer = csv -> assertEquals( - "Date,Property,Reserved Cpu Cores,Reserved Memory GB,Reserved Disk Space GB,Usage Fraction\n" + + CostReportConsumerMock costReportConsumer = new CostReportConsumerMock( + (csv) -> assertEquals( + "Date,Property,Reserved Cpu Cores,Reserved Memory GB,Reserved Disk Space GB,Usage Fraction\n" + "1970-01-01,Property1,96.0,96.0,2000.0,0.3055555555555555\n" + "1970-01-01,Property3,128.0,96.0,2000.0,0.3333333333333333\n" + "1970-01-01,Property2,160.0,96.0,2000.0,0.3611111111111111", - csv); - - SelfHostedCostConfig costConfig = new SelfHostedCostConfig.Builder() - .properties( - new SelfHostedCostConfig.Properties.Builder() - .name("Property3") - .cpuCores(256) - .memoryGb(192) - .diskGb(4000)) - .build(); + csv), + Map.of(new Property("Property3"), new ResourceAllocation(256, 192, 4000)) + ); tester.createTenant("tenant1", "app1", 1L); @@ -50,9 +46,8 @@ public class CostReportMaintainerTest { CostReportMaintainer maintainer = new CostReportMaintainer( tester.controller(), Duration.ofDays(1), - mockConsumer, new JobControl(tester.curator()), - costConfig); + costReportConsumer); maintainer.maintain(); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentIssueReporterTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentIssueReporterTest.java index 264d28fa056..7da1064cb23 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentIssueReporterTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentIssueReporterTest.java @@ -72,7 +72,7 @@ public class DeploymentIssueReporterTest { tester.upgradeSystem(Version.fromString("6.2")); - Optional<Contact> contact = Optional.of(tester.controllerTester().contactRetriever().contact()); + Optional<Contact> contact = Optional.of(tester.controllerTester().serviceRegistry().contactRetrieverMock().contact()); tester.controllerTester().createTenant("tenant1", "domain1", 1L, contact); tester.controllerTester().createTenant("tenant2", "domain2", 1L, contact); tester.controllerTester().createTenant("tenant3", "domain3", 1L, contact); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java index 6411fbe5cbf..d1c7ac5d363 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/ControllerContainerTest.java @@ -64,16 +64,9 @@ public class ControllerContainerTest { " <component id='com.yahoo.vespa.curator.mock.MockCurator'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.athenz.mock.AthenzClientFactoryMock'/>\n" + - " <component id='com.yahoo.vespa.hosted.controller.api.integration.entity.MemoryEntityService'/>\n" + - " <component id='com.yahoo.vespa.hosted.controller.api.integration.stubs.LoggingDeploymentIssues'/>\n" + - " <component id='com.yahoo.vespa.hosted.controller.restapi.cost.NoopCostReportConsumer'/>\n" + - " <component id='com.yahoo.vespa.hosted.controller.api.integration.stubs.DummyOwnershipIssues'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.api.integration.stubs.MockRunDataStore'/>\n" + - " <component id='com.yahoo.vespa.hosted.controller.api.integration.organization.MockContactRetriever'/>\n" + - " <component id='com.yahoo.vespa.hosted.controller.api.integration.organization.MockIssueHandler'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.api.integration.aws.MockAwsEventFetcher' />\n" + " <component id='com.yahoo.vespa.hosted.controller.api.integration.organization.MockBilling'/>\n" + - " <component id='com.yahoo.vespa.hosted.controller.api.integration.stubs.MockMeteringClient'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.integration.ZoneRegistryMock'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.integration.ServiceRegistryMock'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.Controller'/>\n" + diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java index 9db289ae054..102e05ff923 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/ApplicationApiTest.java @@ -34,7 +34,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType; import com.yahoo.vespa.hosted.controller.api.integration.metrics.MetricsService.ApplicationMetrics; import com.yahoo.vespa.hosted.controller.api.integration.organization.Contact; import com.yahoo.vespa.hosted.controller.api.integration.organization.IssueId; -import com.yahoo.vespa.hosted.controller.api.integration.organization.MockContactRetriever; import com.yahoo.vespa.hosted.controller.api.integration.organization.User; import com.yahoo.vespa.hosted.controller.api.integration.resource.MeteringInfo; import com.yahoo.vespa.hosted.controller.api.integration.resource.ResourceAllocation; @@ -928,7 +927,7 @@ public class ApplicationApiTest extends ControllerContainerTest { @Test public void testMeteringResponses() { - MockMeteringClient mockMeteringClient = (MockMeteringClient) controllerTester.controller().meteringClient(); + MockMeteringClient mockMeteringClient = (MockMeteringClient) controllerTester.containerTester().serviceRegistry().meteringService(); // Mock response for MeteringClient ResourceAllocation currentSnapshot = new ResourceAllocation(1, 2, 3); @@ -1727,10 +1726,6 @@ public class ApplicationApiTest extends ControllerContainerTest { return (ServiceRegistryMock) tester.container().components().getComponent(ServiceRegistryMock.class.getName()); } - private MockContactRetriever contactRetriever() { - return (MockContactRetriever) tester.container().components().getComponent(MockContactRetriever.class.getName()); - } - private void setZoneInRotation(String rotationName, ZoneId zone) { serviceRegistry().globalRoutingServiceMock().setStatus(rotationName, zone, com.yahoo.vespa.hosted.controller.api.integration.routing.RotationStatus.IN); new RotationStatusUpdater(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator())).run(); @@ -1759,11 +1754,12 @@ public class ApplicationApiTest extends ControllerContainerTest { private void registerContact(long propertyId) { PropertyId p = new PropertyId(String.valueOf(propertyId)); - contactRetriever().addContact(p, new Contact(URI.create("www.issues.tld/" + p.id()), - URI.create("www.contacts.tld/" + p.id()), - URI.create("www.properties.tld/" + p.id()), - List.of(Collections.singletonList("alice"), - Collections.singletonList("bob")), "queue", Optional.empty())); + serviceRegistry().contactRetrieverMock().addContact(p, new Contact(URI.create("www.issues.tld/" + p.id()), + URI.create("www.contacts.tld/" + p.id()), + URI.create("www.properties.tld/" + p.id()), + List.of(Collections.singletonList("alice"), + Collections.singletonList("bob")), + "queue", Optional.empty())); } private static class RequestBuilder implements Supplier<Request> { |