diff options
author | Ola Aunrønning <olaa@verizonmedia.com> | 2022-05-05 10:14:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-05 10:14:06 +0200 |
commit | 6ea99ad087e66a5fe051ce5cde3aee55a1c44617 (patch) | |
tree | 0ec532052762c960d72879117ca79e48c2ad0d5f /controller-server | |
parent | 11fa502ceff0f4d7b7939289250441b94419eaa5 (diff) | |
parent | 04a992796cd42134806df706cee8c6626a6eac71 (diff) |
Merge pull request #22436 from vespa-engine/olaa/cmr-skip-weekends
Ignore weekends when considering retirement time.
Diffstat (limited to 'controller-server')
2 files changed, 27 insertions, 3 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainer.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainer.java index d0b3b9f4c7f..1463cce595d 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainer.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainer.java @@ -44,7 +44,7 @@ import java.util.stream.Stream; public class VcmrMaintainer extends ControllerMaintainer { private static final Logger LOG = Logger.getLogger(VcmrMaintainer.class.getName()); - private static final Duration ALLOWED_RETIREMENT_TIME = Duration.ofHours(60); + private static final int DAYS_TO_RETIRE = 2; private static final Duration ALLOWED_POSTPONEMENT_TIME = Duration.ofDays(7); private final CuratorDb curator; @@ -240,8 +240,7 @@ public class VcmrMaintainer extends ControllerMaintainer { private boolean shouldRetire(VespaChangeRequest changeRequest, HostAction action) { return action.getState() == State.PENDING_RETIREMENT && - changeRequest.getChangeRequestSource().getPlannedStartTime() - .minus(ALLOWED_RETIREMENT_TIME) + getRetirementStartTime(changeRequest.getChangeRequestSource().getPlannedStartTime()) .isBefore(ZonedDateTime.now()); } @@ -337,4 +336,16 @@ public class VcmrMaintainer extends ControllerMaintainer { nodeRepository.updateReports(zoneId, node.hostname().value(), report.toNodeReports()); } + // Calculate wanted retirement start time, ignoring weekends + // protected for testing + protected ZonedDateTime getRetirementStartTime(ZonedDateTime plannedStartTime) { + var time = plannedStartTime; + var days = 0; + while (days < DAYS_TO_RETIRE) { + time = time.minusDays(1); + if (time.getDayOfWeek().getValue() < 6) days++; + } + return time; + } + } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainerTest.java index e7a6c3ea3c3..bfbd3836ce7 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainerTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainerTest.java @@ -18,9 +18,11 @@ import com.yahoo.vespa.hosted.controller.integration.NodeRepositoryMock; import org.junit.Before; import org.junit.Test; +import java.time.DayOfWeek; import java.time.Duration; import java.time.Instant; import java.time.ZonedDateTime; +import java.time.temporal.TemporalAdjusters; import java.util.List; import static org.junit.Assert.assertEquals; @@ -244,6 +246,17 @@ public class VcmrMaintainerTest { assertEquals(Status.OUT_OF_SYNC, writtenChangeRequest.getStatus()); } + @Test + public void retirement_start_time_ignores_weekends() { + var plannedStartTime = ZonedDateTime.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.WEDNESDAY)); + var retirementStartTime = maintainer.getRetirementStartTime(plannedStartTime); + assertEquals(plannedStartTime.minusDays(2), retirementStartTime); + + plannedStartTime = ZonedDateTime.now().with(TemporalAdjusters.nextOrSame(DayOfWeek.TUESDAY)); + retirementStartTime = maintainer.getRetirementStartTime(plannedStartTime); + assertEquals(plannedStartTime.minusDays(4), retirementStartTime); + } + private VespaChangeRequest canceledChangeRequest() { return newChangeRequest(ChangeRequestSource.Status.CANCELED, State.RETIRED, State.RETIRING, ZonedDateTime.now()); } |