Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id DD70B200D35 for ; Tue, 7 Nov 2017 15:21:07 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id DA473160BED; Tue, 7 Nov 2017 14:21:07 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 2AE1E1609C8 for ; Tue, 7 Nov 2017 15:21:07 +0100 (CET) Received: (qmail 39985 invoked by uid 500); 7 Nov 2017 14:21:06 -0000 Mailing-List: contact issues-help@flink.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@flink.apache.org Delivered-To: mailing list issues@flink.apache.org Received: (qmail 39976 invoked by uid 99); 7 Nov 2017 14:21:06 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 07 Nov 2017 14:21:06 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 56828C5EC4 for ; Tue, 7 Nov 2017 14:21:05 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -100.002 X-Spam-Level: X-Spam-Status: No, score=-100.002 tagged_above=-999 required=6.31 tests=[RP_MATCHES_RCVD=-0.001, SPF_PASS=-0.001, USER_IN_WHITELIST=-100] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 5wWVqRlLKWyZ for ; Tue, 7 Nov 2017 14:21:04 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with ESMTP id 70E845FCDA for ; Tue, 7 Nov 2017 14:21:03 +0000 (UTC) Received: from jira-lw-us.apache.org (unknown [207.244.88.139]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 98F98E0EFC for ; Tue, 7 Nov 2017 14:21:02 +0000 (UTC) Received: from jira-lw-us.apache.org (localhost [127.0.0.1]) by jira-lw-us.apache.org (ASF Mail Server at jira-lw-us.apache.org) with ESMTP id B694A241A6 for ; Tue, 7 Nov 2017 14:21:01 +0000 (UTC) Date: Tue, 7 Nov 2017 14:21:01 +0000 (UTC) From: "ASF GitHub Bot (JIRA)" To: issues@flink.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FLINK-8000) Sort REST handler URLs in RestServerEndpoint MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 archived-at: Tue, 07 Nov 2017 14:21:08 -0000 [ https://issues.apache.org/jira/browse/FLINK-8000?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16242081#comment-16242081 ] ASF GitHub Bot commented on FLINK-8000: --------------------------------------- Github user tillrohrmann commented on a diff in the pull request: https://github.com/apache/flink/pull/4958#discussion_r149379485 --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java --- @@ -268,4 +287,69 @@ private static void registerHandler(Router router, Tuple2The comparator orders the Rest URLs such that URLs with path parameters are ordered behind + * those without parameters. E.g.: + * /jobs + * /jobs/overview + * /jobs/:jobid + * /jobs/:jobid/config + * /:* + * + *

IMPORTANT: This comparator is highly specific to how Netty path parameter are encoded. Namely + * via a preceding ':' character. + */ + static final class RestHandlerUrlComparator implements Comparator>, Serializable { + + private static final long serialVersionUID = 2388466767835547926L; + + private static final Comparator CASE_INSENSITIVE_ORDER = new CaseInsensitiveOrderComparator(); + + static final RestHandlerUrlComparator INSTANCE = new RestHandlerUrlComparator(); + + @Override + public int compare( + Tuple2 o1, + Tuple2 o2) { + return CASE_INSENSITIVE_ORDER.compare(o1.f0.getTargetRestEndpointURL(), o2.f0.getTargetRestEndpointURL()); + } + + static final class CaseInsensitiveOrderComparator implements Comparator, Serializable { + private static final long serialVersionUID = 8550835445193437027L; + + @Override + public int compare(String s1, String s2) { + int n1 = s1.length(); + int n2 = s2.length(); + int min = Math.min(n1, n2); + for (int i = 0; i < min; i++) { + char c1 = s1.charAt(i); + char c2 = s2.charAt(i); + if (c1 != c2) { + c1 = Character.toUpperCase(c1); + c2 = Character.toUpperCase(c2); + if (c1 != c2) { + c1 = Character.toLowerCase(c1); --- End diff -- That's how the `String#compareToIgnoreCase` is implemented. I assume that this is due to a note in `Character.toUpperCase` and `Character.toLowerCase` ``` *

Note that * {@code Character.isUpperCase(Character.toUpperCase(codePoint))} * does not always return {@code true} for some ranges of * characters, particularly those that are symbols or ideographs. ``` > Sort REST handler URLs in RestServerEndpoint > -------------------------------------------- > > Key: FLINK-8000 > URL: https://issues.apache.org/jira/browse/FLINK-8000 > Project: Flink > Issue Type: Improvement > Components: REST > Affects Versions: 1.4.0 > Reporter: Till Rohrmann > Assignee: Till Rohrmann > Priority: Minor > Labels: flip-6 > > In order to make the {{RestServerEndpoint}} more easily extendable, we should automatically sort the returned list of rest handler when calling {{RestServerEndpoint#initializeHandlers}}. That way the order in which the handlers are added to the list is independent of the actual registration order. This is, for example, important for the static file server which always needs to be registered last. > I propose to add a special {{String}} {{Comparator}} which considers the charactor {{':'}} to be the character with the largest value. That way we should get always the following sort order: > - URLs without path parameters have precedence over similar URLs where parts are replaced by path parameters (e.g. {{/jobs/overview}}, {{/jobs/:jobid}} and {{/jobs/:jobid/config}}, {{/jobs/:jobid/vertices/:vertexId}}) > - Prefixes are sorted before URLs containing the prefix (e.g. {{/jobs}}, {{/jobs/overview}}) -- This message was sent by Atlassian JIRA (v6.4.14#64029)