NodeRebooter extends NodeRepositoryMaintainer { @Override protected boolean maintain() { List<Node> nodesToReboot = nodeRepository().getNodes(Node.State.active, Node.State.ready).stream() .filter(node -> node.flavor().getType() != Flavor.Type.DOCKER_CONTAINER) .filter(this::shouldReboot) .collect(Collectors.toList()); if (!nodesToReboot.isEmpty()) nodeRepository().reboot(NodeListFilter.from(nodesToReboot)); return true; } NodeRebooter(NodeRepository nodeRepository, Clock clock, FlagSource flagSource, Metric metric);   }
@Test public void testRebootScheduling() { var rebootInterval = Duration.ofDays(30); var flagSource = new InMemoryFlagSource().withIntFlag(Flags.REBOOT_INTERVAL_IN_DAYS.id(), (int) rebootInterval.toDays()); var tester = new MaintenanceTester(); tester.createReadyHostNodes(15); NodeRebooter rebooter = new NodeRebooter(tester.nodeRepository, tester.clock, flagSource, new TestMetric()); assertReadyHosts(15, tester, 0L); tester.clock.advance(rebootInterval); rebooter.maintain(); simulateReboot(tester); assertReadyHosts(15, tester, 0L); tester.clock.advance(rebootInterval); rebooter.maintain(); simulateReboot(tester); assertReadyHosts(15, tester, 1L); tester.clock.advance(rebootInterval); scheduleOsUpgrade(tester); simulateOsUpgrade(tester); rebooter.maintain(); simulateReboot(tester); assertReadyHosts(15, tester, 1L); tester.clock.advance(rebootInterval); rebooter.maintain(); simulateReboot(tester); assertReadyHosts(15, tester, 1L); tester.clock.advance(rebootInterval); rebooter.maintain(); simulateReboot(tester); assertReadyHosts(15, tester, 2L); }
@Test public void testRebootScheduledEvenWithSmallProbability() { Duration rebootInterval = Duration.ofDays(30); var flagSource = new InMemoryFlagSource().withIntFlag(Flags.REBOOT_INTERVAL_IN_DAYS.id(), (int) rebootInterval.toDays()); var tester = new MaintenanceTester(); tester.createReadyHostNodes(2); NodeRebooter rebooter = new NodeRebooter(tester.nodeRepository, tester.clock, flagSource, new TestMetric()); assertReadyHosts(2, tester, 0L); tester.clock.advance(rebootInterval); rebooter.maintain(); simulateReboot(tester); assertReadyHosts(2, tester, 0L); tester.clock.advance(Duration.ofMinutes(25)); for (int i = 0;; ++i) { rebooter.maintain(); simulateReboot(tester); List<Node> nodes = tester.nodeRepository.getNodes(NodeType.host, Node.State.ready); int count = withCurrentRebootGeneration(1L, nodes).size(); if (count == 2) { break; } } }