This is an automated email from the ASF dual-hosted git repository. uce pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/flink.git
commit 77231de60683753382ec8299a2a5d311e08b24e7 Author: Ufuk Celebi <[email protected]> AuthorDate: Tue May 28 09:29:48 2024 +0200 [FLINK-26808][rest] Factor out getHandlerRoutes(RestHandlerSpecification) --- .../flink/runtime/rest/RestServerEndpoint.java | 39 ++++++++++------------ 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java index 004cb8106ec..817e25521d8 100644 --- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java @@ -513,35 +513,17 @@ public abstract class RestServerEndpoint implements RestService { Router router, Tuple2<RestHandlerSpecification, ChannelInboundHandler> specificationHandler, Logger log) { - final String handlerURL = specificationHandler.f0.getTargetRestEndpointURL(); - // setup versioned urls - for (final RestAPIVersion supportedVersion : - specificationHandler.f0.getSupportedAPIVersions()) { - final String versionedHandlerURL = - '/' + supportedVersion.getURLVersionPrefix() + handlerURL; + for (String route : getHandlerRoutes(specificationHandler.f0)) { log.debug( "Register handler {} under {}@{}.", specificationHandler.f1, specificationHandler.f0.getHttpMethod(), - versionedHandlerURL); + route); registerHandler( router, - versionedHandlerURL, + route, specificationHandler.f0.getHttpMethod(), specificationHandler.f1); - if (supportedVersion.isDefaultVersion()) { - // setup unversioned url for convenience and backwards compatibility - log.debug( - "Register handler {} under {}@{}.", - specificationHandler.f1, - specificationHandler.f0.getHttpMethod(), - handlerURL); - registerHandler( - router, - handlerURL, - specificationHandler.f0.getHttpMethod(), - specificationHandler.f1); - } } } @@ -653,6 +635,21 @@ public abstract class RestServerEndpoint implements RestService { } } + private static Iterable<String> getHandlerRoutes(RestHandlerSpecification handlerSpec) { + final List<String> registeredRoutes = new ArrayList<>(); + final String handlerUrl = handlerSpec.getTargetRestEndpointURL(); + for (RestAPIVersion<?> supportedVersion : handlerSpec.getSupportedAPIVersions()) { + String versionedUrl = '/' + supportedVersion.getURLVersionPrefix() + handlerUrl; + registeredRoutes.add(versionedUrl); + + if (supportedVersion.isDefaultVersion()) { + // Unversioned URL for convenience and backwards compatibility + registeredRoutes.add(handlerUrl); + } + } + return registeredRoutes; + } + /** * Comparator for Rest URLs. *
