aboutsummaryrefslogtreecommitdiffstats
path: root/controller-server
diff options
context:
space:
mode:
authorØyvind Grønnesby <oyving@verizonmedia.com>2019-10-10 09:51:02 +0200
committerGitHub <noreply@github.com>2019-10-10 09:51:02 +0200
commit607c054896d7034175ee2958ebabbfe79038c5a3 (patch)
tree408d8b9eb9ac943021c2c45bd2e2611648adf984 /controller-server
parentbd2a77e32e6138418981c6c202b371811fd08e54 (diff)
parent9ed8162d11b2f1e7042fef2d4a5e030af71948ed (diff)
Merge pull request #10934 from vespa-engine/mpolden/change-status-of-all-endpoints
Change status of all endpoints when overriding global status
Diffstat (limited to 'controller-server')
-rw-r--r--controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java32
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java28
-rw-r--r--controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/global-rotation-get.json2
3 files changed, 32 insertions, 30 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java
index 59c81778890..1dfcafcfa21 100644
--- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java
+++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/ApplicationController.java
@@ -87,6 +87,7 @@ import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -235,35 +236,34 @@ public class ApplicationController {
.orElse(controller.systemVersion());
}
- /** Change the global endpoint status for given deployment */
+ /** Change status of all global endpoints for given deployment */
public void setGlobalRotationStatus(DeploymentId deployment, EndpointStatus status) {
- findGlobalEndpoint(deployment).map(endpoint -> {
+ var globalEndpoints = findGlobalEndpoints(deployment);
+ if (globalEndpoints.isEmpty()) throw new IllegalArgumentException(deployment + " has no global endpoints");
+ globalEndpoints.forEach(endpoint -> {
try {
configServer.setGlobalRotationStatus(deployment, endpoint.upstreamName(), status);
- return endpoint;
} catch (Exception e) {
- throw new RuntimeException("Failed to set rotation status of " + deployment, e);
+ throw new RuntimeException("Failed to set rotation status of " + endpoint + " in " + deployment, e);
}
- }).orElseThrow(() -> new IllegalArgumentException("No global endpoint exists for " + deployment));
+ });
}
/** Get global endpoint status for given deployment */
public Map<RoutingEndpoint, EndpointStatus> globalRotationStatus(DeploymentId deployment) {
- return findGlobalEndpoint(deployment).map(endpoint -> {
- try {
- EndpointStatus status = configServer.getGlobalRotationStatus(deployment, endpoint.upstreamName());
- return Map.of(endpoint, status);
- } catch (Exception e) {
- throw new RuntimeException("Failed to get rotation status of " + deployment, e);
- }
- }).orElseGet(Collections::emptyMap);
+ var routingEndpoints = new LinkedHashMap<RoutingEndpoint, EndpointStatus>();
+ findGlobalEndpoints(deployment).forEach(endpoint -> {
+ var status = configServer.getGlobalRotationStatus(deployment, endpoint.upstreamName());
+ routingEndpoints.put(endpoint, status);
+ });
+ return Collections.unmodifiableMap(routingEndpoints);
}
- /** Find the global endpoint of given deployment, if any */
- private Optional<RoutingEndpoint> findGlobalEndpoint(DeploymentId deployment) {
+ /** Find the global endpoints of given deployment */
+ private List<RoutingEndpoint> findGlobalEndpoints(DeploymentId deployment) {
return routingGenerator.endpoints(deployment).stream()
.filter(RoutingEndpoint::isGlobal)
- .findFirst();
+ .collect(Collectors.toUnmodifiableList());
}
/**
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java
index dad4b80de68..1558656b086 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/ControllerTest.java
@@ -46,6 +46,7 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier;
+import java.util.stream.Collectors;
import static com.yahoo.config.provision.SystemName.main;
import static com.yahoo.vespa.hosted.controller.api.integration.deployment.JobType.component;
@@ -236,29 +237,31 @@ public class ControllerTest {
new RoutingEndpoint("http://old-endpoint.vespa.yahooapis.com:4080", "host1", false, "upstream2"),
new RoutingEndpoint("http://qrs-endpoint.vespa.yahooapis.com:4080", "host1", false, "upstream1"),
new RoutingEndpoint("http://feeding-endpoint.vespa.yahooapis.com:4080", "host2", false, "upstream3"),
+ new RoutingEndpoint("http://global-endpoint-2.vespa.yahooapis.com:4080", "host2", true, "upstream4"),
new RoutingEndpoint("http://global-endpoint.vespa.yahooapis.com:4080", "host1", true, "upstream1"),
new RoutingEndpoint("http://alias-endpoint.vespa.yahooapis.com:4080", "host1", true, "upstream1")
));
- Supplier<Map<RoutingEndpoint, EndpointStatus>> rotationStatus = () -> tester.controller().applications().globalRotationStatus(deployment);
- Function<String, Optional<EndpointStatus>> findStatusByUpstream = (upstreamName) -> {
- return rotationStatus.get()
- .entrySet().stream()
- .filter(kv -> kv.getKey().upstreamName().equals(upstreamName))
- .findFirst()
- .map(Map.Entry::getValue);
+ Supplier<Map<RoutingEndpoint, EndpointStatus>> globalRotationStatus = () -> tester.controller().applications().globalRotationStatus(deployment);
+ Supplier<List<EndpointStatus>> upstreamOneEndpoints = () -> {
+ return globalRotationStatus.get()
+ .entrySet().stream()
+ .filter(kv -> kv.getKey().upstreamName().equals("upstream1"))
+ .map(Map.Entry::getValue)
+ .collect(Collectors.toList());
};
// Check initial rotation status
- assertEquals(1, rotationStatus.get().size());
- assertEquals(findStatusByUpstream.apply("upstream1").get().getStatus(), EndpointStatus.Status.in);
+ assertEquals(3, globalRotationStatus.get().size());
+ assertEquals(2, upstreamOneEndpoints.get().size());
+ assertTrue("All upstreams are in", upstreamOneEndpoints.get().stream().allMatch(es -> es.getStatus() == EndpointStatus.Status.in));
// Set the global rotations out of service
EndpointStatus status = new EndpointStatus(EndpointStatus.Status.out, "unit-test", "Test", tester.clock().instant().getEpochSecond());
tester.controller().applications().setGlobalRotationStatus(deployment, status);
- assertEquals(1, rotationStatus.get().size());
- assertEquals(findStatusByUpstream.apply("upstream1").get().getStatus(), EndpointStatus.Status.out);
- assertEquals("unit-test", findStatusByUpstream.apply("upstream1").get().getReason());
+ assertEquals(2, upstreamOneEndpoints.get().size());
+ assertTrue("All upstreams are out", upstreamOneEndpoints.get().stream().allMatch(es -> es.getStatus() == EndpointStatus.Status.out));
+ assertTrue("Reason is set", upstreamOneEndpoints.get().stream().allMatch(es -> es.getReason().equals("unit-test")));
// Deployment without a global endpoint
tester.serviceRegistry().routingGeneratorMock().putEndpoints(deployment, List.of(
@@ -266,7 +269,6 @@ public class ControllerTest {
new RoutingEndpoint("http://qrs-endpoint.vespa.yahooapis.com:4080", "host1", false, "upstream1"),
new RoutingEndpoint("http://feeding-endpoint.vespa.yahooapis.com:4080", "host2", false, "upstream3")
));
- assertFalse("No global endpoint exists", findStatusByUpstream.apply("upstream1").isPresent());
try {
tester.controller().applications().setGlobalRotationStatus(deployment, status);
fail("Expected exception");
diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/global-rotation-get.json b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/global-rotation-get.json
index 860d6c49cdf..52aabab1584 100644
--- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/global-rotation-get.json
+++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/application/responses/global-rotation-get.json
@@ -1 +1 @@
-{"globalrotationoverride":["upstream1",{"status":"in","reason":"","agent":"","timestamp":1497618757}]}
+{"globalrotationoverride":["upstream1",{"status":"in","reason":"","agent":"","timestamp":1497618757},"upstream1",{"status":"in","reason":"","agent":"","timestamp":1497618757}]}