HostedVespaClusterPolicy implements ClusterPolicy { @Override public SuspensionReasons verifyGroupGoingDownIsFine(ClusterApi clusterApi) throws HostStateChangeDeniedException { if (clusterApi.noServicesOutsideGroupIsDown()) { return SuspensionReasons.nothingNoteworthy(); } int percentageOfServicesAllowedToBeDown = getConcurrentSuspensionLimit(clusterApi).asPercentage(); if (clusterApi.percentageOfServicesDownIfGroupIsAllowedToBeDown() <= percentageOfServicesAllowedToBeDown) { return SuspensionReasons.nothingNoteworthy(); } Optional<SuspensionReasons> suspensionReasons = clusterApi.reasonsForNoServicesInGroupIsUp(); if (suspensionReasons.isPresent()) { return suspensionReasons.get(); } throw new HostStateChangeDeniedException( clusterApi.getNodeGroup(), ENOUGH_SERVICES_UP_CONSTRAINT, "Suspension for service type " + clusterApi.serviceType() + " would increase from " + clusterApi.percentageOfServicesDown() + "% to " + clusterApi.percentageOfServicesDownIfGroupIsAllowedToBeDown() + "%, over the limit of " + percentageOfServicesAllowedToBeDown + "%." + clusterApi.downDescription()); }  @Override SuspensionReasons verifyGroupGoingDownIsFine(ClusterApi clusterApi); @Override void verifyGroupGoingDownPermanentlyIsFine(ClusterApi clusterApi);  }
@Test public void verifyGroupGoingDownIsFine_noServicesOutsideGroupIsDownIsFine() { verifyGroupGoingDownIsFine(true, Optional.empty(), 13, true); }
@Test public void verifyGroupGoingDownIsFine_noServicesInGroupIsUp() { var reasons = new SuspensionReasons().addReason(new HostName("host1"), "supension reason 1"); verifyGroupGoingDownIsFine(false, Optional.of(reasons), 13, true); }
@Test public void verifyGroupGoingDownIsFine_percentageIsFine() { verifyGroupGoingDownIsFine(false, Optional.empty(), 9, true); }
@Test public void verifyGroupGoingDownIsFine_fails() { verifyGroupGoingDownIsFine(false, Optional.empty(), 13, false); }