diff options
author | Jon Marius Venstad <venstad@gmail.com> | 2018-11-01 21:03:15 +0100 |
---|---|---|
committer | Jon Marius Venstad <venstad@gmail.com> | 2018-11-01 21:28:52 +0100 |
commit | bf06c2bd3ca2fc5eb74107c3066e4970711fb60b (patch) | |
tree | ea7621068b91799ef61aa05326fdb1dcca232fcd /controller-server | |
parent | 17af68683da8b4df81bbc7c4e4018c616369dc4b (diff) |
Use a public Duration instead of a private primitive for max pause
Diffstat (limited to 'controller-server')
2 files changed, 9 insertions, 8 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTrigger.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTrigger.java index e2a66adee6b..69a42866a9e 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTrigger.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTrigger.java @@ -66,8 +66,9 @@ import static java.util.stream.Collectors.toList; */ public class DeploymentTrigger { + public static final Duration maxPause = Duration.ofDays(3); + private final static Logger log = Logger.getLogger(DeploymentTrigger.class.getName()); - private static final long maxPauseDays = 3; private final Controller controller; private final Clock clock; @@ -224,12 +225,12 @@ public class DeploymentTrigger { } /** Prevents jobs of the given type from starting, until the given time. */ - public void pauseJob(ApplicationId id, JobType jobType, long until) { - if (until > clock.instant().plus(Duration.ofDays(maxPauseDays)).toEpochMilli()) - throw new IllegalArgumentException("Pause only allowed for up to " + maxPauseDays + " days."); + public void pauseJob(ApplicationId id, JobType jobType, Instant until) { + if (until.isAfter(clock.instant().plus(maxPause))) + throw new IllegalArgumentException("Pause only allowed for up to " + maxPause); applications().lockOrThrow(id, application -> - applications().store(application.withJobPause(jobType, OptionalLong.of(until)))); + applications().store(application.withJobPause(jobType, OptionalLong.of(until.toEpochMilli())))); } /** Triggers a change of this application, unless it already has a change. */ diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java index a7668349f66..db58ef1830f 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/deployment/DeploymentTriggerTest.java @@ -530,8 +530,8 @@ public class DeploymentTriggerTest { Application app = tester.createAndDeploy("app", 3, "default"); tester.upgradeSystem(new Version("9.8.7")); - tester.applications().deploymentTrigger().pauseJob(app.id(), productionUsWest1, tester.clock().millis() + 1000); - tester.applications().deploymentTrigger().pauseJob(app.id(), productionUsEast3, tester.clock().millis() + 3000); + tester.applications().deploymentTrigger().pauseJob(app.id(), productionUsWest1, tester.clock().instant().plus(Duration.ofSeconds(1))); + tester.applications().deploymentTrigger().pauseJob(app.id(), productionUsEast3, tester.clock().instant().plus(Duration.ofSeconds(3))); // us-west-1 does not trigger when paused. tester.deployAndNotify(app, true, systemTest); @@ -542,7 +542,7 @@ public class DeploymentTriggerTest { tester.clock().advance(Duration.ofMillis(1500)); tester.readyJobTrigger().run(); tester.assertRunning(productionUsWest1, app.id()); - tester.applications().deploymentTrigger().pauseJob(app.id(), productionUsWest1, tester.clock().millis() + 1000); + tester.applications().deploymentTrigger().pauseJob(app.id(), productionUsWest1, tester.clock().instant().plus(Duration.ofSeconds(1))); tester.deployAndNotify(app, false, productionUsWest1); tester.assertNotRunning(productionUsWest1, app.id()); tester.clock().advance(Duration.ofMillis(1000)); |