diff options
author | Morten Tokle <mortent@verizonmedia.com> | 2022-02-14 08:51:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-14 08:51:39 +0100 |
commit | e8a9a133b207a0692909eda2e737be440f3a0849 (patch) | |
tree | e2d97db03c4e91239361c64dd33b574330cb39e0 /configserver | |
parent | 4ea6e26006ec8c3267e7e5c17e6addfeba567c8a (diff) | |
parent | f1d670e03ac8ed0ce4bd37b10448b57f769917d9 (diff) |
Merge pull request #21151 from vespa-engine/mpolden/better-routing-status
Add /routing/v2/status API
Diffstat (limited to 'configserver')
2 files changed, 35 insertions, 0 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v1/RoutingStatusApiHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v1/RoutingStatusApiHandler.java index d9cbc7bc533..569ed1525b2 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v1/RoutingStatusApiHandler.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v1/RoutingStatusApiHandler.java @@ -63,6 +63,7 @@ public class RoutingStatusApiHandler extends RestApiRequestHandler<RoutingStatus private static RestApi createRestApiDefinition(RoutingStatusApiHandler self) { return RestApi.builder() + // TODO(mpolden): Remove this route when clients have migrated to v2 .addRoute(RestApi.route("/routing/v1/status") .get(self::listInactiveDeployments)) .addRoute(RestApi.route("/routing/v1/status/zone") @@ -72,9 +73,27 @@ public class RoutingStatusApiHandler extends RestApiRequestHandler<RoutingStatus .addRoute(RestApi.route("/routing/v1/status/{upstreamName}") .get(self::getDeploymentStatus) .put(self::changeDeploymentStatus)) + .addRoute(RestApi.route("/routing/v2/status") + .get(self::getDeploymentStatusV2)) .build(); } + /* Get inactive deployments and zone status */ + private SlimeJsonResponse getDeploymentStatusV2(RestApi.RequestContext context) { + Slime slime = new Slime(); + Cursor root = slime.setObject(); + Cursor inactiveDeploymentsArray = root.setArray("inactiveDeployments"); + curator.getChildren(DEPLOYMENT_STATUS_ROOT).stream() + .filter(upstreamName -> deploymentStatus(upstreamName).status() == RoutingStatus.out) + .sorted() + .forEach(upstreamName -> { + Cursor deploymentObject = inactiveDeploymentsArray.addObject(); + deploymentObject.setString("upstreamName", upstreamName); + }); + root.setBool("zoneActive", zoneStatus() == RoutingStatus.in); + return new SlimeJsonResponse(slime); + } + /** Get upstream of all deployments with status OUT */ private SlimeJsonResponse listInactiveDeployments(RestApi.RequestContext context) { List<String> inactiveDeployments = curator.getChildren(DEPLOYMENT_STATUS_ROOT).stream() diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v1/RoutingStatusApiHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v1/RoutingStatusApiHandlerTest.java index e2b45d33cbc..f389829a160 100644 --- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v1/RoutingStatusApiHandlerTest.java +++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v1/RoutingStatusApiHandlerTest.java @@ -62,6 +62,22 @@ public class RoutingStatusApiHandlerTest { } @Test + public void get_deployment_status_v2() { + String response = responseAsString(executeRequest(Method.GET, "/routing/v2/status/", null)); + assertEquals("{\"inactiveDeployments\":[],\"zoneActive\":true}", response); + + // Set deployment out + executeRequest(Method.PUT, "/routing/v1/status/" + upstreamName + "?application=" + instance.serializedForm(), statusOut()); + response = responseAsString(executeRequest(Method.GET, "/routing/v2/status/", null)); + assertEquals("{\"inactiveDeployments\":[{\"upstreamName\":\"test-upstream-name\"}],\"zoneActive\":true}", response); + + // Set zone out + executeRequest(Method.PUT, "/routing/v1/status/zone", null); + response = responseAsString(executeRequest(Method.GET, "/routing/v2/status/", null)); + assertEquals("{\"inactiveDeployments\":[{\"upstreamName\":\"test-upstream-name\"}],\"zoneActive\":false}", response); + } + + @Test public void set_deployment_status() { String response = responseAsString(executeRequest(Method.PUT, "/routing/v1/status/" + upstreamName + "?application=" + instance.serializedForm(), statusOut())); |