aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Marius Venstad <venstad@gmail.com>2021-04-30 13:16:39 +0200
committerJon Marius Venstad <venstad@gmail.com>2021-04-30 13:16:39 +0200
commit44f7c2dc80a1dff60226119c549695e9a2cae369 (patch)
tree2ca1334df45d7eea6dfb35d99fc875762c92b732
parent3f18254fe2428c5a3dfd5c014daf09e025003c80 (diff)
Revert "Merge pull request #17664 from vespa-engine/revert-17658-jonmv/rest-api-bindings-without-trailing-slash"
This reverts commit 9de25e274dbec90a81d9fc107a429dc275c76deb, reversing changes made to 2a8254e4a8e61916974016a6d9933cd406443096.
-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, 25 insertions, 36 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 6aff3b8a361..9063c5137ef 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,6 +93,7 @@ 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/*");
}
@@ -103,7 +104,7 @@ public class TenantHandler extends HttpHandler {
private static boolean isListTenantsRequest(HttpRequest request) {
return getBindingMatch(request).groupCount() == 2 &&
- request.getUri().getPath().endsWith("/tenant/");
+ request.getUri().getPath().matches("/application/v2/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 fd8bda8f305..73aa5db98e4 100644
--- a/configserver/src/main/resources/configserver-app/services.xml
+++ b/configserver/src/main/resources/configserver-app/services.xml
@@ -102,8 +102,7 @@
<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 b0b01ea24b4..e7723f75ffc 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,6 +102,9 @@ 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 028d0d69df6..64bcaf15a69 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 a12e2a8b11c..8a6e466fdf3 100644
--- a/node-repository/src/main/config/node-repository.xml
+++ b/node-repository/src/main/config/node-repository.xml
@@ -14,6 +14,7 @@
</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 f81e3240397..e73f97304c1 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,53 +1,37 @@
// 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.ErrorResponse;
-import com.yahoo.vespa.hosted.provision.NoSuchNodeException;
+import com.yahoo.restapi.RestApi;
+import com.yahoo.restapi.RestApiRequestHandler;
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 LoggingRequestHandler {
+public class LoadBalancersV1ApiHandler extends RestApiRequestHandler<LoadBalancersV1ApiHandler> {
private final NodeRepository nodeRepository;
@Inject
public LoadBalancersV1ApiHandler(LoggingRequestHandler.Context parentCtx, NodeRepository nodeRepository) {
- super(parentCtx);
+ super(parentCtx, LoadBalancersV1ApiHandler::createRestApiDefinition);
this.nodeRepository = nodeRepository;
}
- @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 static RestApi createRestApiDefinition(LoadBalancersV1ApiHandler self) {
+ return RestApi.builder()
+ .addRoute(RestApi.route("/loadbalancers/v1")
+ .get(self::getLoadBalancers))
+ .build();
}
- 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 + "'");
+ private HttpResponse getLoadBalancers(RestApi.RequestContext context) {
+ return new LoadBalancersResponse(context.request(), nodeRepository);
}
+
}
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 5e40c0bd9ff..ebaf4d47887 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 e9811985b7d..1ca552bca94 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,6 +22,7 @@ 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\":[]}");