summaryrefslogtreecommitdiffstats
path: root/orchestrator/src/test/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'orchestrator/src/test/java/com')
-rw-r--r--orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorImplTest.java5
-rw-r--r--orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ClusterApiImplTest.java74
-rw-r--r--orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ModelTestUtils.java26
-rw-r--r--orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaClusterPolicyTest.java23
-rw-r--r--orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaPolicyTest.java5
-rw-r--r--orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/SuspensionReasonsTest.java40
-rw-r--r--orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/HostResourceTest.java20
7 files changed, 142 insertions, 51 deletions
diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorImplTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorImplTest.java
index b32a6aafa56..3580b305c2a 100644
--- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorImplTest.java
+++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorImplTest.java
@@ -26,6 +26,7 @@ import com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException;
import com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException;
import com.yahoo.vespa.orchestrator.policy.HostedVespaClusterPolicy;
import com.yahoo.vespa.orchestrator.policy.HostedVespaPolicy;
+import com.yahoo.vespa.orchestrator.policy.SuspensionReasons;
import com.yahoo.vespa.orchestrator.status.ApplicationLock;
import com.yahoo.vespa.orchestrator.status.HostStatus;
import com.yahoo.vespa.orchestrator.status.StatusService;
@@ -73,7 +74,8 @@ import static org.mockito.internal.verification.VerificationModeFactory.atLeastO
*/
public class OrchestratorImplTest {
- private final ApplicationApiFactory applicationApiFactory = new ApplicationApiFactory(3);
+ private final ManualClock clock = new ManualClock();
+ private final ApplicationApiFactory applicationApiFactory = new ApplicationApiFactory(3, clock);
private final InMemoryFlagSource flagSource = new InMemoryFlagSource();
private final MockCurator curator = new MockCurator();
private ZkStatusService statusService = new ZkStatusService(
@@ -344,6 +346,7 @@ public class OrchestratorImplTest {
var applicationApiFactory = mock(ApplicationApiFactory.class);
var lock = mock(ApplicationLock.class);
+ when(policy.grantSuspensionRequest(any(), any())).thenReturn(SuspensionReasons.nothingNoteworthy());
when(serviceMonitor.getApplication(any(HostName.class))).thenReturn(Optional.of(applicationInstance));
when(applicationInstance.reference()).thenReturn(applicationInstanceReference);
when(zookeeperStatusService.lockApplication(any(), any())).thenReturn(lock);
diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ClusterApiImplTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ClusterApiImplTest.java
index a5cb5cfa630..14d35902738 100644
--- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ClusterApiImplTest.java
+++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ClusterApiImplTest.java
@@ -1,6 +1,7 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.orchestrator.model;
+import com.yahoo.test.ManualClock;
import com.yahoo.vespa.applicationmodel.ApplicationInstance;
import com.yahoo.vespa.applicationmodel.ApplicationInstanceId;
import com.yahoo.vespa.applicationmodel.ClusterId;
@@ -8,15 +9,19 @@ import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.applicationmodel.ServiceCluster;
import com.yahoo.vespa.applicationmodel.ServiceInstance;
import com.yahoo.vespa.applicationmodel.ServiceStatus;
+import com.yahoo.vespa.applicationmodel.ServiceStatusInfo;
import com.yahoo.vespa.applicationmodel.ServiceType;
import com.yahoo.vespa.applicationmodel.TenantId;
import com.yahoo.vespa.orchestrator.OrchestratorUtil;
import com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException;
import com.yahoo.vespa.orchestrator.policy.HostedVespaClusterPolicy;
+import com.yahoo.vespa.orchestrator.policy.SuspensionReasons;
import com.yahoo.vespa.orchestrator.status.HostInfos;
import com.yahoo.vespa.orchestrator.status.HostStatus;
import org.junit.Test;
+import java.time.Duration;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -43,6 +48,7 @@ public class ClusterApiImplTest {
private final ApplicationApi applicationApi = mock(ApplicationApi.class);
private final ModelTestUtils modelUtils = new ModelTestUtils();
+ private final ManualClock clock = new ManualClock(Instant.ofEpochSecond(1600436659));
@Test
public void testServicesDownAndNotInGroup() {
@@ -76,7 +82,7 @@ public class ClusterApiImplTest {
serviceCluster,
new NodeGroup(modelUtils.createApplicationInstance(new ArrayList<>()), hostName5),
modelUtils.getHostInfos(),
- modelUtils.getClusterControllerClientFactory(), ModelTestUtils.NUMBER_OF_CONFIG_SERVERS);
+ modelUtils.getClusterControllerClientFactory(), ModelTestUtils.NUMBER_OF_CONFIG_SERVERS, clock);
assertEquals("{ clusterId=cluster, serviceType=service-type }", clusterApi.clusterInfo());
assertFalse(clusterApi.isStorageCluster());
@@ -139,16 +145,30 @@ public class ClusterApiImplTest {
HostName hostName3 = new HostName("host3");
HostName hostName4 = new HostName("host4");
HostName hostName5 = new HostName("host5");
+ HostName hostName6 = new HostName("host6");
+
+ ServiceInstance service2 = modelUtils.createServiceInstance("service-2", hostName2, ServiceStatus.DOWN);
+
+ // Within down moratorium
+ Instant downSince5 = clock.instant().minus(ClusterApiImpl.downMoratorium).plus(Duration.ofSeconds(5));
+ ServiceInstance service5 = modelUtils.createServiceInstance("service-5", hostName5,
+ new ServiceStatusInfo(ServiceStatus.DOWN, downSince5, downSince5, Optional.empty(), Optional.empty()));
+
+ // After down moratorium
+ Instant downSince6 = clock.instant().minus(ClusterApiImpl.downMoratorium).minus(Duration.ofSeconds(5));
+ ServiceInstance service6 = modelUtils.createServiceInstance("service-6", hostName6,
+ new ServiceStatusInfo(ServiceStatus.DOWN, downSince6, downSince6, Optional.empty(), Optional.empty()));
ServiceCluster serviceCluster = modelUtils.createServiceCluster(
"cluster",
new ServiceType("service-type"),
Arrays.asList(
modelUtils.createServiceInstance("service-1", hostName1, ServiceStatus.UP),
- modelUtils.createServiceInstance("service-2", hostName2, ServiceStatus.DOWN),
+ service2,
modelUtils.createServiceInstance("service-3", hostName3, ServiceStatus.UP),
modelUtils.createServiceInstance("service-4", hostName4, ServiceStatus.DOWN),
- modelUtils.createServiceInstance("service-5", hostName5, ServiceStatus.UP)
+ service5,
+ service6
)
);
modelUtils.createApplicationInstance(Collections.singletonList(serviceCluster));
@@ -158,21 +178,33 @@ public class ClusterApiImplTest {
modelUtils.createNode(hostName3, HostStatus.ALLOWED_TO_BE_DOWN);
modelUtils.createNode(hostName4, HostStatus.ALLOWED_TO_BE_DOWN);
modelUtils.createNode(hostName5, HostStatus.NO_REMARKS);
-
- verifyNoServices(serviceCluster, false, false, hostName1);
- verifyNoServices(serviceCluster, true, false, hostName2);
- verifyNoServices(serviceCluster, true, false, hostName3);
- verifyNoServices(serviceCluster, true, false, hostName4);
- verifyNoServices(serviceCluster, false, false, hostName5);
-
- verifyNoServices(serviceCluster, false, false, hostName1, hostName2);
- verifyNoServices(serviceCluster, true, false, hostName2, hostName3);
- verifyNoServices(serviceCluster, true, true, hostName2, hostName3, hostName4);
- verifyNoServices(serviceCluster, false, true, hostName1, hostName2, hostName3, hostName4);
+ modelUtils.createNode(hostName6, HostStatus.NO_REMARKS);
+
+ var reason2 = SuspensionReasons.isDown(service2);
+ var reason6 = SuspensionReasons.downSince(service6, downSince6, Duration.ofSeconds(35));
+ var reasons2and6 = new SuspensionReasons().mergeWith(reason2).mergeWith(reason6);
+
+ verifyNoServices(serviceCluster, Optional.empty(), false, hostName1);
+ verifyNoServices(serviceCluster, Optional.of(reason2), false, hostName2);
+ verifyNoServices(serviceCluster, Optional.of(SuspensionReasons.nothingNoteworthy()), false, hostName3);
+ verifyNoServices(serviceCluster, Optional.of(SuspensionReasons.nothingNoteworthy()), false, hostName4);
+ verifyNoServices(serviceCluster, Optional.empty(), false, hostName5);
+ verifyNoServices(serviceCluster, Optional.of(reason6), false, hostName6);
+
+ verifyNoServices(serviceCluster, Optional.empty(), false, hostName1, hostName2);
+ verifyNoServices(serviceCluster, Optional.of(reasons2and6), false, hostName2, hostName3, hostName6);
+ verifyNoServices(serviceCluster, Optional.of(reasons2and6), false,
+ hostName2, hostName3, hostName4, hostName6);
+ verifyNoServices(serviceCluster, Optional.empty(), true,
+ hostName2, hostName3, hostName4, hostName5, hostName6);
+ verifyNoServices(serviceCluster, Optional.empty(), false,
+ hostName1, hostName2, hostName3, hostName4, hostName6);
+ verifyNoServices(serviceCluster, Optional.empty(), true,
+ hostName1, hostName2, hostName3, hostName4, hostName5, hostName6);
}
private void verifyNoServices(ServiceCluster serviceCluster,
- boolean expectedNoServicesInGroupIsUp,
+ Optional<SuspensionReasons> expectedNoServicesInGroupIsUp,
boolean expectedNoServicesOutsideGroupIsDown,
HostName... groupNodes) {
ClusterApiImpl clusterApi = new ClusterApiImpl(
@@ -180,9 +212,10 @@ public class ClusterApiImplTest {
serviceCluster,
new NodeGroup(modelUtils.createApplicationInstance(new ArrayList<>()), groupNodes),
modelUtils.getHostInfos(),
- modelUtils.getClusterControllerClientFactory(), ModelTestUtils.NUMBER_OF_CONFIG_SERVERS);
+ modelUtils.getClusterControllerClientFactory(), ModelTestUtils.NUMBER_OF_CONFIG_SERVERS, clock);
- assertEquals(expectedNoServicesInGroupIsUp, clusterApi.noServicesInGroupIsUp());
+ assertEquals(expectedNoServicesInGroupIsUp.map(SuspensionReasons::getMessagesInOrder),
+ clusterApi.reasonsForNoServicesInGroupIsUp().map(SuspensionReasons::getMessagesInOrder));
assertEquals(expectedNoServicesOutsideGroupIsDown, clusterApi.noServicesOutsideGroupIsDown());
}
@@ -210,7 +243,7 @@ public class ClusterApiImplTest {
serviceCluster,
new NodeGroup(applicationInstance, hostName1, hostName3),
new HostInfos(),
- modelUtils.getClusterControllerClientFactory(), ModelTestUtils.NUMBER_OF_CONFIG_SERVERS);
+ modelUtils.getClusterControllerClientFactory(), ModelTestUtils.NUMBER_OF_CONFIG_SERVERS, clock);
assertTrue(clusterApi.isStorageCluster());
assertEquals(Optional.of(hostName1), clusterApi.storageNodeInGroup().map(storageNode -> storageNode.hostName()));
@@ -233,6 +266,9 @@ public class ClusterApiImplTest {
ServiceType.CONFIG_SERVER,
instances
);
+ for (var instance : instances) {
+ instance.setServiceCluster(serviceCluster);
+ }
Set<ServiceCluster> serviceClusterSet = Set.of(serviceCluster);
@@ -250,7 +286,7 @@ public class ClusterApiImplTest {
serviceCluster,
new NodeGroup(application, hostnames.get(0)),
modelUtils.getHostInfos(),
- modelUtils.getClusterControllerClientFactory(), clusterSize);
+ modelUtils.getClusterControllerClientFactory(), clusterSize, clock);
assertEquals(clusterSize - serviceStatusList.size(), clusterApi.missingServices());
assertEquals(clusterSize == serviceStatusList.size(), clusterApi.noServicesOutsideGroupIsDown());
diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ModelTestUtils.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ModelTestUtils.java
index 8162542e540..c4087daeb94 100644
--- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ModelTestUtils.java
+++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ModelTestUtils.java
@@ -13,6 +13,7 @@ import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.applicationmodel.ServiceCluster;
import com.yahoo.vespa.applicationmodel.ServiceInstance;
import com.yahoo.vespa.applicationmodel.ServiceStatus;
+import com.yahoo.vespa.applicationmodel.ServiceStatusInfo;
import com.yahoo.vespa.applicationmodel.ServiceType;
import com.yahoo.vespa.applicationmodel.TenantId;
import com.yahoo.vespa.curator.mock.MockCurator;
@@ -72,9 +73,10 @@ class ModelTestUtils {
new ManualClock(),
applicationApiFactory(),
flagSource);
+ private final ManualClock clock = new ManualClock();
ApplicationApiFactory applicationApiFactory() {
- return new ApplicationApiFactory(NUMBER_OF_CONFIG_SERVERS);
+ return new ApplicationApiFactory(NUMBER_OF_CONFIG_SERVERS, clock);
}
HostInfos getHostInfos() {
@@ -142,21 +144,19 @@ class ModelTestUtils {
ServiceType serviceType,
List<ServiceInstance> serviceInstances) {
Set<ServiceInstance> serviceInstanceSet = new HashSet<>(serviceInstances);
+ var cluster = new ServiceCluster(new ClusterId(clusterId), serviceType, serviceInstanceSet);
+ for (var service : serviceInstanceSet) {
+ service.setServiceCluster(cluster);
+ }
+ return cluster;
+ }
- return new ServiceCluster(
- new ClusterId(clusterId),
- serviceType,
- serviceInstanceSet);
+ ServiceInstance createServiceInstance(String configId, HostName hostName, ServiceStatus status) {
+ return new ServiceInstance(new ConfigId(configId), hostName, status);
}
- ServiceInstance createServiceInstance(
- String configId,
- HostName hostName,
- ServiceStatus status) {
- return new ServiceInstance(
- new ConfigId(configId),
- hostName,
- status);
+ ServiceInstance createServiceInstance(String configId, HostName hostName, ServiceStatusInfo statusInfo) {
+ return new ServiceInstance(new ConfigId(configId), hostName, statusInfo);
}
ClusterControllerClientFactory getClusterControllerClientFactory() {
diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaClusterPolicyTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaClusterPolicyTest.java
index 4462e886d1b..e5be87ba043 100644
--- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaClusterPolicyTest.java
+++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaClusterPolicyTest.java
@@ -3,6 +3,7 @@ package com.yahoo.vespa.orchestrator.policy;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.vespa.applicationmodel.ClusterId;
+import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.applicationmodel.ServiceType;
import com.yahoo.vespa.orchestrator.model.ApplicationApi;
import com.yahoo.vespa.orchestrator.model.ClusterApi;
@@ -11,6 +12,8 @@ import com.yahoo.vespa.orchestrator.model.VespaModelUtil;
import org.junit.Before;
import org.junit.Test;
+import java.util.Optional;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
@@ -71,30 +74,31 @@ public class HostedVespaClusterPolicyTest {
@Test
public void verifyGroupGoingDownIsFine_noServicesOutsideGroupIsDownIsFine() {
- verifyGroupGoingDownIsFine(true, false, 13, true);
+ verifyGroupGoingDownIsFine(true, Optional.empty(), 13, true);
}
@Test
public void verifyGroupGoingDownIsFine_noServicesInGroupIsUp() {
- verifyGroupGoingDownIsFine(false, true, 13, true);
+ 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, false, 9, true);
+ verifyGroupGoingDownIsFine(false, Optional.empty(), 9, true);
}
@Test
public void verifyGroupGoingDownIsFine_fails() {
- verifyGroupGoingDownIsFine(false, false, 13, false);
+ verifyGroupGoingDownIsFine(false, Optional.empty(), 13, false);
}
private void verifyGroupGoingDownIsFine(boolean noServicesOutsideGroupIsDown,
- boolean noServicesInGroupIsUp,
+ Optional<SuspensionReasons> noServicesInGroupIsUp,
int percentageOfServicesDownIfGroupIsAllowedToBeDown,
boolean expectSuccess) {
when(clusterApi.noServicesOutsideGroupIsDown()).thenReturn(noServicesOutsideGroupIsDown);
- when(clusterApi.noServicesInGroupIsUp()).thenReturn(noServicesInGroupIsUp);
+ when(clusterApi.reasonsForNoServicesInGroupIsUp()).thenReturn(noServicesInGroupIsUp);
when(clusterApi.percentageOfServicesDownIfGroupIsAllowedToBeDown()).thenReturn(20);
doReturn(ConcurrentSuspensionLimitForCluster.TEN_PERCENT).when(policy).getConcurrentSuspensionLimit(clusterApi);
@@ -107,12 +111,15 @@ public class HostedVespaClusterPolicyTest {
when(clusterApi.getNodeGroup()).thenReturn(nodeGroup);
when(nodeGroup.toCommaSeparatedString()).thenReturn("node-group");
- when(clusterApi.noServicesInGroupIsUp()).thenReturn(false);
try {
- policy.verifyGroupGoingDownIsFine(clusterApi);
+ SuspensionReasons reasons = policy.verifyGroupGoingDownIsFine(clusterApi);
if (!expectSuccess) {
fail();
}
+
+ if (noServicesInGroupIsUp.isPresent()) {
+ assertEquals(noServicesInGroupIsUp.get().getMessagesInOrder(), reasons.getMessagesInOrder());
+ }
} catch (HostStateChangeDeniedException e) {
if (!expectSuccess) {
assertEquals("Changing the state of node-group would violate enough-services-up: " +
diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaPolicyTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaPolicyTest.java
index ed6917a3a4e..599b50548b7 100644
--- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaPolicyTest.java
+++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/HostedVespaPolicyTest.java
@@ -3,6 +3,7 @@ package com.yahoo.vespa.orchestrator.policy;
import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.test.ManualClock;
import com.yahoo.vespa.applicationmodel.HostName;
import com.yahoo.vespa.orchestrator.OrchestrationException;
import com.yahoo.vespa.orchestrator.OrchestratorContext;
@@ -34,7 +35,8 @@ public class HostedVespaPolicyTest {
private final ClusterControllerClientFactory clientFactory = mock(ClusterControllerClientFactory.class);
private final ClusterControllerClient client = mock(ClusterControllerClient.class);
- private final ApplicationApiFactory applicationApiFactory = new ApplicationApiFactory(3);
+ private final ManualClock clock = new ManualClock();
+ private final ApplicationApiFactory applicationApiFactory = new ApplicationApiFactory(3, clock);
@Before
public void setUp() {
@@ -44,6 +46,7 @@ public class HostedVespaPolicyTest {
@Test
public void testGrantSuspension() throws HostStateChangeDeniedException {
final HostedVespaClusterPolicy clusterPolicy = mock(HostedVespaClusterPolicy.class);
+ when(clusterPolicy.verifyGroupGoingDownIsFine(any())).thenReturn(SuspensionReasons.nothingNoteworthy());
final HostedVespaPolicy policy = new HostedVespaPolicy(clusterPolicy, clientFactory, applicationApiFactory);
final ApplicationApi applicationApi = mock(ApplicationApi.class);
when(applicationApi.applicationId()).thenReturn(ApplicationId.fromSerializedForm("tenant:app:default"));
diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/SuspensionReasonsTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/SuspensionReasonsTest.java
new file mode 100644
index 00000000000..11274dc5d75
--- /dev/null
+++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/policy/SuspensionReasonsTest.java
@@ -0,0 +1,40 @@
+package com.yahoo.vespa.orchestrator.policy;// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+
+import com.yahoo.test.ManualClock;
+import com.yahoo.vespa.applicationmodel.HostName;
+import com.yahoo.vespa.applicationmodel.ServiceInstance;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.time.Instant;
+import java.util.Optional;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+public class SuspensionReasonsTest {
+ private final ManualClock clock = new ManualClock(Instant.ofEpochMilli(1600440708123L));
+ private final ServiceInstance service = mock(ServiceInstance.class);
+ private final ServiceInstance service2 = mock(ServiceInstance.class);
+
+ @Test
+ public void test() {
+ assertEquals(Optional.empty(), new SuspensionReasons().makeLogMessage());
+ assertEquals(Optional.empty(), SuspensionReasons.nothingNoteworthy().makeLogMessage());
+
+ when(service.hostName()).thenReturn(new HostName("host1"));
+ when(service.descriptiveName()).thenReturn("service1");
+ when(service2.hostName()).thenReturn(new HostName("host2"));
+ when(service2.descriptiveName()).thenReturn("service2");
+
+ var reasons = SuspensionReasons.downSince(service, clock.instant(), Duration.ofSeconds(30));
+ reasons.mergeWith(SuspensionReasons.isDown(service2));
+ assertEquals(Optional.of(
+ "host1 suspended because service1 has been down since 2020-09-18T14:51:48Z (30 seconds); " +
+ "host2 suspended because service2 is down"),
+ reasons.makeLogMessage());
+
+ }
+
+} \ No newline at end of file
diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/HostResourceTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/HostResourceTest.java
index 0605fcb8a0a..46346e7de7f 100644
--- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/HostResourceTest.java
+++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/HostResourceTest.java
@@ -32,6 +32,7 @@ import com.yahoo.vespa.orchestrator.model.ApplicationApiFactory;
import com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException;
import com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException;
import com.yahoo.vespa.orchestrator.policy.Policy;
+import com.yahoo.vespa.orchestrator.policy.SuspensionReasons;
import com.yahoo.vespa.orchestrator.restapi.wire.BatchOperationResult;
import com.yahoo.vespa.orchestrator.restapi.wire.GetHostResponse;
import com.yahoo.vespa.orchestrator.restapi.wire.PatchHostRequest;
@@ -83,7 +84,7 @@ public class HostResourceTest {
private static final ServiceMonitor serviceMonitor = mock(ServiceMonitor.class);
private static final StatusService EVERY_HOST_IS_UP_HOST_STATUS_SERVICE = new ZkStatusService(
new MockCurator(), mock(Metric.class), new TestTimer(), new DummyAntiServiceMonitor());
- private static final ApplicationApiFactory applicationApiFactory = new ApplicationApiFactory(3);
+ private static final ApplicationApiFactory applicationApiFactory = new ApplicationApiFactory(3, clock);
static {
when(serviceMonitor.getApplication(any(HostName.class)))
@@ -107,7 +108,8 @@ public class HostResourceTest {
private static class AlwaysAllowPolicy implements Policy {
@Override
- public void grantSuspensionRequest(OrchestratorContext context, ApplicationApi applicationApi) {
+ public SuspensionReasons grantSuspensionRequest(OrchestratorContext context, ApplicationApi applicationApi) {
+ return SuspensionReasons.nothingNoteworthy();
}
@Override
@@ -208,18 +210,18 @@ public class HostResourceTest {
private static class AlwaysFailPolicy implements Policy {
@Override
- public void grantSuspensionRequest(OrchestratorContext context, ApplicationApi applicationApi) throws HostStateChangeDeniedException {
- doThrow();
+ public SuspensionReasons grantSuspensionRequest(OrchestratorContext context, ApplicationApi applicationApi) throws HostStateChangeDeniedException {
+ throw newHostStateChangeDeniedException();
}
@Override
public void releaseSuspensionGrant(OrchestratorContext context, ApplicationApi application) throws HostStateChangeDeniedException {
- doThrow();
+ throw newHostStateChangeDeniedException();
}
@Override
public void acquirePermissionToRemove(OrchestratorContext context, ApplicationApi applicationApi) throws HostStateChangeDeniedException {
- doThrow();
+ throw newHostStateChangeDeniedException();
}
@Override
@@ -227,11 +229,11 @@ public class HostResourceTest {
OrchestratorContext context, ApplicationInstance applicationInstance,
HostName hostName,
ApplicationLock hostStatusRegistry) throws HostStateChangeDeniedException {
- doThrow();
+ throw newHostStateChangeDeniedException();
}
- private static void doThrow() throws HostStateChangeDeniedException {
- throw new HostStateChangeDeniedException(
+ private static HostStateChangeDeniedException newHostStateChangeDeniedException() {
+ return new HostStateChangeDeniedException(
new HostName("some-host"),
"impossible-policy",
"This policy rejects all requests");