diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-04-28 20:17:59 +0200 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-04-29 11:54:42 +0200 |
commit | 11fc2eece8075c8eefd104f8754e973425e5304c (patch) | |
tree | ad8f1a11a0ff4a62bbe0485442ecd9df841bc0d4 /controller-server | |
parent | b89b5e9eeb57e6af217579b051f418c72847d928 (diff) |
Use vespajlib maintenance package in controller-server
Diffstat (limited to 'controller-server')
59 files changed, 314 insertions, 626 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 017b8cfaf45..f46b40b7668 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 @@ -5,6 +5,7 @@ import com.google.inject.Inject; import com.yahoo.component.AbstractComponent; import com.yahoo.component.Version; import com.yahoo.component.Vtag; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.config.provision.CloudName; import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.SystemName; @@ -59,6 +60,7 @@ public class Controller extends AbstractComponent { private final Supplier<String> hostnameSupplier; private final CuratorDb curator; + private final JobControl jobControl; private final ApplicationController applicationController; private final TenantController tenantController; private final JobController jobController; @@ -105,6 +107,7 @@ public class Controller extends AbstractComponent { tenantController = new TenantController(this, curator, accessControl); routingController = new RoutingController(this, Objects.requireNonNull(rotationsConfig, "RotationsConfig cannot be null")); auditLogger = new AuditLogger(curator, clock); + jobControl = new JobControl(curator); // Record the version of this controller curator().writeControllerVersion(this.hostname(), ControllerVersion.CURRENT); @@ -270,4 +273,7 @@ public class Controller extends AbstractComponent { return vespaVersion.map(v -> v.versionNumber().toFullString()).orElse("unknown"); } + public JobControl jobControl() { + return jobControl; + } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ApplicationOwnershipConfirmer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ApplicationOwnershipConfirmer.java index 9c426d23d82..786819d9442 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ApplicationOwnershipConfirmer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ApplicationOwnershipConfirmer.java @@ -26,13 +26,13 @@ import java.util.logging.Level; * * @author jonmv */ -public class ApplicationOwnershipConfirmer extends Maintainer { +public class ApplicationOwnershipConfirmer extends ControllerMaintainer { private final OwnershipIssues ownershipIssues; private final ApplicationController applications; - public ApplicationOwnershipConfirmer(Controller controller, Duration interval, JobControl jobControl, OwnershipIssues ownershipIssues) { - super(controller, interval, jobControl); + public ApplicationOwnershipConfirmer(Controller controller, Duration interval, OwnershipIssues ownershipIssues) { + super(controller, interval); this.ownershipIssues = ownershipIssues; this.applications = controller.applications(); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingMaintainer.java index 2ab1b4c93ed..7427fac93d2 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/BillingMaintainer.java @@ -12,12 +12,12 @@ import java.util.EnumSet; /** * @author olaa */ -public class BillingMaintainer extends Maintainer { +public class BillingMaintainer extends ControllerMaintainer { private final Billing billing; - public BillingMaintainer(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl, BillingMaintainer.class.getSimpleName(), EnumSet.of(SystemName.cd)); + public BillingMaintainer(Controller controller, Duration interval) { + super(controller, interval, BillingMaintainer.class.getSimpleName(), EnumSet.of(SystemName.cd)); this.billing = controller.serviceRegistry().billingService(); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CloudEventReporter.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CloudEventReporter.java index 199e9e4e7ae..4b96bd404ee 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CloudEventReporter.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/CloudEventReporter.java @@ -26,7 +26,7 @@ import java.util.stream.Collectors; * 2. Submits an issue detailing the event if some hosts are not processed by 1. * @author mgimle */ -public class CloudEventReporter extends Maintainer { +public class CloudEventReporter extends ControllerMaintainer { private static final Logger log = Logger.getLogger(CloudEventReporter.class.getName()); @@ -35,8 +35,8 @@ public class CloudEventReporter extends Maintainer { private final Map<String, List<ZoneApi>> zonesByCloudNativeRegion; private final NodeRepository nodeRepository; - CloudEventReporter(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl); + CloudEventReporter(Controller controller, Duration interval) { + super(controller, interval); this.issueHandler = controller.serviceRegistry().issueHandler(); this.eventFetcher = controller.serviceRegistry().eventFetcherService(); this.nodeRepository = controller.serviceRegistry().configServer().nodeRepository(); 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 12b52d1bf2f..4aba8d881bf 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 @@ -2,7 +2,6 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.config.provision.SystemName; -import java.util.logging.Level; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.LockedTenant; import com.yahoo.vespa.hosted.controller.TenantController; @@ -14,6 +13,7 @@ import com.yahoo.yolean.Exceptions; import java.time.Duration; import java.util.Optional; import java.util.function.Predicate; +import java.util.logging.Level; import java.util.logging.Logger; import static java.util.logging.Level.INFO; @@ -23,14 +23,14 @@ import static java.util.logging.Level.INFO; * * @author mpolden */ -public class ContactInformationMaintainer extends Maintainer { +public class ContactInformationMaintainer extends ControllerMaintainer { private static final Logger log = Logger.getLogger(ContactInformationMaintainer.class.getName()); private final ContactRetriever contactRetriever; - public ContactInformationMaintainer(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl, null, SystemName.allOf(Predicate.not(SystemName::isPublic))); + public ContactInformationMaintainer(Controller controller, Duration interval) { + super(controller, interval, null, SystemName.allOf(Predicate.not(SystemName::isPublic))); this.contactRetriever = controller.serviceRegistry().contactRetriever(); } @@ -56,8 +56,8 @@ public class ContactInformationMaintainer extends Maintainer { } } catch (Exception e) { log.log(Level.WARNING, "Failed to update contact information for " + tenant + ": " + - Exceptions.toMessageString(e) + ". Retrying in " + - maintenanceInterval()); + Exceptions.toMessageString(e) + ". Retrying in " + + interval()); } } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintainer.java new file mode 100644 index 00000000000..2b7c78f96d0 --- /dev/null +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintainer.java @@ -0,0 +1,46 @@ +// 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.maintenance; + +import com.yahoo.concurrent.maintenance.Maintainer; +import com.yahoo.config.provision.SystemName; +import com.yahoo.vespa.hosted.controller.Controller; + +import java.time.Duration; +import java.util.EnumSet; +import java.util.Objects; +import java.util.Set; +import java.util.logging.Logger; + +/** + * A maintainer is some job which runs at a fixed interval to perform some maintenance task in the controller. + * + * @author bratseth + */ +public abstract class ControllerMaintainer extends Maintainer { + + protected static final Logger log = Logger.getLogger(ControllerMaintainer.class.getName()); + + private final Controller controller; + + /** The systems in which this maintainer should run */ + private final Set<SystemName> activeSystems; + + public ControllerMaintainer(Controller controller, Duration interval) { + this(controller, interval, null, EnumSet.allOf(SystemName.class)); + } + + public ControllerMaintainer(Controller controller, Duration interval, String name, Set<SystemName> activeSystems) { + super(name, interval, controller.clock().instant(), controller.jobControl(), controller.curator().cluster()); + this.controller = controller; + this.activeSystems = Set.copyOf(Objects.requireNonNull(activeSystems)); + } + + protected Controller controller() { return controller; } + + @Override + public void run() { + if (!activeSystems.contains(controller.system())) return; + super.run(); + } + +} 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 18fe96fc9b2..b92da2ce740 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 @@ -23,8 +23,6 @@ import java.util.stream.Collectors; */ public class ControllerMaintenance extends AbstractComponent { - private final JobControl jobControl; - private final DeploymentExpirer deploymentExpirer; private final DeploymentIssueReporter deploymentIssueReporter; private final MetricsReporter metricsReporter; @@ -52,70 +50,65 @@ public class ControllerMaintenance extends AbstractComponent { public ControllerMaintenance(MaintainerConfig maintainerConfig, Controller controller, CuratorDb curator, - JobControl jobControl, Metric metric) { Duration maintenanceInterval = Duration.ofMinutes(maintainerConfig.intervalMinutes()); - this.jobControl = jobControl; - deploymentExpirer = new DeploymentExpirer(controller, maintenanceInterval, jobControl); - deploymentIssueReporter = new DeploymentIssueReporter(controller, controller.serviceRegistry().deploymentIssues(), maintenanceInterval, jobControl); - metricsReporter = new MetricsReporter(controller, metric, jobControl); - outstandingChangeDeployer = new OutstandingChangeDeployer(controller, Duration.ofMinutes(3), jobControl); - versionStatusUpdater = new VersionStatusUpdater(controller, Duration.ofMinutes(3), jobControl); - upgrader = new Upgrader(controller, maintenanceInterval, jobControl, curator); - readyJobsTrigger = new ReadyJobsTrigger(controller, Duration.ofMinutes(1), jobControl); - deploymentMetricsMaintainer = new DeploymentMetricsMaintainer(controller, Duration.ofMinutes(5), jobControl); - applicationOwnershipConfirmer = new ApplicationOwnershipConfirmer(controller, Duration.ofHours(12), jobControl, controller.serviceRegistry().ownershipIssues()); - systemUpgrader = new SystemUpgrader(controller, Duration.ofMinutes(1), jobControl); - jobRunner = new JobRunner(controller, Duration.ofSeconds(90), jobControl); - osUpgraders = osUpgraders(controller, jobControl); - osVersionStatusUpdater = new OsVersionStatusUpdater(controller, maintenanceInterval, jobControl); - contactInformationMaintainer = new ContactInformationMaintainer(controller, Duration.ofHours(12), jobControl); - nameServiceDispatcher = new NameServiceDispatcher(controller, Duration.ofSeconds(10), jobControl); - costReportMaintainer = new CostReportMaintainer(controller, Duration.ofHours(2), jobControl, controller.serviceRegistry().costReportConsumer()); - resourceMeterMaintainer = new ResourceMeterMaintainer(controller, Duration.ofMinutes(1), jobControl, metric, controller.serviceRegistry().meteringService()); - billingMaintainer = new BillingMaintainer(controller, Duration.ofDays(3), jobControl); - cloudEventReporter = new CloudEventReporter(controller, Duration.ofDays(1), jobControl); - rotationStatusUpdater = new RotationStatusUpdater(controller, maintenanceInterval, jobControl); - resourceTagMaintainer = new ResourceTagMaintainer(controller, Duration.ofMinutes(30), jobControl, controller.serviceRegistry().resourceTagger()); + deploymentExpirer = new DeploymentExpirer(controller, maintenanceInterval); + deploymentIssueReporter = new DeploymentIssueReporter(controller, controller.serviceRegistry().deploymentIssues(), maintenanceInterval); + metricsReporter = new MetricsReporter(controller, metric); + outstandingChangeDeployer = new OutstandingChangeDeployer(controller, Duration.ofMinutes(3)); + versionStatusUpdater = new VersionStatusUpdater(controller, Duration.ofMinutes(3)); + upgrader = new Upgrader(controller, maintenanceInterval, curator); + readyJobsTrigger = new ReadyJobsTrigger(controller, Duration.ofMinutes(1)); + deploymentMetricsMaintainer = new DeploymentMetricsMaintainer(controller, Duration.ofMinutes(5)); + applicationOwnershipConfirmer = new ApplicationOwnershipConfirmer(controller, Duration.ofHours(12), controller.serviceRegistry().ownershipIssues()); + systemUpgrader = new SystemUpgrader(controller, Duration.ofMinutes(1)); + jobRunner = new JobRunner(controller, Duration.ofSeconds(90)); + osUpgraders = osUpgraders(controller); + osVersionStatusUpdater = new OsVersionStatusUpdater(controller, maintenanceInterval); + contactInformationMaintainer = new ContactInformationMaintainer(controller, Duration.ofHours(12)); + nameServiceDispatcher = new NameServiceDispatcher(controller, Duration.ofSeconds(10)); + costReportMaintainer = new CostReportMaintainer(controller, Duration.ofHours(2), controller.serviceRegistry().costReportConsumer()); + resourceMeterMaintainer = new ResourceMeterMaintainer(controller, Duration.ofMinutes(1), metric, controller.serviceRegistry().meteringService()); + billingMaintainer = new BillingMaintainer(controller, Duration.ofDays(3)); + cloudEventReporter = new CloudEventReporter(controller, Duration.ofDays(1)); + rotationStatusUpdater = new RotationStatusUpdater(controller, maintenanceInterval); + resourceTagMaintainer = new ResourceTagMaintainer(controller, Duration.ofMinutes(30), controller.serviceRegistry().resourceTagger()); } public Upgrader upgrader() { return upgrader; } - - /** Returns control of the maintenance jobs of this */ - public JobControl jobControl() { return jobControl; } @Override public void deconstruct() { - deploymentExpirer.deconstruct(); - deploymentIssueReporter.deconstruct(); - metricsReporter.deconstruct(); - outstandingChangeDeployer.deconstruct(); - versionStatusUpdater.deconstruct(); - upgrader.deconstruct(); - readyJobsTrigger.deconstruct(); - deploymentMetricsMaintainer.deconstruct(); - applicationOwnershipConfirmer.deconstruct(); - systemUpgrader.deconstruct(); - osUpgraders.forEach(Maintainer::deconstruct); - osVersionStatusUpdater.deconstruct(); - jobRunner.deconstruct(); - contactInformationMaintainer.deconstruct(); - costReportMaintainer.deconstruct(); - resourceMeterMaintainer.deconstruct(); - nameServiceDispatcher.deconstruct(); - billingMaintainer.deconstruct(); - cloudEventReporter.deconstruct(); - rotationStatusUpdater.deconstruct(); - resourceTagMaintainer.deconstruct(); + deploymentExpirer.close(); + deploymentIssueReporter.close(); + metricsReporter.close(); + outstandingChangeDeployer.close(); + versionStatusUpdater.close(); + upgrader.close(); + readyJobsTrigger.close(); + deploymentMetricsMaintainer.close(); + applicationOwnershipConfirmer.close(); + systemUpgrader.close(); + osUpgraders.forEach(ControllerMaintainer::close); + osVersionStatusUpdater.close(); + jobRunner.close(); + contactInformationMaintainer.close(); + costReportMaintainer.close(); + resourceMeterMaintainer.close(); + nameServiceDispatcher.close(); + billingMaintainer.close(); + cloudEventReporter.close(); + rotationStatusUpdater.close(); + resourceTagMaintainer.close(); } /** Create one OS upgrader per cloud found in the zone registry of controller */ - private static List<OsUpgrader> osUpgraders(Controller controller, JobControl jobControl) { + private static List<OsUpgrader> osUpgraders(Controller controller) { return controller.zoneRegistry().zones().controllerUpgraded().zones().stream() .map(ZoneApi::getCloudName) .distinct() .sorted() - .map(cloud -> new OsUpgrader(controller, Duration.ofMinutes(1), jobControl, cloud)) + .map(cloud -> new OsUpgrader(controller, Duration.ofMinutes(1), cloud)) .collect(Collectors.collectingAndThen(Collectors.toList(), Collections::unmodifiableList)); } 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 5b792f384e5..d028a88fb92 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 @@ -17,15 +17,14 @@ import java.util.EnumSet; * @author ldalves * @author andreer */ -public class CostReportMaintainer extends Maintainer { +public class CostReportMaintainer extends ControllerMaintainer { private final CostReportConsumer consumer; private final NodeRepository nodeRepository; private final Clock clock; - public CostReportMaintainer(Controller controller, Duration interval, - JobControl jobControl, CostReportConsumer costReportConsumer) { - super(controller, interval, jobControl, null, EnumSet.of(SystemName.main)); + public CostReportMaintainer(Controller controller, Duration interval, CostReportConsumer costReportConsumer) { + super(controller, interval, null, EnumSet.of(SystemName.main)); this.consumer = costReportConsumer; this.nodeRepository = controller.serviceRegistry().configServer().nodeRepository(); this.clock = controller.clock(); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirer.java index 3160e7aef1d..bb2161bca1d 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirer.java @@ -1,9 +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.maintenance; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.vespa.hosted.controller.Application; -import com.yahoo.vespa.hosted.controller.Instance; import com.yahoo.vespa.hosted.controller.Controller; +import com.yahoo.vespa.hosted.controller.Instance; import com.yahoo.vespa.hosted.controller.application.Deployment; import com.yahoo.yolean.Exceptions; @@ -16,10 +17,10 @@ import java.util.logging.Level; * @author mortent * @author bratseth */ -public class DeploymentExpirer extends Maintainer { +public class DeploymentExpirer extends ControllerMaintainer { - public DeploymentExpirer(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl); + public DeploymentExpirer(Controller controller, Duration interval) { + super(controller, interval); } @Override @@ -35,7 +36,7 @@ public class DeploymentExpirer extends Maintainer { } catch (Exception e) { log.log(Level.WARNING, "Could not expire " + deployment + " of " + instance + ": " + Exceptions.toMessageString(e) + ". Retrying in " + - maintenanceInterval()); + interval()); } } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentIssueReporter.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentIssueReporter.java index 848bd451398..89f1e0fe840 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentIssueReporter.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentIssueReporter.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.component.Version; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.SystemName; import com.yahoo.vespa.hosted.controller.Application; @@ -29,7 +30,7 @@ import static com.yahoo.vespa.hosted.controller.versions.VespaVersion.Confidence * * @author jonmv */ -public class DeploymentIssueReporter extends Maintainer { +public class DeploymentIssueReporter extends ControllerMaintainer { static final Duration maxFailureAge = Duration.ofDays(2); static final Duration maxInactivity = Duration.ofDays(4); @@ -37,8 +38,8 @@ public class DeploymentIssueReporter extends Maintainer { private final DeploymentIssues deploymentIssues; - DeploymentIssueReporter(Controller controller, DeploymentIssues deploymentIssues, Duration maintenanceInterval, JobControl jobControl) { - super(controller, maintenanceInterval, jobControl); + DeploymentIssueReporter(Controller controller, DeploymentIssues deploymentIssues, Duration maintenanceInterval) { + super(controller, maintenanceInterval); this.deploymentIssues = deploymentIssues; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java index a4078f7e028..c03be2ca1d1 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainer.java @@ -1,11 +1,11 @@ // Copyright 2018 Yahoo Holdings. 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.yahoo.concurrent.maintenance.JobControl; import com.yahoo.config.provision.SystemName; -import java.util.logging.Level; -import com.yahoo.vespa.hosted.controller.Instance; import com.yahoo.vespa.hosted.controller.ApplicationController; import com.yahoo.vespa.hosted.controller.Controller; +import com.yahoo.vespa.hosted.controller.Instance; import com.yahoo.vespa.hosted.controller.application.Deployment; import com.yahoo.vespa.hosted.controller.application.DeploymentMetrics; import com.yahoo.yolean.Exceptions; @@ -15,6 +15,7 @@ import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -24,7 +25,7 @@ import java.util.logging.Logger; * @author smorgrav * @author mpolden */ -public class DeploymentMetricsMaintainer extends Maintainer { +public class DeploymentMetricsMaintainer extends ControllerMaintainer { private static final Logger log = Logger.getLogger(DeploymentMetricsMaintainer.class.getName()); @@ -32,8 +33,8 @@ public class DeploymentMetricsMaintainer extends Maintainer { private final ApplicationController applications; - public DeploymentMetricsMaintainer(Controller controller, Duration duration, JobControl jobControl) { - super(controller, duration, jobControl, DeploymentMetricsMaintainer.class.getSimpleName(), SystemName.all()); + public DeploymentMetricsMaintainer(Controller controller, Duration duration) { + super(controller, duration, DeploymentMetricsMaintainer.class.getSimpleName(), SystemName.all()); this.applications = controller.applications(); } @@ -84,7 +85,7 @@ public class DeploymentMetricsMaintainer extends Maintainer { String.format("Failed to gather metrics for %d/%d applications. Retrying in %s. Last error: %s", failures.get(), attempts.get(), - maintenanceInterval(), + interval(), Exceptions.toMessageString(lastException.get()))); } } catch (InterruptedException e) { 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 056acd174a9..40072df48b5 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 @@ -23,15 +23,14 @@ import java.util.logging.Logger; * * @author mpolden */ -public abstract class InfrastructureUpgrader extends Maintainer { +public abstract class InfrastructureUpgrader extends ControllerMaintainer { private static final Logger log = Logger.getLogger(InfrastructureUpgrader.class.getName()); private final UpgradePolicy upgradePolicy; - public InfrastructureUpgrader(Controller controller, Duration interval, JobControl jobControl, - UpgradePolicy upgradePolicy, String name) { - super(controller, interval, jobControl, name, EnumSet.allOf(SystemName.class)); + public InfrastructureUpgrader(Controller controller, Duration interval, UpgradePolicy upgradePolicy, String name) { + super(controller, interval, name, EnumSet.allOf(SystemName.class)); this.upgradePolicy = upgradePolicy; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobControl.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobControl.java deleted file mode 100644 index 898af474a8c..00000000000 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobControl.java +++ /dev/null @@ -1,64 +0,0 @@ -// 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.maintenance; - -import com.yahoo.vespa.curator.Lock; -import com.yahoo.vespa.hosted.controller.persistence.CuratorDb; - -import java.util.LinkedHashSet; -import java.util.Set; -import java.util.concurrent.ConcurrentSkipListSet; - -/** - * Provides status and control over running maintenance jobs. - * This is multithread safe. - * - * Job deactivation is stored in zookeeper. - * - * @author bratseth - */ -public class JobControl { - - private final CuratorDb curator; - - /** This is not stored in ZooKeeper as all nodes start all jobs */ - private final Set<String> startedJobs = new ConcurrentSkipListSet<>(); - - /** Create a job control instance which persists activation changes to the default directory */ - public JobControl(CuratorDb curator) { - this.curator = curator; - } - - public CuratorDb curator() { return curator; } - - /** Notifies this that a job was started */ - public void started(String jobSimpleClassName) { - startedJobs.add(jobSimpleClassName); - } - - /** - * Returns a snapshot of the set of jobs started on this system (whether deactivated or not). - * Each job is represented by its simple (omitting package) class name. - */ - public Set<String> jobs() { return new LinkedHashSet<>(startedJobs); } - - /** Returns an unmodifiable set containing the currently inactive jobs in this */ - public Set<String> inactiveJobs() { return curator.readInactiveJobs(); } - - /** Returns true if this job is not currently deactivated */ - public boolean isActive(String jobSimpleClassName) { - return ! inactiveJobs().contains(jobSimpleClassName); - } - - /** Set a job active or inactive */ - public void setActive(String jobSimpleClassName, boolean active) { - try (Lock lock = curator.lockInactiveJobs()) { - Set<String> inactiveJobs = curator.readInactiveJobs(); - if (active) - inactiveJobs.remove(jobSimpleClassName); - else - inactiveJobs.add(jobSimpleClassName); - curator.writeInactiveJobs(inactiveJobs); - } - } - -} diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunner.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunner.java index e8391b8aded..b26375ed4e6 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunner.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunner.java @@ -1,7 +1,6 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.maintenance; -import java.util.logging.Level; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.integration.deployment.RunId; import com.yahoo.vespa.hosted.controller.deployment.InternalStepRunner; @@ -18,6 +17,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.logging.Level; import java.util.logging.Logger; /** @@ -25,7 +25,7 @@ import java.util.logging.Logger; * * @author jonmv */ -public class JobRunner extends Maintainer { +public class JobRunner extends ControllerMaintainer { public static final Duration jobTimeout = Duration.ofDays(1).plusHours(1); private static final Logger log = Logger.getLogger(JobRunner.class.getName()); @@ -34,14 +34,13 @@ public class JobRunner extends Maintainer { private final ExecutorService executors; private final StepRunner runner; - public JobRunner(Controller controller, Duration duration, JobControl jobControl) { - this(controller, duration, jobControl, Executors.newFixedThreadPool(32), new InternalStepRunner(controller)); + public JobRunner(Controller controller, Duration duration) { + this(controller, duration, Executors.newFixedThreadPool(32), new InternalStepRunner(controller)); } @TestOnly - public JobRunner(Controller controller, Duration duration, JobControl jobControl, ExecutorService executors, - StepRunner runner) { - super(controller, duration, jobControl); + public JobRunner(Controller controller, Duration duration, ExecutorService executors, StepRunner runner) { + super(controller, duration); this.jobs = controller.jobController(); this.jobs.setRunner(this::advance); this.executors = executors; @@ -55,8 +54,8 @@ public class JobRunner extends Maintainer { } @Override - public void deconstruct() { - super.deconstruct(); + public void close() { + super.close(); executors.shutdown(); try { executors.awaitTermination(50, TimeUnit.SECONDS); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/Maintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/Maintainer.java deleted file mode 100644 index 3e283d6c54a..00000000000 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/Maintainer.java +++ /dev/null @@ -1,121 +0,0 @@ -// 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.maintenance; - -import com.yahoo.component.AbstractComponent; -import com.yahoo.config.provision.HostName; -import com.yahoo.config.provision.SystemName; -import com.yahoo.vespa.curator.Lock; -import com.yahoo.vespa.hosted.controller.Controller; -import com.yahoo.yolean.Exceptions; - -import java.time.Duration; -import java.time.Instant; -import java.util.EnumSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * A maintainer is some job which runs at a fixed interval to perform some maintenance task in the controller. - * - * @author bratseth - */ -public abstract class Maintainer extends AbstractComponent implements Runnable { - - protected static final Logger log = Logger.getLogger(Maintainer.class.getName()); - - private final Controller controller; - private final Duration maintenanceInterval; - private final JobControl jobControl; - private final ScheduledExecutorService service; - private final String name; - - /** The systems in which this maintainer should run */ - private final Set<SystemName> activeSystems; - - public Maintainer(Controller controller, Duration interval, JobControl jobControl) { - this(controller, interval, jobControl, null, EnumSet.allOf(SystemName.class)); - } - - public Maintainer(Controller controller, Duration interval, JobControl jobControl, String name, Set<SystemName> activeSystems) { - if (interval.isNegative() || interval.isZero()) - throw new IllegalArgumentException("Interval must be positive, but was " + interval); - - this.controller = controller; - this.maintenanceInterval = interval; - this.jobControl = jobControl; - this.name = name; - this.activeSystems = Set.copyOf(activeSystems); - - service = new ScheduledThreadPoolExecutor(1, r -> new Thread(r, name() + "-worker")); - long delay = staggeredDelay(controller.curator().cluster(), controller.hostname(), controller.clock().instant(), interval); - service.scheduleAtFixedRate(this, delay, interval.toMillis(), TimeUnit.MILLISECONDS); - jobControl.started(name()); - } - - protected Controller controller() { return controller; } - - @Override - public void run() { - try { - if ( ! activeSystems.contains(controller.system())) { - return; - } - if (jobControl.isActive(name())) { - try (Lock lock = jobControl.curator().lockMaintenanceJob(name())) { - maintain(); - } - } - } - catch (TimeoutException e) { - // another controller instance is running this job at the moment; ok - } - catch (Throwable t) { - log.log(Level.WARNING, "Maintainer " + name() + " failed. Will retry in " + - maintenanceInterval + ": " + Exceptions.toMessageString(t)); - } - } - - @Override - public void deconstruct() { - var timeout = Duration.ofSeconds(30); - service.shutdown(); - try { - if (!service.awaitTermination(timeout.toMillis(), TimeUnit.MILLISECONDS)) { - log.log(Level.WARNING, "Maintainer " + name() + " failed to shutdown " + - "within " + timeout); - } - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - } - - /** Called once each time this maintenance job should run */ - protected abstract void maintain(); - - public Duration maintenanceInterval() { return maintenanceInterval; } - - public final String name() { - return name == null ? this.getClass().getSimpleName() : name; - } - - /** Returns the name of this */ - @Override - public final String toString() { - return name(); - } - - static long staggeredDelay(List<HostName> cluster, HostName host, Instant now, Duration interval) { - if ( ! cluster.contains(host)) - return interval.toMillis(); - - long offset = cluster.indexOf(host) * interval.toMillis() / cluster.size(); - return Math.floorMod(offset - now.toEpochMilli(), interval.toMillis()); - } - -} diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporter.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporter.java index dfd35d52b2d..a745cf47b42 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporter.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporter.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.maintenance; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.config.provision.ApplicationId; import com.yahoo.jdisc.Metric; import com.yahoo.vespa.hosted.controller.Application; @@ -33,7 +34,7 @@ import java.util.stream.Collectors; * @author mortent * @author mpolden */ -public class MetricsReporter extends Maintainer { +public class MetricsReporter extends ControllerMaintainer { public static final String DEPLOYMENT_FAIL_METRIC = "deployment.failurePercentage"; public static final String DEPLOYMENT_AVERAGE_DURATION = "deployment.averageDuration"; @@ -48,8 +49,8 @@ public class MetricsReporter extends Maintainer { private final Metric metric; private final Clock clock; - public MetricsReporter(Controller controller, Metric metric, JobControl jobControl) { - super(controller, Duration.ofMinutes(1), jobControl); // use fixed rate for metrics + public MetricsReporter(Controller controller, Metric metric) { + super(controller, Duration.ofMinutes(1)); // use fixed rate for metrics this.metric = metric; this.clock = controller.clock(); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcher.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcher.java index e9ff039f8ab..73daef7c2b0 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcher.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/NameServiceDispatcher.java @@ -1,7 +1,6 @@ // 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 java.util.logging.Level; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.integration.dns.NameService; import com.yahoo.vespa.hosted.controller.dns.NameServiceQueue; @@ -9,6 +8,7 @@ import com.yahoo.vespa.hosted.controller.persistence.CuratorDb; import java.time.Clock; import java.time.Duration; +import java.util.logging.Level; /** * This consumes requests from the {@link NameServiceQueue} by submitting them to a {@link NameService}. Successfully @@ -16,7 +16,7 @@ import java.time.Duration; * * @author mpolden */ -public class NameServiceDispatcher extends Maintainer { +public class NameServiceDispatcher extends ControllerMaintainer { private static final int defaultRequestCount = 1; @@ -25,12 +25,12 @@ public class NameServiceDispatcher extends Maintainer { private final NameService nameService; private final int requestCount; - public NameServiceDispatcher(Controller controller, Duration interval, JobControl jobControl) { - this(controller, interval, jobControl, defaultRequestCount); + public NameServiceDispatcher(Controller controller, Duration interval) { + this(controller, interval, defaultRequestCount); } - public NameServiceDispatcher(Controller controller, Duration interval, JobControl jobControl, int requestCount) { - super(controller, interval, jobControl); + public NameServiceDispatcher(Controller controller, Duration interval, int requestCount) { + super(controller, interval); this.clock = controller.clock(); this.db = controller.curator(); this.nameService = controller.serviceRegistry().nameService(); diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OsUpgrader.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OsUpgrader.java index dcb93937eb3..8a97f8f1a9d 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OsUpgrader.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OsUpgrader.java @@ -31,8 +31,8 @@ public class OsUpgrader extends InfrastructureUpgrader { private final CloudName cloud; - public OsUpgrader(Controller controller, Duration interval, JobControl jobControl, CloudName cloud) { - super(controller, interval, jobControl, controller.zoneRegistry().osUpgradePolicy(cloud), name(cloud)); + public OsUpgrader(Controller controller, Duration interval, CloudName cloud) { + super(controller, interval, controller.zoneRegistry().osUpgradePolicy(cloud), name(cloud)); this.cloud = cloud; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OsVersionStatusUpdater.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OsVersionStatusUpdater.java index 4b4d2c8698d..a62b1745145 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OsVersionStatusUpdater.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OsVersionStatusUpdater.java @@ -1,20 +1,21 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.maintenance; -import java.util.logging.Level; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.versions.OsVersionStatus; import com.yahoo.yolean.Exceptions; import java.time.Duration; +import java.util.logging.Level; /** * @author mpolden */ -public class OsVersionStatusUpdater extends Maintainer { +public class OsVersionStatusUpdater extends ControllerMaintainer { - public OsVersionStatusUpdater(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl); + public OsVersionStatusUpdater(Controller controller, Duration interval) { + super(controller, interval); } @Override @@ -24,7 +25,7 @@ public class OsVersionStatusUpdater extends Maintainer { controller().updateOsVersionStatus(newStatus); } catch (Exception e) { log.log(Level.WARNING, "Failed to compute version status: " + Exceptions.toMessageString(e) + - ". Retrying in " + maintenanceInterval()); + ". Retrying in " + interval()); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OutstandingChangeDeployer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OutstandingChangeDeployer.java index 83deb71e663..5dd62251759 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OutstandingChangeDeployer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/OutstandingChangeDeployer.java @@ -12,10 +12,10 @@ import java.time.Duration; * * @author bratseth */ -public class OutstandingChangeDeployer extends Maintainer { +public class OutstandingChangeDeployer extends ControllerMaintainer { - public OutstandingChangeDeployer(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl); + public OutstandingChangeDeployer(Controller controller, Duration interval) { + super(controller, interval); } @Override diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ReadyJobsTrigger.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ReadyJobsTrigger.java index 314f52ca775..32b65f05cac 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ReadyJobsTrigger.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ReadyJobsTrigger.java @@ -1,6 +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.maintenance; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.vespa.hosted.controller.Controller; import java.time.Duration; @@ -10,10 +11,10 @@ import java.time.Duration; * * @author bratseth */ -public class ReadyJobsTrigger extends Maintainer { +public class ReadyJobsTrigger extends ControllerMaintainer { - public ReadyJobsTrigger(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl); + public ReadyJobsTrigger(Controller controller, Duration interval) { + super(controller, interval); } @Override diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java index 34096ba6a10..d57d6ff0976 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainer.java @@ -25,7 +25,7 @@ import java.util.stream.Collectors; * * @author olaa */ -public class ResourceMeterMaintainer extends Maintainer { +public class ResourceMeterMaintainer extends ControllerMaintainer { private final Clock clock; private final Metric metric; @@ -38,10 +38,9 @@ public class ResourceMeterMaintainer extends Maintainer { @SuppressWarnings("WeakerAccess") public ResourceMeterMaintainer(Controller controller, Duration interval, - JobControl jobControl, Metric metric, MeteringClient meteringClient) { - super(controller, interval, jobControl, null, SystemName.all()); + super(controller, interval, null, SystemName.all()); this.clock = controller.clock(); this.nodeRepository = controller.serviceRegistry().configServer().nodeRepository(); this.metric = metric; diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainer.java index 85603704d43..31434de472d 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainer.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.maintenance; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.CloudName; import com.yahoo.config.provision.HostName; @@ -16,12 +17,12 @@ import java.util.stream.Collectors; /** * @author olaa */ -public class ResourceTagMaintainer extends Maintainer { +public class ResourceTagMaintainer extends ControllerMaintainer { private final ResourceTagger resourceTagger; - public ResourceTagMaintainer(Controller controller, Duration interval, JobControl jobControl, ResourceTagger resourceTagger) { - super(controller, interval, jobControl); + public ResourceTagMaintainer(Controller controller, Duration interval, ResourceTagger resourceTagger) { + super(controller, interval); this.resourceTagger = resourceTagger; } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/RotationStatusUpdater.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/RotationStatusUpdater.java index 68f8e5464a0..a8dcaa5740c 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/RotationStatusUpdater.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/RotationStatusUpdater.java @@ -1,7 +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.maintenance; -import java.util.logging.Level; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.vespa.hosted.controller.ApplicationController; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.Instance; @@ -19,6 +19,7 @@ import java.util.concurrent.ForkJoinPool; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import java.util.logging.Level; import java.util.stream.Collectors; /** @@ -26,15 +27,15 @@ import java.util.stream.Collectors; * * @author mpolden */ -public class RotationStatusUpdater extends Maintainer { +public class RotationStatusUpdater extends ControllerMaintainer { private static final int applicationsToUpdateInParallel = 10; private final GlobalRoutingService service; private final ApplicationController applications; - public RotationStatusUpdater(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl); + public RotationStatusUpdater(Controller controller, Duration interval) { + super(controller, interval); this.service = controller.serviceRegistry().globalRoutingService(); this.applications = controller.applications(); } @@ -69,9 +70,9 @@ public class RotationStatusUpdater extends Maintainer { pool.awaitTermination(30, TimeUnit.SECONDS); if (lastException.get() != null) { log.log(Level.WARNING, String.format("Failed to get global routing status of %d/%d applications. Retrying in %s. Last error: ", - failures.get(), - attempts.get(), - maintenanceInterval()), + failures.get(), + attempts.get(), + interval()), lastException.get()); } } catch (InterruptedException e) { diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgrader.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgrader.java index 72c5639735d..be87b5f9223 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgrader.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgrader.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.component.Version; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.config.provision.zone.ZoneApi; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.api.integration.configserver.Node; @@ -24,8 +25,8 @@ public class SystemUpgrader extends InfrastructureUpgrader { private static final Set<Node.State> upgradableNodeStates = Set.of(Node.State.active, Node.State.reserved); - public SystemUpgrader(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl, controller.zoneRegistry().upgradePolicy(), null); + public SystemUpgrader(Controller controller, Duration interval) { + super(controller, interval, controller.zoneRegistry().upgradePolicy(), null); } @Override diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/Upgrader.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/Upgrader.java index 1e22c59636a..6df467c8790 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/Upgrader.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/Upgrader.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.component.Version; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.config.application.api.DeploymentSpec.UpgradePolicy; import com.yahoo.config.provision.ApplicationId; import com.yahoo.vespa.curator.Lock; @@ -33,14 +34,14 @@ import static java.util.Comparator.naturalOrder; * @author bratseth * @author mpolden */ -public class Upgrader extends Maintainer { +public class Upgrader extends ControllerMaintainer { private static final Logger log = Logger.getLogger(Upgrader.class.getName()); private final CuratorDb curator; - public Upgrader(Controller controller, Duration interval, JobControl jobControl, CuratorDb curator) { - super(controller, interval, jobControl); + public Upgrader(Controller controller, Duration interval, CuratorDb curator) { + super(controller, interval); this.curator = Objects.requireNonNull(curator, "curator cannot be null"); } @@ -129,7 +130,7 @@ public class Upgrader extends Maintainer { /** Returns the number of applications to upgrade in this run */ private int numberOfApplicationsToUpgrade() { - return numberOfApplicationsToUpgrade(maintenanceInterval().dividedBy(Math.max(1, controller().curator().cluster().size())).toMillis(), + return numberOfApplicationsToUpgrade(interval().dividedBy(Math.max(1, controller().curator().cluster().size())).toMillis(), controller().clock().millis(), upgradesPerMinute()); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/VersionStatusUpdater.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/VersionStatusUpdater.java index 22030931944..4f1f453637e 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/VersionStatusUpdater.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/VersionStatusUpdater.java @@ -1,12 +1,13 @@ // 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.maintenance; -import java.util.logging.Level; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.versions.VersionStatus; import com.yahoo.yolean.Exceptions; import java.time.Duration; +import java.util.logging.Level; /** * This maintenance job periodically updates the version status. @@ -15,10 +16,10 @@ import java.time.Duration; * * @author bratseth */ -public class VersionStatusUpdater extends Maintainer { +public class VersionStatusUpdater extends ControllerMaintainer { - public VersionStatusUpdater(Controller controller, Duration interval, JobControl jobControl) { - super(controller, interval, jobControl); + public VersionStatusUpdater(Controller controller, Duration interval) { + super(controller, interval); } @Override @@ -28,7 +29,7 @@ public class VersionStatusUpdater extends Maintainer { controller().updateVersionStatus(newStatus); } catch (Exception e) { log.log(Level.WARNING, "Failed to compute version status: " + Exceptions.toMessageString(e) + - ". Retrying in " + maintenanceInterval()); + ". Retrying in " + interval()); } } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java index db0866de5b6..ebd4921ccd7 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/CuratorDb.java @@ -5,11 +5,12 @@ import com.google.common.util.concurrent.UncheckedTimeoutException; import com.google.inject.Inject; import com.yahoo.collections.Pair; import com.yahoo.component.Version; +import com.yahoo.concurrent.maintenance.JobControl; +import com.yahoo.concurrent.maintenance.StringSetSerializer; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.HostName; import com.yahoo.config.provision.TenantName; import com.yahoo.config.provision.zone.ZoneId; -import java.util.logging.Level; import com.yahoo.path.Path; import com.yahoo.slime.Slime; import com.yahoo.slime.SlimeUtils; @@ -71,7 +72,7 @@ import static java.util.stream.Collectors.toUnmodifiableList; * @author mpolden * @author jonmv */ -public class CuratorDb { +public class CuratorDb implements JobControl.Db { private static final Logger log = Logger.getLogger(CuratorDb.class.getName()); private static final Duration deployLockTimeout = Duration.ofMinutes(30); @@ -119,13 +120,12 @@ public class CuratorDb { this.tryLockTimeout = tryLockTimeout; } - /** Returns all hosts configured to be part of this ZooKeeper cluster */ - public List<HostName> cluster() { + /** Returns all hostnames configured to be part of this ZooKeeper cluster */ + public List<String> cluster() { return Arrays.stream(curator.zooKeeperEnsembleConnectionSpec().split(",")) .filter(hostAndPort -> !hostAndPort.isEmpty()) .map(hostAndPort -> hostAndPort.split(":")[0]) - .map(HostName::from) - .collect(Collectors.toList()); + .collect(Collectors.toUnmodifiableList()); } // -------------- Locks --------------------------------------------------- @@ -158,12 +158,18 @@ public class CuratorDb { return curator.lock(lockRoot.append("confidenceOverrides"), defaultLockTimeout); } + @Override public Lock lockInactiveJobs() { return curator.lock(lockRoot.append("inactiveJobsLock"), defaultLockTimeout); } - public Lock lockMaintenanceJob(String jobName) throws TimeoutException { - return tryLock(lockRoot.append("maintenanceJobLocks").append(jobName)); + @Override + public Lock lockMaintenanceJob(String jobName) { + try { + return tryLock(lockRoot.append("maintenanceJobLocks").append(jobName)); + } catch (TimeoutException e) { + throw new UncheckedTimeoutException(e); + } } @SuppressWarnings("unused") // Called by internal code @@ -222,11 +228,12 @@ public class CuratorDb { } } - // -------------- Deployment orchestration -------------------------------- + // -------------- Maintenance jobs ---------------------------------------- + @Override public Set<String> readInactiveJobs() { try { - return readSlime(inactiveJobsPath()).map(stringSetSerializer::fromSlime).orElseGet(HashSet::new); + return read(inactiveJobsPath(), stringSetSerializer::fromJson).orElseGet(HashSet::new); } catch (RuntimeException e) { log.log(Level.WARNING, "Error reading inactive jobs, deleting inactive state"); @@ -235,10 +242,13 @@ public class CuratorDb { } } + @Override public void writeInactiveJobs(Set<String> inactiveJobs) { curator.set(inactiveJobsPath(), stringSetSerializer.toJson(inactiveJobs)); } + // -------------- Deployment orchestration -------------------------------- + public double readUpgradesPerMinute() { return read(upgradesPerMinutePath(), ByteBuffer::wrap).map(ByteBuffer::getDouble).orElse(0.125); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/StringSetSerializer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/StringSetSerializer.java deleted file mode 100644 index cfd92e8a7f4..00000000000 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/persistence/StringSetSerializer.java +++ /dev/null @@ -1,44 +0,0 @@ -// 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.persistence; - -import com.yahoo.slime.ArrayTraverser; -import com.yahoo.slime.Cursor; -import com.yahoo.slime.Inspector; -import com.yahoo.slime.Slime; -import com.yahoo.slime.SlimeUtils; - -import java.io.IOException; -import java.util.HashSet; -import java.util.Set; - -/** - * Serialization of a set of strings to/from Json bytes using Slime. - * - * The set is serialized as an array of string. - * - * @author bratseth - */ -public class StringSetSerializer { - - public byte[] toJson(Set<String> stringSet) { - try { - Slime slime = new Slime(); - Cursor array = slime.setArray(); - for (String element : stringSet) - array.addString(element); - return SlimeUtils.toJsonBytes(slime); - } - catch (IOException e) { - throw new RuntimeException("Serialization of a string set failed", e); - } - - } - - public Set<String> fromSlime(Slime slime) { - Inspector inspector = slime.get(); - Set<String> stringSet = new HashSet<>(); - inspector.traverse((ArrayTraverser) (index, name) -> stringSet.add(name.asString())); - return stringSet; - } - -} diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/ControllerApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/ControllerApiHandler.java index ea3559a92ae..8b1beb91b83 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/ControllerApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/ControllerApiHandler.java @@ -68,7 +68,7 @@ public class ControllerApiHandler extends AuditLoggingRequestHandler { Path path = new Path(request.getUri()); if (path.matches("/controller/v1/")) return root(request); if (path.matches("/controller/v1/auditlog/")) return new AuditLogResponse(controller.auditLogger().readLog()); - if (path.matches("/controller/v1/maintenance/")) return new JobsResponse(maintenance.jobControl()); + if (path.matches("/controller/v1/maintenance/")) return new JobsResponse(controller.jobControl()); if (path.matches("/controller/v1/jobs/upgrader")) return new UpgraderResponse(maintenance.upgrader()); if (path.matches("/controller/v1/metering/tenant/{tenant}/month/{month}")) return new MeteringResponse(controller.serviceRegistry().meteringService(), path.get("tenant"), path.get("month")); return notFound(path); @@ -101,10 +101,10 @@ public class ControllerApiHandler extends AuditLoggingRequestHandler { } private HttpResponse setActive(String jobName, boolean active) { - boolean activatingInactiveJob = active && !maintenance.jobControl().isActive(jobName); - if (!activatingInactiveJob && !maintenance.jobControl().jobs().contains(jobName)) + boolean activatingInactiveJob = active && !controller.jobControl().isActive(jobName); + if (!activatingInactiveJob && !controller.jobControl().jobs().contains(jobName)) return ErrorResponse.notFoundError("No job named '" + jobName + "'"); - maintenance.jobControl().setActive(jobName, active); + controller.jobControl().setActive(jobName, active); return new MessageResponse((active ? "Re-activated" : "Deactivated" ) + " job '" + jobName + "'"); } diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/JobsResponse.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/JobsResponse.java index 82e76ddeda4..df259b2c6f3 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/JobsResponse.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/controller/JobsResponse.java @@ -1,10 +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.restapi.controller; +import com.yahoo.concurrent.maintenance.JobControl; +import com.yahoo.restapi.SlimeJsonResponse; import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; -import com.yahoo.vespa.hosted.controller.maintenance.JobControl; -import com.yahoo.restapi.SlimeJsonResponse; /** * A response containing maintenance job status diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/versions/VersionStatus.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/versions/VersionStatus.java index 19b98ae12cc..fffdd431be1 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/versions/VersionStatus.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/versions/VersionStatus.java @@ -6,7 +6,6 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ListMultimap; import com.yahoo.component.Version; import com.yahoo.config.provision.HostName; -import java.util.logging.Level; import com.yahoo.vespa.hosted.controller.Controller; import com.yahoo.vespa.hosted.controller.application.ApplicationList; import com.yahoo.vespa.hosted.controller.application.SystemApplication; @@ -171,7 +170,8 @@ public class VersionStatus { if (controller.curator().cluster().isEmpty()) { // Use vtag if we do not have cluster versions.put(ControllerVersion.CURRENT, controller.hostname()); } else { - for (HostName hostname : controller.curator().cluster()) { + for (String host : controller.curator().cluster()) { + HostName hostname = HostName.from(host); versions.put(controller.curator().readControllerVersion(hostname), hostname); } } 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 189bd5156e3..189615ad763 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 @@ -197,7 +197,7 @@ public final class ControllerTester { /** Upgrade controller to given version */ public void upgradeController(Version version, String commitSha, Instant commitDate) { for (var hostname : controller().curator().cluster()) { - upgradeController(hostname, version, commitSha, commitDate); + upgradeController(HostName.from(hostname), version, commitSha, commitDate); } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentContext.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentContext.java index a04dc6fb579..6067322f2b6 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentContext.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentContext.java @@ -32,7 +32,6 @@ import com.yahoo.vespa.hosted.controller.application.Deployment; import com.yahoo.vespa.hosted.controller.application.EndpointId; import com.yahoo.vespa.hosted.controller.application.TenantAndApplicationId; import com.yahoo.vespa.hosted.controller.integration.ConfigServerMock; -import com.yahoo.vespa.hosted.controller.maintenance.JobControl; import com.yahoo.vespa.hosted.controller.maintenance.JobRunner; import com.yahoo.vespa.hosted.controller.maintenance.NameServiceDispatcher; import com.yahoo.vespa.hosted.controller.routing.GlobalRouting; @@ -218,8 +217,7 @@ public class DeploymentContext { /** Flush count pending DNS updates */ public DeploymentContext flushDnsUpdates(int count) { - var dispatcher = new NameServiceDispatcher(tester.controller(), Duration.ofDays(1), - new JobControl(tester.controller().curator()), count); + var dispatcher = new NameServiceDispatcher(tester.controller(), Duration.ofDays(1), count); dispatcher.run(); return this; } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTester.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTester.java index 0dccea41ae1..993fb919594 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTester.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTester.java @@ -1,8 +1,8 @@ // Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. package com.yahoo.vespa.hosted.controller.deployment; +import com.yahoo.concurrent.maintenance.JobControl; import com.yahoo.config.provision.ApplicationId; -import java.util.logging.Level; import com.yahoo.test.ManualClock; import com.yahoo.vespa.hosted.controller.Application; import com.yahoo.vespa.hosted.controller.ApplicationController; @@ -14,7 +14,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.stubs.MockTesterCloud; import com.yahoo.vespa.hosted.controller.application.ApplicationList; import com.yahoo.vespa.hosted.controller.application.TenantAndApplicationId; import com.yahoo.vespa.hosted.controller.integration.ConfigServerMock; -import com.yahoo.vespa.hosted.controller.maintenance.JobControl; import com.yahoo.vespa.hosted.controller.maintenance.JobRunner; import com.yahoo.vespa.hosted.controller.maintenance.JobRunnerTest; import com.yahoo.vespa.hosted.controller.maintenance.OutstandingChangeDeployer; @@ -26,6 +25,7 @@ import java.time.Duration; import java.time.Instant; import java.time.ZoneOffset; import java.time.temporal.TemporalAdjusters; +import java.util.logging.Level; import java.util.logging.Logger; import static org.junit.Assert.assertTrue; @@ -77,12 +77,12 @@ public class DeploymentTester { jobs = tester.controller().jobController(); cloud = (MockTesterCloud) tester.controller().jobController().cloud(); var jobControl = new JobControl(tester.controller().curator()); - runner = new JobRunner(tester.controller(), Duration.ofDays(1), jobControl, + runner = new JobRunner(tester.controller(), Duration.ofDays(1), JobRunnerTest.inThreadExecutor(), new InternalStepRunner(tester.controller())); - upgrader = new Upgrader(tester.controller(), maintenanceInterval, jobControl, tester.curator()); + upgrader = new Upgrader(tester.controller(), maintenanceInterval, tester.curator()); upgrader.setUpgradesPerMinute(1); // Anything that makes it at least one for any maintenance period is fine. - readyJobsTrigger = new ReadyJobsTrigger(tester.controller(), maintenanceInterval, jobControl); - outstandingChangeDeployer = new OutstandingChangeDeployer(tester.controller(), maintenanceInterval, jobControl); + readyJobsTrigger = new ReadyJobsTrigger(tester.controller(), maintenanceInterval); + outstandingChangeDeployer = new OutstandingChangeDeployer(tester.controller(), maintenanceInterval); // Get deployment job logs to stderr. Logger.getLogger("").setLevel(Level.FINE); 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 299c81fdb3c..f79d47766ba 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 @@ -9,7 +9,6 @@ import com.yahoo.vespa.hosted.controller.api.integration.organization.IssueId; import com.yahoo.vespa.hosted.controller.api.integration.organization.OwnershipIssues; import com.yahoo.vespa.hosted.controller.api.integration.organization.User; import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester; -import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb; import org.junit.Before; import org.junit.Test; @@ -35,7 +34,7 @@ public class ApplicationOwnershipConfirmerTest { public void setup() { tester = new DeploymentTester(); issues = new MockOwnershipIssues(); - confirmer = new ApplicationOwnershipConfirmer(tester.controller(), Duration.ofDays(1), new JobControl(new MockCuratorDb()), issues); + confirmer = new ApplicationOwnershipConfirmer(tester.controller(), Duration.ofDays(1), issues); } @Test diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudEventReporterTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudEventReporterTest.java index 369ecaf5eb7..b141457dc18 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudEventReporterTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/CloudEventReporterTest.java @@ -44,7 +44,7 @@ public class CloudEventReporterTest { @Test public void maintain() { setUpZones(); - CloudEventReporter cloudEventReporter = new CloudEventReporter(tester.controller(), Duration.ofMinutes(15), new JobControl(tester.curator())); + CloudEventReporter cloudEventReporter = new CloudEventReporter(tester.controller(), Duration.ofMinutes(15)); assertEquals(Set.of("host1.com", "host2.com", "host3.com"), getHostnames(nonAwsZone.getId())); assertEquals(Set.of("host1.com", "host2.com", "host3.com"), getHostnames(awsZone1.getId())); 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 32d2e2f35f4..a75bada7b6f 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 @@ -18,7 +18,6 @@ import java.util.function.Supplier; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; /** * @author mpolden @@ -31,8 +30,7 @@ public class ContactInformationMaintainerTest { @Before public void before() { tester = new ControllerTester(); - maintainer = new ContactInformationMaintainer(tester.controller(), Duration.ofDays(1), - new JobControl(tester.controller().curator())); + maintainer = new ContactInformationMaintainer(tester.controller(), Duration.ofDays(1)); } @Test diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintainerTest.java new file mode 100644 index 00000000000..1151fdd07f0 --- /dev/null +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ControllerMaintainerTest.java @@ -0,0 +1,45 @@ +// Copyright 2018 Yahoo Holdings. 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.yahoo.config.provision.SystemName; +import com.yahoo.vespa.hosted.controller.ControllerTester; +import org.junit.Before; +import org.junit.Test; + +import java.time.Duration; +import java.util.EnumSet; +import java.util.concurrent.atomic.AtomicInteger; + +import static org.junit.Assert.assertEquals; + +/** + * @author mpolden + */ +public class ControllerMaintainerTest { + + private ControllerTester tester; + + @Before + public void before() { + tester = new ControllerTester(); + } + + @Test + public void only_runs_in_permitted_systems() { + AtomicInteger executions = new AtomicInteger(); + maintainerIn(SystemName.cd, executions).run(); + maintainerIn(SystemName.main, executions).run(); + assertEquals(1, executions.get()); + } + + private ControllerMaintainer maintainerIn(SystemName system, AtomicInteger executions) { + return new ControllerMaintainer(tester.controller(), Duration.ofDays(1), + "MockMaintainer", EnumSet.of(system)) { + @Override + protected void maintain() { + executions.incrementAndGet(); + } + }; + } + +} 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 b19003ff734..cbffd6d610f 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 @@ -47,8 +47,8 @@ public class CostReportMaintainerTest { CostReportMaintainer maintainer = new CostReportMaintainer( tester.controller(), Duration.ofDays(1), - new JobControl(tester.curator()), - costReportConsumer); + costReportConsumer + ); maintainer.maintain(); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirerTest.java index bef04b338e6..d718dc6b9cf 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentExpirerTest.java @@ -10,7 +10,6 @@ import com.yahoo.vespa.hosted.controller.application.ApplicationPackage; import com.yahoo.vespa.hosted.controller.application.Deployment; import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder; import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester; -import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb; import org.junit.Test; import java.time.Duration; @@ -32,8 +31,8 @@ public class DeploymentExpirerTest { ZoneId.from(Environment.dev, RegionName.from("us-east-1")), Duration.ofDays(14) ); - DeploymentExpirer expirer = new DeploymentExpirer(tester.controller(), Duration.ofDays(10), - new JobControl(new MockCuratorDb())); + DeploymentExpirer expirer = new DeploymentExpirer(tester.controller(), Duration.ofDays(10) + ); var devApp = tester.newDeploymentContext("tenant1", "app1", "default"); var prodApp = tester.newDeploymentContext("tenant2", "app2", "default"); 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 ee5639dbfec..157941bd092 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 @@ -13,7 +13,6 @@ import com.yahoo.vespa.hosted.controller.application.Change; import com.yahoo.vespa.hosted.controller.application.TenantAndApplicationId; import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder; import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester; -import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb; import com.yahoo.vespa.hosted.controller.versions.VespaVersion; import org.junit.Before; import org.junit.Test; @@ -56,7 +55,7 @@ public class DeploymentIssueReporterTest { public void setup() { tester = new DeploymentTester(); issues = new MockDeploymentIssues(); - reporter = new DeploymentIssueReporter(tester.controller(), issues, Duration.ofDays(1), new JobControl(new MockCuratorDb())); + reporter = new DeploymentIssueReporter(tester.controller(), issues, Duration.ofDays(1)); } @Test diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainerTest.java index 931f22dd7f9..a1fb6463074 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/DeploymentMetricsMaintainerTest.java @@ -122,7 +122,7 @@ public class DeploymentMetricsMaintainerTest { } private static DeploymentMetricsMaintainer maintainer(Controller controller) { - return new DeploymentMetricsMaintainer(controller, Duration.ofDays(1), new JobControl(controller.curator())); + return new DeploymentMetricsMaintainer(controller, Duration.ofDays(1)); } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/JobControlTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/JobControlTest.java deleted file mode 100644 index 44d8adf1d15..00000000000 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/JobControlTest.java +++ /dev/null @@ -1,93 +0,0 @@ -// 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.maintenance; - -import com.yahoo.vespa.hosted.controller.Controller; -import com.yahoo.vespa.hosted.controller.ControllerTester; -import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb; -import org.junit.Test; - -import java.time.Duration; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -/** - * @author bratseth - */ -public class JobControlTest { - - @Test - public void testJobControl() { - JobControl jobControl = new JobControl(new MockCuratorDb()); - - assertTrue(jobControl.jobs().isEmpty()); - - String job1 = "Job1"; - String job2 = "Job2"; - - jobControl.started(job1); - jobControl.started(job2); - assertEquals(2, jobControl.jobs().size()); - assertTrue(jobControl.jobs().contains(job1)); - assertTrue(jobControl.jobs().contains(job2)); - - assertTrue(jobControl.isActive(job1)); - assertTrue(jobControl.isActive(job2)); - - jobControl.setActive(job1, false); - assertFalse(jobControl.isActive(job1)); - assertTrue(jobControl.isActive(job2)); - - jobControl.setActive(job2, false); - assertFalse(jobControl.isActive(job1)); - assertFalse(jobControl.isActive(job2)); - - jobControl.setActive(job1, true); - assertTrue(jobControl.isActive(job1)); - assertFalse(jobControl.isActive(job2)); - - jobControl.setActive(job2, true); - assertTrue(jobControl.isActive(job1)); - assertTrue(jobControl.isActive(job2)); - } - - @Test - public void testJobControlMayDeactivateJobs() { - JobControl jobControl = new JobControl(new MockCuratorDb()); - - ControllerTester tester = new ControllerTester(); - MockMaintainer mockMaintainer = new MockMaintainer(tester.controller(), jobControl); - - assertTrue(jobControl.jobs().contains("MockMaintainer")); - - assertEquals(0, mockMaintainer.maintenanceInvocations); - - mockMaintainer.run(); - assertEquals(1, mockMaintainer.maintenanceInvocations); - - jobControl.setActive("MockMaintainer", false); - mockMaintainer.run(); - assertEquals(1, mockMaintainer.maintenanceInvocations); - - jobControl.setActive("MockMaintainer", true); - mockMaintainer.run(); - assertEquals(2, mockMaintainer.maintenanceInvocations); - } - - private static class MockMaintainer extends Maintainer { - - int maintenanceInvocations = 0; - - public MockMaintainer(Controller controller, JobControl jobControl) { - super(controller, Duration.ofHours(1), jobControl); - } - - @Override - protected void maintain() { - maintenanceInvocations++; - } - - } - -} diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunnerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunnerTest.java index d2946651619..fe33d728b7c 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunnerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/JobRunnerTest.java @@ -87,8 +87,7 @@ public class JobRunnerTest { JobController jobs = tester.controller().jobController(); StepRunner stepRunner = (step, id) -> id.type() == stagingTest && step.get() == startTests? Optional.of(error) : Optional.of(running); Phaser phaser = new Phaser(1); - JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator()), - phasedExecutor(phaser), stepRunner); + JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), phasedExecutor(phaser), stepRunner); TenantAndApplicationId appId = tester.createApplication("tenant", "real", "default").id(); ApplicationId id = appId.defaultInstance(); @@ -119,8 +118,7 @@ public class JobRunnerTest { DeploymentTester tester = new DeploymentTester(); JobController jobs = tester.controller().jobController(); Map<Step, RunStatus> outcomes = new EnumMap<>(Step.class); - JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator()), - inThreadExecutor(), mappedRunner(outcomes)); + JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), inThreadExecutor(), mappedRunner(outcomes)); TenantAndApplicationId appId = tester.createApplication("tenant", "real", "default").id(); ApplicationId id = appId.defaultInstance(); @@ -227,8 +225,7 @@ public class JobRunnerTest { JobController jobs = tester.controller().jobController(); // Hang during tester deployment, until notified. CyclicBarrier barrier = new CyclicBarrier(2); - JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator()), - Executors.newFixedThreadPool(32), waitingRunner(barrier)); + JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), Executors.newFixedThreadPool(32), waitingRunner(barrier)); TenantAndApplicationId appId = tester.createApplication("tenant", "real", "default").id(); ApplicationId id = appId.defaultInstance(); @@ -264,8 +261,7 @@ public class JobRunnerTest { public void historyPruning() { DeploymentTester tester = new DeploymentTester(); JobController jobs = tester.controller().jobController(); - JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator()), - inThreadExecutor(), (id, step) -> Optional.of(running)); + JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), inThreadExecutor(), (id, step) -> Optional.of(running)); TenantAndApplicationId appId = tester.createApplication("tenant", "real", "default").id(); ApplicationId instanceId = appId.defaultInstance(); @@ -289,8 +285,7 @@ public class JobRunnerTest { assertFalse(jobs.details(new RunId(instanceId, systemTest, 1)).isPresent()); assertTrue(jobs.details(new RunId(instanceId, systemTest, 65)).isPresent()); - JobRunner failureRunner = new JobRunner(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator()), - inThreadExecutor(), (id, step) -> Optional.of(error)); + JobRunner failureRunner = new JobRunner(tester.controller(), Duration.ofDays(1), inThreadExecutor(), (id, step) -> Optional.of(error)); // Make all but the oldest of the 54 jobs a failure. for (int i = 0; i < jobs.historyLength() - 1; i++) { @@ -362,8 +357,7 @@ public class JobRunnerTest { DeploymentTester tester = new DeploymentTester(); JobController jobs = tester.controller().jobController(); Map<Step, RunStatus> outcomes = new EnumMap<>(Step.class); - JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator()), - inThreadExecutor(), mappedRunner(outcomes)); + JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), inThreadExecutor(), mappedRunner(outcomes)); TenantAndApplicationId appId = tester.createApplication("tenant", "real", "default").id(); ApplicationId id = appId.defaultInstance(); @@ -380,8 +374,7 @@ public class JobRunnerTest { DeploymentTester tester = new DeploymentTester(); JobController jobs = tester.controller().jobController(); Map<Step, RunStatus> outcomes = new EnumMap<>(Step.class); - JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator()), - inThreadExecutor(), mappedRunner(outcomes)); + JobRunner runner = new JobRunner(tester.controller(), Duration.ofDays(1), inThreadExecutor(), mappedRunner(outcomes)); TenantAndApplicationId appId = tester.createApplication("tenant", "real", "default").id(); ApplicationId id = appId.defaultInstance(); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MaintainerTest.java deleted file mode 100644 index efd5d61ce56..00000000000 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MaintainerTest.java +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2018 Yahoo Holdings. 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.yahoo.config.provision.HostName; -import com.yahoo.config.provision.SystemName; -import com.yahoo.vespa.hosted.controller.ControllerTester; -import org.junit.Before; -import org.junit.Test; - -import java.time.Duration; -import java.time.Instant; -import java.util.EnumSet; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - -import static org.junit.Assert.assertEquals; - -/** - * @author mpolden - */ -public class MaintainerTest { - - private ControllerTester tester; - - @Before - public void before() { - tester = new ControllerTester(); - } - - @Test - public void only_runs_in_permitted_systems() { - AtomicInteger executions = new AtomicInteger(); - maintainerIn(SystemName.cd, executions).run(); - maintainerIn(SystemName.main, executions).run(); - assertEquals(1, executions.get()); - } - - @Test - public void staggering() { - List<HostName> cluster = List.of(HostName.from("cfg1"), HostName.from("cfg2"), HostName.from("cfg3")); - Duration interval = Duration.ofMillis(300); - - Instant now = Instant.ofEpochMilli(1000); - assertEquals(200, Maintainer.staggeredDelay(cluster, HostName.from("cfg1"), now, interval)); - assertEquals( 0, Maintainer.staggeredDelay(cluster, HostName.from("cfg2"), now, interval)); - assertEquals(100, Maintainer.staggeredDelay(cluster, HostName.from("cfg3"), now, interval)); - - now = Instant.ofEpochMilli(1001); - assertEquals(199, Maintainer.staggeredDelay(cluster, HostName.from("cfg1"), now, interval)); - assertEquals(299, Maintainer.staggeredDelay(cluster, HostName.from("cfg2"), now, interval)); - assertEquals( 99, Maintainer.staggeredDelay(cluster, HostName.from("cfg3"), now, interval)); - - now = Instant.ofEpochMilli(1101); - assertEquals( 99, Maintainer.staggeredDelay(cluster, HostName.from("cfg1"), now, interval)); - assertEquals(199, Maintainer.staggeredDelay(cluster, HostName.from("cfg2"), now, interval)); - assertEquals(299, Maintainer.staggeredDelay(cluster, HostName.from("cfg3"), now, interval)); - - assertEquals(300, Maintainer.staggeredDelay(cluster, HostName.from("cfg0"), now, interval)); - } - - private Maintainer maintainerIn(SystemName system, AtomicInteger executions) { - return new Maintainer(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator()), - "MockMaintainer", EnumSet.of(system)) { - @Override - protected void maintain() { - executions.incrementAndGet(); - } - }; - } - -} diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporterTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporterTest.java index df5c3bcbc3c..3c60d467342 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporterTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/MetricsReporterTest.java @@ -17,7 +17,6 @@ import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder; import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester; import com.yahoo.vespa.hosted.controller.integration.MetricsMock; import com.yahoo.vespa.hosted.controller.integration.ZoneApiMock; -import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb; import org.junit.Test; import java.time.Duration; @@ -232,8 +231,8 @@ public class MetricsReporterTest { var reporter = createReporter(tester.controller()); var zone = ZoneId.from("prod.eu-west-1"); tester.zoneRegistry().setUpgradePolicy(UpgradePolicy.create().upgrade(ZoneApiMock.from(zone))); - var systemUpgrader = new SystemUpgrader(tester.controller(), Duration.ofDays(1), - new JobControl(tester.curator())); + var systemUpgrader = new SystemUpgrader(tester.controller(), Duration.ofDays(1) + ); tester.configServer().bootstrap(List.of(zone), SystemApplication.configServer); // System on initial version @@ -287,9 +286,9 @@ public class MetricsReporterTest { var cloud = CloudName.defaultName(); tester.zoneRegistry().setOsUpgradePolicy(cloud, UpgradePolicy.create().upgrade(ZoneApiMock.from(zone))); var osUpgrader = new OsUpgrader(tester.controller(), Duration.ofDays(1), - new JobControl(tester.curator()), CloudName.defaultName()); - var statusUpdater = new OsVersionStatusUpdater(tester.controller(), Duration.ofDays(1), - new JobControl(tester.controller().curator())); + CloudName.defaultName()); + var statusUpdater = new OsVersionStatusUpdater(tester.controller(), Duration.ofDays(1) + ); tester.configServer().bootstrap(List.of(zone), SystemApplication.configServerHost, SystemApplication.tenantHost); // All nodes upgrade to initial OS version @@ -439,7 +438,7 @@ public class MetricsReporterTest { } private MetricsReporter createReporter(Controller controller) { - return new MetricsReporter(controller, metrics, new JobControl(new MockCuratorDb())); + return new MetricsReporter(controller, metrics); } private static String appDimension(ApplicationId id) { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OsUpgraderTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OsUpgraderTest.java index baa4b29ac1d..a5a7304398b 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OsUpgraderTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OsUpgraderTest.java @@ -35,8 +35,8 @@ public class OsUpgraderTest { private static final ZoneApi zone5 = ZoneApiMock.newBuilder().withId("prod.us-north-1").withCloud("other").build(); private final ControllerTester tester = new ControllerTester(); - private final OsVersionStatusUpdater statusUpdater = new OsVersionStatusUpdater(tester.controller(), Duration.ofDays(1), - new JobControl(tester.controller().curator())); + private final OsVersionStatusUpdater statusUpdater = new OsVersionStatusUpdater(tester.controller(), Duration.ofDays(1) + ); @Test public void upgrade_os() { OsUpgrader osUpgrader = osUpgrader( @@ -170,7 +170,7 @@ public class OsUpgraderTest { .setSystemName(system) .setOsUpgradePolicy(CloudName.defaultName(), upgradePolicy); return new OsUpgrader(tester.controller(), Duration.ofDays(1), - new JobControl(tester.curator()), CloudName.defaultName()); + CloudName.defaultName()); } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OsVersionStatusUpdaterTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OsVersionStatusUpdaterTest.java index e51fcff33d1..5ddd2064c32 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OsVersionStatusUpdaterTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OsVersionStatusUpdaterTest.java @@ -6,7 +6,6 @@ import com.yahoo.config.provision.CloudName; import com.yahoo.config.provision.zone.UpgradePolicy; import com.yahoo.config.provision.zone.ZoneApi; import com.yahoo.vespa.hosted.controller.ControllerTester; -import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb; import com.yahoo.vespa.hosted.controller.versions.OsVersion; import com.yahoo.vespa.hosted.controller.versions.OsVersionStatus; import org.junit.Test; @@ -26,8 +25,8 @@ public class OsVersionStatusUpdaterTest { @Test public void test_update() { ControllerTester tester = new ControllerTester(); - OsVersionStatusUpdater statusUpdater = new OsVersionStatusUpdater(tester.controller(), Duration.ofDays(1), - new JobControl(new MockCuratorDb())); + OsVersionStatusUpdater statusUpdater = new OsVersionStatusUpdater(tester.controller(), Duration.ofDays(1) + ); // Add all zones to upgrade policy UpgradePolicy upgradePolicy = UpgradePolicy.create(); for (ZoneApi zone : tester.zoneRegistry().zones().controllerUpgraded().zones()) { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OutstandingChangeDeployerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OutstandingChangeDeployerTest.java index 314901d5e4b..6c303bc2496 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OutstandingChangeDeployerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/OutstandingChangeDeployerTest.java @@ -10,7 +10,6 @@ import com.yahoo.vespa.hosted.controller.application.Change; import com.yahoo.vespa.hosted.controller.deployment.ApplicationPackageBuilder; import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester; import com.yahoo.vespa.hosted.controller.deployment.Run; -import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb; import org.junit.Test; import java.time.Duration; @@ -29,8 +28,7 @@ public class OutstandingChangeDeployerTest { @Test public void testChangeDeployer() { DeploymentTester tester = new DeploymentTester(); - OutstandingChangeDeployer deployer = new OutstandingChangeDeployer(tester.controller(), Duration.ofMinutes(10), - new JobControl(new MockCuratorDb())); + OutstandingChangeDeployer deployer = new OutstandingChangeDeployer(tester.controller(), Duration.ofMinutes(10)); ApplicationPackage applicationPackage = new ApplicationPackageBuilder() .environment(Environment.prod) .region("us-west-1") diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java index 8379722be66..ffc735c1990 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceMeterMaintainerTest.java @@ -35,7 +35,7 @@ public class ResourceMeterMaintainerTest { public void testMaintainer() { setUpZones(); - ResourceMeterMaintainer resourceMeterMaintainer = new ResourceMeterMaintainer(tester.controller(), Duration.ofMinutes(5), new JobControl(tester.curator()), metrics, snapshotConsumer); + ResourceMeterMaintainer resourceMeterMaintainer = new ResourceMeterMaintainer(tester.controller(), Duration.ofMinutes(5), metrics, snapshotConsumer); resourceMeterMaintainer.maintain(); Collection<ResourceSnapshot> consumedResources = snapshotConsumer.consumedResources(); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainerTest.java index 66b125186e0..e42d99c1fee 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/ResourceTagMaintainerTest.java @@ -27,7 +27,6 @@ public class ResourceTagMaintainerTest { MockResourceTagger mockResourceTagger = new MockResourceTagger(); ResourceTagMaintainer resourceTagMaintainer = new ResourceTagMaintainer(tester.controller(), Duration.ofMinutes(5), - new JobControl(tester.curator()), mockResourceTagger); resourceTagMaintainer.maintain(); assertEquals(2, mockResourceTagger.getValues().size()); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RotationStatusUpdaterTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RotationStatusUpdaterTest.java index 77567a58ed2..8df973454a1 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RotationStatusUpdaterTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/RotationStatusUpdaterTest.java @@ -23,7 +23,7 @@ public class RotationStatusUpdaterTest { public void updates_rotation_status() { var tester = new DeploymentTester(); var globalRotationService = tester.controllerTester().serviceRegistry().globalRoutingServiceMock(); - var updater = new RotationStatusUpdater(tester.controller(), Duration.ofDays(1), new JobControl(tester.controller().curator())); + var updater = new RotationStatusUpdater(tester.controller(), Duration.ofDays(1)); var context = tester.newDeploymentContext(ApplicationId.from("tenant1", "app1", "default")); var zone1 = ZoneId.from("prod", "us-west-1"); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgraderTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgraderTest.java index f1031c90344..d5c26408b23 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgraderTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/SystemUpgraderTest.java @@ -266,7 +266,7 @@ public class SystemUpgraderTest { convergeServices(SystemApplication.proxy, zone1); // Confidence is reduced to broken and next zone is not scheduled for upgrade - new Upgrader(tester.controller(), Duration.ofDays(1), new JobControl(tester.curator()), tester.curator()) + new Upgrader(tester.controller(), Duration.ofDays(1), tester.curator()) .overrideConfidence(version2, VespaVersion.Confidence.broken); tester.computeVersionStatus(); systemUpgrader.maintain(); @@ -382,8 +382,8 @@ public class SystemUpgraderTest { private SystemUpgrader systemUpgrader(UpgradePolicy upgradePolicy) { tester.zoneRegistry().setUpgradePolicy(upgradePolicy); - return new SystemUpgrader(tester.controller(), Duration.ofDays(1), - new JobControl(tester.curator())); + return new SystemUpgrader(tester.controller(), Duration.ofDays(1) + ); } } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/UpgraderTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/UpgraderTest.java index 78f198bf05f..b49686237d8 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/UpgraderTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/UpgraderTest.java @@ -607,7 +607,6 @@ public class UpgraderTest { // Setup our own upgrader as we need to control the interval Upgrader upgrader = new Upgrader(tester.controller(), Duration.ofMinutes(10), - new JobControl(tester.controllerTester().curator()), tester.controllerTester().curator()); upgrader.setUpgradesPerMinute(0.2); diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/VersionStatusUpdaterTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/VersionStatusUpdaterTest.java index aab38952602..d3efac55a1a 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/VersionStatusUpdaterTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/VersionStatusUpdaterTest.java @@ -2,7 +2,6 @@ package com.yahoo.vespa.hosted.controller.maintenance; import com.yahoo.vespa.hosted.controller.ControllerTester; -import com.yahoo.vespa.hosted.controller.persistence.MockCuratorDb; import com.yahoo.vespa.hosted.controller.versions.VersionStatus; import org.junit.Test; @@ -25,8 +24,8 @@ public class VersionStatusUpdaterTest { tester.controller().updateVersionStatus(new VersionStatus(Collections.emptyList())); assertFalse(tester.controller().versionStatus().systemVersion().isPresent()); - VersionStatusUpdater updater = new VersionStatusUpdater(tester.controller(), Duration.ofDays(1), - new JobControl(new MockCuratorDb())); + VersionStatusUpdater updater = new VersionStatusUpdater(tester.controller(), Duration.ofDays(1) + ); updater.maintain(); assertTrue(tester.controller().versionStatus().systemVersion().isPresent()); } 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 ad8a3409eef..f79051f2edb 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 @@ -71,7 +71,6 @@ public class ControllerContainerTest { " <component id='com.yahoo.vespa.hosted.controller.Controller'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.integration.ConfigServerProxyMock'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.maintenance.ControllerMaintenance'/>\n" + - " <component id='com.yahoo.vespa.hosted.controller.maintenance.JobControl'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.api.integration.stubs.MockMavenRepository'/>\n" + " <component id='com.yahoo.vespa.hosted.controller.api.integration.stubs.MockUserManagement'/>\n" + " <handler id='com.yahoo.vespa.hosted.controller.restapi.deployment.DeploymentApiHandler'>\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 2752ba64b61..a63597ad32b 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 @@ -58,7 +58,6 @@ import com.yahoo.vespa.hosted.controller.deployment.DeploymentTester; import com.yahoo.vespa.hosted.controller.deployment.DeploymentTrigger; import com.yahoo.vespa.hosted.controller.integration.ConfigServerMock; import com.yahoo.vespa.hosted.controller.integration.ZoneApiMock; -import com.yahoo.vespa.hosted.controller.maintenance.JobControl; import com.yahoo.vespa.hosted.controller.maintenance.RotationStatusUpdater; import com.yahoo.vespa.hosted.controller.metric.ApplicationMetrics; import com.yahoo.vespa.hosted.controller.restapi.ContainerTester; @@ -1589,7 +1588,7 @@ public class ApplicationApiTest extends ControllerContainerTest { private void setZoneInRotation(String rotationName, ZoneId zone) { tester.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(); + new RotationStatusUpdater(tester.controller(), Duration.ofDays(1)).run(); } private void updateContactInformation() { diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/os/OsApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/os/OsApiTest.java index 9f63c714786..66493e6e226 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/os/OsApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/os/OsApiTest.java @@ -14,8 +14,7 @@ import com.yahoo.vespa.hosted.controller.application.SystemApplication; import com.yahoo.vespa.hosted.controller.integration.NodeRepositoryMock; import com.yahoo.vespa.hosted.controller.integration.ZoneApiMock; import com.yahoo.vespa.hosted.controller.integration.ZoneRegistryMock; -import com.yahoo.vespa.hosted.controller.maintenance.JobControl; -import com.yahoo.vespa.hosted.controller.maintenance.Maintainer; +import com.yahoo.vespa.hosted.controller.maintenance.ControllerMaintainer; import com.yahoo.vespa.hosted.controller.maintenance.OsUpgrader; import com.yahoo.vespa.hosted.controller.restapi.ContainerTester; import com.yahoo.vespa.hosted.controller.restapi.ControllerContainerTest; @@ -56,10 +55,8 @@ public class OsApiTest extends ControllerContainerTest { .setOsUpgradePolicy(cloud2, UpgradePolicy.create().upgrade(zone3)); osUpgraders = List.of( new OsUpgrader(tester.controller(), Duration.ofDays(1), - new JobControl(tester.controller().curator()), cloud1), new OsUpgrader(tester.controller(), Duration.ofDays(1), - new JobControl(tester.controller().curator()), cloud2)); } @@ -130,7 +127,7 @@ public class OsApiTest extends ControllerContainerTest { } private void upgradeAndUpdateStatus() { - osUpgraders.forEach(Maintainer::run); + osUpgraders.forEach(ControllerMaintainer::run); updateVersionStatus(); } |