summaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorOla Aunrønning <olaa@verizonmedia.com>2022-05-04 11:48:04 +0200
committerOla Aunrønning <olaa@verizonmedia.com>2022-05-04 11:48:04 +0200
commit04a992796cd42134806df706cee8c6626a6eac71 (patch)
tree9cf49c7547d048ad8d8d9034e9d8cf4a69c3814b /controller-server
parentba40d4f84d8b5a62634d68ac9ce671a5044210b2 (diff)
Ignore weekends when considering retirement time. Adjust from 60 to 48 hours
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainer.java17
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/maintenance/VcmrMaintainerTest.java13
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());
}