aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHarald Musum <musum@verizonmedia.com>2021-04-29 16:48:30 +0200
committerGitHub <noreply@github.com>2021-04-29 16:48:30 +0200
commit6e8b76060ae6ef2b9b07377a4c18de40ecd754f9 (patch)
treebc9b038646f10c74cea284976404055e33cc1fb2
parent2a8254e4a8e61916974016a6d9933cd406443096 (diff)
Revert "Support loadbalancer/v1 and application/v2/tenant without trailing slash"
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantHandler.java3
-rw-r--r--configserver/src/main/resources/configserver-app/services.xml3
-rw-r--r--configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java3
-rw-r--r--jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingSetTestCase.java4
-rw-r--r--node-repository/src/main/config/node-repository.xml1
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiHandler.java42
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java4
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java1
8 files changed, 36 insertions, 25 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantHandler.java b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantHandler.java
index 9063c5137ef..6aff3b8a361 100644
--- a/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantHandler.java
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/http/v2/TenantHandler.java
@@ -93,7 +93,6 @@ public class TenantHandler extends HttpHandler {
private static BindingMatch<?> getBindingMatch(HttpRequest request) {
return HttpConfigRequests.getBindingMatch(request,
- "http://*/application/v2/tenant",
"http://*/application/v2/tenant/",
"http://*/application/v2/tenant/*");
}
@@ -104,7 +103,7 @@ public class TenantHandler extends HttpHandler {
private static boolean isListTenantsRequest(HttpRequest request) {
return getBindingMatch(request).groupCount() == 2 &&
- request.getUri().getPath().matches("/application/v2/tenant/?");
+ request.getUri().getPath().endsWith("/tenant/");
}
private static TenantName getTenantNameFromRequest(HttpRequest request) {
diff --git a/configserver/src/main/resources/configserver-app/services.xml b/configserver/src/main/resources/configserver-app/services.xml
index 73aa5db98e4..fd8bda8f305 100644
--- a/configserver/src/main/resources/configserver-app/services.xml
+++ b/configserver/src/main/resources/configserver-app/services.xml
@@ -102,7 +102,8 @@
<binding>http://*/status</binding>
</handler>
<handler id='com.yahoo.vespa.config.server.http.v2.TenantHandler' bundle='configserver'>
- <binding>http://*/application/v2/tenant*</binding>
+ <binding>http://*/application/v2/tenant/</binding>
+ <binding>http://*/application/v2/tenant/*</binding>
</handler>
<handler id='com.yahoo.vespa.config.server.http.v2.SessionCreateHandler' bundle='configserver'>
<binding>http://*/application/v2/tenant/*/session</binding>
diff --git a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java
index e7723f75ffc..b0b01ea24b4 100644
--- a/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java
+++ b/configserver/src/test/java/com/yahoo/vespa/config/server/http/v2/TenantHandlerTest.java
@@ -102,9 +102,6 @@ public class TenantHandlerTest {
assertResponseEquals((ListTenantsResponse) handler.handleGET(
HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant/", Method.GET)),
"{\"tenants\":[\"default\",\"a\"]}");
- assertResponseEquals((ListTenantsResponse) handler.handleGET(
- HttpRequest.createTestRequest("http://deploy.example.yahoo.com:80/application/v2/tenant", Method.GET)),
- "{\"tenants\":[\"default\",\"a\"]}");
}
@Test(expected=BadRequestException.class)
diff --git a/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingSetTestCase.java b/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingSetTestCase.java
index 64bcaf15a69..028d0d69df6 100644
--- a/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingSetTestCase.java
+++ b/jdisc_core/src/test/java/com/yahoo/jdisc/application/BindingSetTestCase.java
@@ -249,7 +249,7 @@ public class BindingSetTestCase {
handlers.put(new UriPattern("http://*/config/v1/*/"), foo1);
handlers.put(new UriPattern("http://*/config/v1/*/*"), foo2);
handlers.put(new UriPattern("http://*/config/v1/*/*/"), foo3);
- handlers.put(new UriPattern("http://*/application/v2/tenant*"), foo4);
+ handlers.put(new UriPattern("http://*/application/v2/tenant/"), foo4);
handlers.put(new UriPattern("http://*/application/v2/tenant/*"), foo5);
handlers.put(new UriPattern("http://*/application/v2/tenant/*/session"), foo6);
handlers.put(new UriPattern("http://*/application/v2/tenant/*/session/*/prepared"), foo7);
@@ -276,7 +276,7 @@ public class BindingSetTestCase {
assertSame(foo3, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" +
"/config/v1/cloud.config.log.logd/admin/")));
assertSame(foo4, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" +
- "/application/v2/tenant")));
+ "/application/v2/tenant/")));
assertSame(foo5, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" +
"/application/v2/tenant/b")));
assertSame(foo6, bindings.resolve(URI.create("http://abcxyz.yahoo.com:19071" +
diff --git a/node-repository/src/main/config/node-repository.xml b/node-repository/src/main/config/node-repository.xml
index 8a6e466fdf3..a12e2a8b11c 100644
--- a/node-repository/src/main/config/node-repository.xml
+++ b/node-repository/src/main/config/node-repository.xml
@@ -14,7 +14,6 @@
</handler>
<handler id="com.yahoo.vespa.hosted.provision.restapi.LoadBalancersV1ApiHandler" bundle="node-repository">
- <binding>http://*/loadbalancers/v1</binding>
<binding>http://*/loadbalancers/v1/*</binding>
</handler>
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiHandler.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiHandler.java
index e73f97304c1..f81e3240397 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiHandler.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiHandler.java
@@ -1,37 +1,53 @@
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.provision.restapi;
+import com.yahoo.container.jdisc.HttpRequest;
import com.yahoo.container.jdisc.HttpResponse;
import com.yahoo.container.jdisc.LoggingRequestHandler;
-import com.yahoo.restapi.RestApi;
-import com.yahoo.restapi.RestApiRequestHandler;
+import com.yahoo.restapi.ErrorResponse;
+import com.yahoo.vespa.hosted.provision.NoSuchNodeException;
import com.yahoo.vespa.hosted.provision.NodeRepository;
+import com.yahoo.yolean.Exceptions;
import javax.inject.Inject;
+import java.util.logging.Level;
/**
* @author mpolden
- * @author jonmv
*/
-public class LoadBalancersV1ApiHandler extends RestApiRequestHandler<LoadBalancersV1ApiHandler> {
+public class LoadBalancersV1ApiHandler extends LoggingRequestHandler {
private final NodeRepository nodeRepository;
@Inject
public LoadBalancersV1ApiHandler(LoggingRequestHandler.Context parentCtx, NodeRepository nodeRepository) {
- super(parentCtx, LoadBalancersV1ApiHandler::createRestApiDefinition);
+ super(parentCtx);
this.nodeRepository = nodeRepository;
}
- private static RestApi createRestApiDefinition(LoadBalancersV1ApiHandler self) {
- return RestApi.builder()
- .addRoute(RestApi.route("/loadbalancers/v1")
- .get(self::getLoadBalancers))
- .build();
+ @Override
+ public HttpResponse handle(HttpRequest request) {
+ try {
+ switch (request.getMethod()) {
+ case GET: return handleGET(request);
+ default: return ErrorResponse.methodNotAllowed("Method '" + request.getMethod() + "' is not supported");
+ }
+ }
+ catch (NotFoundException | NoSuchNodeException e) {
+ return ErrorResponse.notFoundError(Exceptions.toMessageString(e));
+ }
+ catch (IllegalArgumentException e) {
+ return ErrorResponse.badRequest(Exceptions.toMessageString(e));
+ }
+ catch (RuntimeException e) {
+ log.log(Level.WARNING, "Unexpected error handling '" + request.getUri() + "'", e);
+ return ErrorResponse.internalServerError(Exceptions.toMessageString(e));
+ }
}
- private HttpResponse getLoadBalancers(RestApi.RequestContext context) {
- return new LoadBalancersResponse(context.request(), nodeRepository);
+ private HttpResponse handleGET(HttpRequest request) {
+ String path = request.getUri().getPath();
+ if (path.equals("/loadbalancers/v1/")) return new LoadBalancersResponse(request, nodeRepository);
+ throw new NotFoundException("Nothing at path '" + path + "'");
}
-
}
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java
index ebaf4d47887..5e40c0bd9ff 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/testutils/ContainerConfig.java
@@ -33,10 +33,10 @@ public class ContainerConfig {
" <component id='com.yahoo.vespa.flags.InMemoryFlagSource'/>\n" +
" <component id='com.yahoo.config.provision.Zone'/>\n" +
" <handler id='com.yahoo.vespa.hosted.provision.restapi.NodesV2ApiHandler'>\n" +
- " <binding>http://*/nodes/v2*</binding>\n" +
+ " <binding>http://*/nodes/v2/*</binding>\n" +
" </handler>\n" +
" <handler id='com.yahoo.vespa.hosted.provision.restapi.LoadBalancersV1ApiHandler'>\n" +
- " <binding>http://*/loadbalancers/v1*</binding>\n" +
+ " <binding>http://*/loadbalancers/v1/*</binding>\n" +
" </handler>\n" +
" <http>\n" +
" <server id='myServer' port='" + port + "'/>\n" +
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java
index 1ca552bca94..e9811985b7d 100644
--- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/LoadBalancersV1ApiTest.java
@@ -22,7 +22,6 @@ public class LoadBalancersV1ApiTest {
@Test
public void test_load_balancers() throws Exception {
- tester.assertFile(new Request("http://localhost:8080/loadbalancers/v1"), "load-balancers.json");
tester.assertFile(new Request("http://localhost:8080/loadbalancers/v1/"), "load-balancers.json");
tester.assertFile(new Request("http://localhost:8080/loadbalancers/v1/?application=tenant4.application4.instance4"), "load-balancers-single.json");
tester.assertResponse(new Request("http://localhost:8080/loadbalancers/v1/?application=tenant.nonexistent.default"), "{\"loadBalancers\":[]}");