From 34a14790cc5b780a5322ee071d20eab948a7bb89 Mon Sep 17 00:00:00 2001 From: Jake Landis Date: Fri, 27 Sep 2024 12:38:10 -0500 Subject: [PATCH] fix tests and nits --- .../elasticsearch/rest/RestController.java | 38 ++++++++++++------- .../org/elasticsearch/rest/RestHandler.java | 2 +- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/rest/RestController.java b/server/src/main/java/org/elasticsearch/rest/RestController.java index f97c8820bb426..3bce4ae922737 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestController.java +++ b/server/src/main/java/org/elasticsearch/rest/RestController.java @@ -163,20 +163,22 @@ protected void registerAsDeprecatedHandler( Level deprecationLevel ) { assert (handler instanceof DeprecationRestHandler) == false; - registerHandler( - method, - path, - version, - new DeprecationRestHandler( - handler, + if (RestApiVersion.onOrAfter(RestApiVersion.minimumSupported()).test(version)) { + registerHandler( method, path, - deprecationLevel, - deprecationMessage, - deprecationLogger, - version != RestApiVersion.current() - ) - ); + version, + new DeprecationRestHandler( + handler, + method, + path, + deprecationLevel, + deprecationMessage, + deprecationLogger, + version != RestApiVersion.current() + ) + ); + } } /** @@ -237,7 +239,15 @@ protected void registerHandler(RestRequest.Method method, String path, RestApiVe private void registerHandlerNoWrap(RestRequest.Method method, String path, RestApiVersion version, RestHandler handler) { assert RestApiVersion.minimumSupported() == version || RestApiVersion.current() == version - : "REST API compatibility is only supported for version " + RestApiVersion.minimumSupported().major; + : "REST API compatibility is only supported for version " + + RestApiVersion.minimumSupported().major + + " [method=" + + method + + ", path=" + + path + + ", handler=" + + handler.getClass().getCanonicalName() + + "]"; if (RESERVED_PATHS.contains(path)) { throw new IllegalArgumentException("path [" + path + "] is a reserved path and may not be registered"); @@ -252,7 +262,7 @@ private void registerHandlerNoWrap(RestRequest.Method method, String path, RestA } public void registerHandler(final Route route, final RestHandler handler) { - if (route.isReplacement()) { + if (route.hasReplacement()) { Route replaced = route.getReplacedRoute(); registerAsReplacedHandler( route.getMethod(), diff --git a/server/src/main/java/org/elasticsearch/rest/RestHandler.java b/server/src/main/java/org/elasticsearch/rest/RestHandler.java index 99584171c7667..e8b843facef17 100644 --- a/server/src/main/java/org/elasticsearch/rest/RestHandler.java +++ b/server/src/main/java/org/elasticsearch/rest/RestHandler.java @@ -343,7 +343,7 @@ public Route getReplacedRoute() { return replacedRoute; } - public boolean isReplacement() { + public boolean hasReplacement() { return replacedRoute != null; } }