diff options
author | Martin Polden <mpolden@mpolden.no> | 2020-11-12 14:56:38 +0100 |
---|---|---|
committer | Martin Polden <mpolden@mpolden.no> | 2020-11-12 16:37:05 +0100 |
commit | 82ddbb814c8bb1339bdb4e9b2cf54482869e1339 (patch) | |
tree | cf3ad546184007a583bc0cf7abdfa630f796181d /controller-server | |
parent | 0bf5758475b7399d7e8502a27093eef5ab8f324a (diff) |
Require valid deployment when changing routing status
Diffstat (limited to 'controller-server')
2 files changed, 26 insertions, 1 deletions
diff --git a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/routing/RoutingApiHandler.java b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/routing/RoutingApiHandler.java index 9e73e9c9747..f26477beb3b 100644 --- a/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/routing/RoutingApiHandler.java +++ b/controller-server/src/main/java/com/yahoo/vespa/hosted/controller/restapi/routing/RoutingApiHandler.java @@ -18,6 +18,7 @@ import com.yahoo.slime.Cursor; import com.yahoo.slime.Slime; import com.yahoo.vespa.hosted.controller.Application; import com.yahoo.vespa.hosted.controller.Controller; +import com.yahoo.vespa.hosted.controller.Instance; import com.yahoo.vespa.hosted.controller.api.application.v4.model.EndpointStatus; import com.yahoo.vespa.hosted.controller.api.identifiers.DeploymentId; import com.yahoo.vespa.hosted.controller.application.TenantAndApplicationId; @@ -203,6 +204,7 @@ public class RoutingApiHandler extends AuditLoggingRequestHandler { var instance = controller.applications().requireInstance(deployment.applicationId()); var status = in ? GlobalRouting.Status.in : GlobalRouting.Status.out; var agent = GlobalRouting.Agent.operator; // Always operator as this is an operator API + requireDeployment(deployment, instance); // Set rotation status, if rotations can route to this zone if (rotationCanRouteTo(deployment.zoneId())) { @@ -238,7 +240,7 @@ public class RoutingApiHandler extends AuditLoggingRequestHandler { .collect(Collectors.toList()) : List.of(zoneId); for (var zone : zones) { - var deploymentId = new DeploymentId(instance.id(), zone); + var deploymentId = requireDeployment(new DeploymentId(instance.id(), zone), instance); // Include status from rotation if (rotationCanRouteTo(zone)) { var rotationStatus = controller.routing().globalRotationStatus(deploymentId); @@ -331,6 +333,13 @@ public class RoutingApiHandler extends AuditLoggingRequestHandler { return zone; } + private static DeploymentId requireDeployment(DeploymentId deployment, Instance instance) { + if (!instance.deployments().containsKey(deployment.zoneId())) { + throw new IllegalArgumentException("No such deployment: " + deployment); + } + return deployment; + } + private static boolean isRecursive(HttpRequest request) { return "true".equals(request.getProperty("recursive")); } diff --git a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/routing/RoutingApiTest.java b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/routing/RoutingApiTest.java index 175d7d3705b..0a9e2dac49e 100644 --- a/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/routing/RoutingApiTest.java +++ b/controller-server/src/test/java/com/yahoo/vespa/hosted/controller/restapi/routing/RoutingApiTest.java @@ -345,6 +345,22 @@ public class RoutingApiTest extends ControllerContainerTest { "{\"error-code\":\"BAD_REQUEST\",\"message\":\"t1.a1 not found\"}", 400); + // GET, DELETE non-existent deployment + var context = deploymentTester.newDeploymentContext(); + var applicationPackage = new ApplicationPackageBuilder() + .region("us-east-3") + .endpoint("default", "default") + .build(); + context.submit(applicationPackage).deploy(); + tester.assertResponse(operatorRequest("http://localhost:8080/routing/v1/status/tenant/tenant/application/application/instance/default/environment/prod/region/us-west-1", + "", Request.Method.GET), + "{\"error-code\":\"BAD_REQUEST\",\"message\":\"No such deployment: tenant.application in prod.us-west-1\"}", + 400); + tester.assertResponse(operatorRequest("http://localhost:8080/routing/v1/inactive/tenant/tenant/application/application/instance/default/environment/prod/region/us-west-1", + "", Request.Method.DELETE), + "{\"error-code\":\"BAD_REQUEST\",\"message\":\"No such deployment: tenant.application in prod.us-west-1\"}", + 400); + // GET non-existent zone tester.assertResponse(operatorRequest("http://localhost:8080/routing/v1/status/environment/prod/region/us-north-1", "", Request.Method.GET), |