-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Drop legacy results api #21772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Drop legacy results api #21772
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
presto-main/src/main/java/com/facebook/presto/server/AsyncPageTransportForwardFilter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.facebook.presto.server; | ||
|
|
||
| import javax.servlet.Filter; | ||
| import javax.servlet.FilterChain; | ||
| import javax.servlet.FilterConfig; | ||
| import javax.servlet.ServletException; | ||
| import javax.servlet.ServletRequest; | ||
| import javax.servlet.ServletResponse; | ||
| import javax.servlet.http.HttpServletRequest; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| /** | ||
| * It is not possible to map the {@link AsyncPageTransportServlet} to "/v1/task/<taskid>/results/*" directly. | ||
| * Servlet pattern matching doesn't allow arbitrary globbing (e.g.: /v1/task/*\/results/*). | ||
| * Only prefix or suffix matching is allowed (e.g.: /v1/task/*, *\/suffix). | ||
| * Hence a more nuanced matching and a forward is required. | ||
| */ | ||
| public class AsyncPageTransportForwardFilter | ||
| implements Filter | ||
| { | ||
| private static final String GET_RESULTS_URL_PREFIX = "/v1/task"; | ||
| private static final Pattern GET_RESULTS_URL_PATTERN = Pattern.compile("/v1/task/[^/]+/results/[^/]+/[^/]+/?"); | ||
| private static final String GET_RESULTS_METHOD = "GET"; | ||
| private static final String GET_RESULTS_URL_FORWARD_PREFIX = "/v1/task/async"; | ||
|
|
||
| @Override | ||
| public void init(FilterConfig filterConfig) {} | ||
|
|
||
| @Override | ||
| public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) | ||
| throws IOException, ServletException | ||
| { | ||
| HttpServletRequest httpRequest = (HttpServletRequest) request; | ||
| String requestUri = httpRequest.getRequestURI(); | ||
| if (isGetResultsRequest(httpRequest.getRequestURI(), httpRequest.getMethod())) { | ||
| String forwardUri = GET_RESULTS_URL_FORWARD_PREFIX + requestUri.substring(GET_RESULTS_URL_PREFIX.length()); | ||
| httpRequest.getRequestDispatcher(forwardUri).forward(request, response); | ||
| } | ||
| else { | ||
| chain.doFilter(request, response); | ||
| } | ||
| } | ||
|
|
||
| private boolean isGetResultsRequest(String uri, String method) | ||
| { | ||
| if (!GET_RESULTS_METHOD.equals(method)) { | ||
| return false; | ||
| } | ||
| if (!uri.startsWith(GET_RESULTS_URL_PREFIX)) { | ||
| return false; | ||
| } | ||
| return GET_RESULTS_URL_PATTERN.matcher(uri).matches(); | ||
| } | ||
|
|
||
| @Override | ||
| public void destroy() {} | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just implement the rename in one shot, as opposed to forwarding
/v1/taskto/v1/task/async? i.e. why not just use/v1/taskand remove this filter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then all the requests starting with
/v1/taskwill be routed to the custom servlet, while requests other than/v1/task*/results/*have to be routed toTaskResourceThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't think of a better way of doing it.