{"action":"created","comment":{"url":"https://api.github.com/repos/apache/flink/pulls/comments/134686921","pull_request_review_id":58005594,"id":134686921,"diff_hunk":"@@ -0,0 +1,121 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the License.  You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.flink.runtime.rest.handler;\n+\n+import org.apache.flink.runtime.rest.messages.ResponseBody;\n+import org.apache.flink.util.Preconditions;\n+\n+import org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpResponseStatus;\n+\n+import javax.annotation.Nonnull;\n+\n+/**\n+ * Simple container for the response of a handler, that contains either a response of type {@code P} if the incoming\n+ * request was handled successfully, otherwise it contains an error message and an associated error code.\n+ *\n+ * @param <P> type of successful response\n+ */\n+public final class HandlerResponse<P extends ResponseBody> {","path":"flink-runtime/src/main/java/org/apache/flink/runtime/rest/handler/HandlerResponse.java","position":34,"original_position":34,"commit_id":"9763c95750a12810223f0ccaa0c7ca169a645d5c","original_commit_id":"61988d8060dab1084b29c61f40cee356783cb8b5","user":{"login":"kl0u","id":2405800,"avatar_url":"https://avatars3.githubusercontent.com/u/2405800?v=4","gravatar_id":"","url":"https://api.github.com/users/kl0u","html_url":"https://github.com/kl0u","followers_url":"https://api.github.com/users/kl0u/followers","following_url":"https://api.github.com/users/kl0u/following{/other_user}","gists_url":"https://api.github.com/users/kl0u/gists{/gist_id}","starred_url":"https://api.github.com/users/kl0u/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kl0u/subscriptions","organizations_url":"https://api.github.com/users/kl0u/orgs","repos_url":"https://api.github.com/users/kl0u/repos","events_url":"https://api.github.com/users/kl0u/events{/privacy}","received_events_url":"https://api.github.com/users/kl0u/received_events","type":"User","site_admin":false},"body":"I think it would also be nice to allow the user to be able to specify a callback in the response which will be called when the response has been fully sent in the network. The reason for this is to be able to update metrics like \"how long did the transfer take?\" or \"what is the progress so far (for big messages)\". This would require adding the callback in the `HandlerResponse` which implements the `ChannelFutureListener` and in the `AbstractRestHandler.sendResponse()` register that listener with the `lastContentFuture`, if I understand correctly.\r\n","created_at":"2017-08-23T08:25:31Z","updated_at":"2017-08-23T08:25:31Z","html_url":"https://github.com/apache/flink/pull/4569#discussion_r134686921","pull_request_url":"https://api.github.com/repos/apache/flink/pulls/4569","_links":{"self":{"href":"https://api.github.com/repos/apache/flink/pulls/comments/134686921"},"html":{"href":"https://github.com/apache/flink/pull/4569#discussion_r134686921"},"pull_request":{"href":"https://api.github.com/repos/apache/flink/pulls/4569"}}},"pull_request":{"url":"https://api.github.com/repos/apache/flink/pulls/4569","id":136772955,"html_url":"https://github.com/apache/flink/pull/4569","diff_url":"https://github.com/apache/flink/pull/4569.diff","patch_url":"https://github.com/apache/flink/pull/4569.patch","issue_url":"https://api.github.com/repos/apache/flink/issues/4569","number":4569,"state":"open","locked":false,"title":"[FLINK-7040] [REST] Add basics for REST communication","user":{"login":"zentol","id":5725237,"avatar_url":"https://avatars1.githubusercontent.com/u/5725237?v=4","gravatar_id":"","url":"https://api.github.com/users/zentol","html_url":"https://github.com/zentol","followers_url":"https://api.github.com/users/zentol/followers","following_url":"https://api.github.com/users/zentol/following{/other_user}","gists_url":"https://api.github.com/users/zentol/gists{/gist_id}","starred_url":"https://api.github.com/users/zentol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zentol/subscriptions","organizations_url":"https://api.github.com/users/zentol/orgs","repos_url":"https://api.github.com/users/zentol/repos","events_url":"https://api.github.com/users/zentol/events{/privacy}","received_events_url":"https://api.github.com/users/zentol/received_events","type":"User","site_admin":false},"body":"## What is the purpose of the change\r\n\r\nThis PR implements the fundamentals for generic Client/Server REST communication that will be used for the client/cluster communication, the WebRuntimeMonitor and queryable state.\r\n\r\n#### Endpoints\r\n\r\n`Endpoints` are the main runtime component that have to be started before any communication can happen. Their primary purpose is setting up the underlying netty stack.\r\n\r\nThe `RestClientEndpoint` is a fully-functional class that provides an asynchronous API for sending requests/receiving responses based around `CompleteFutures`. Requests are sent in a synchronous fashion; a new request is only sent out after a response was received for the previous request (for simplicity).\r\n\r\nThe `RestServerEndpoint` is an abstract class that is very similar to the `WebRuntimeMonitor`. Implementations have to implement a single method `abstract Collection<? extends AbstractRestHandler<?, ?>> initializeHandlers();` that returns a collection of handlers that should be registered.\r\n\r\n#### Messages\r\n\r\nTo send a request the client accepts 3 arguments:\r\n* a `MessageHeaders`\r\n* a `RequestBody`\r\n* a `ParameterMapper`\r\n\r\n`RequestBodies` represent the http message body, and will be converted to JSON using jackson-databind.\r\n\r\n`ParameterMappers` are used to assemble the final url, including query and path parameters\r\n\r\n`MessageHeaders` are stateless objects that define a link between requests and responses as well as provide meta-data about the communication for this particular pair. Headers have generic type arguments for requests and responses and provide some level of type-safeness; if the client and server use the same headers class the request/response type, url, http status codes etc. are all well-defined.\r\nEssentially, headers provide a tight coupling between handlers, clients, requests and responses (provided that implementations don't define arbitrary headers on the fly).\r\n\r\nFor example, to define the communication for submitting a job one would define a `JobSubmitRequestBody` that contains the serialized job graph, a `JobSubmitResponseBody` containing the URL to track the job status and a `JobSubmitHeaders` class that define the HTTP method (POST), the url (e.g `/submit`, the response http status code (ACCEPTED).\r\n\r\n#### Handlers\r\n\r\nSomeone has to deal with requests and send out responses, which is where the `AbstractRestHandler`  comes into play. This is an abstract class that manages all the netty stuff, and, just like the `MessageHeaders`, has generic type arguments for a `RequestBody` and `ResponseBody`. Only a single method must be implemented, which accepts a request and returns a response: `abstract CompletableFuture<HandlerResponse<P>> handleRequest(@Nonnull HandlerRequest<R> request);`\r\n\r\nA `HandlerRequest` contains a `RequestBody` and maps for path/query parameters.\r\nA `HandlerResponse` contains either a `ResponseBody`, or an `ErrorResponse`.\r\n\r\n## Brief change log\r\n\r\n  - Add `MessageHeaders`, `Request-/ResponseBody` for modeling messages\r\n  - Add `AbstractRestHandler`, `HandlerRequest/-Response` for message processing\r\n  - Add `RestClient-/-ServerEndpoint` that setup netty\r\n\r\n## Verifying this change\r\n\r\nThis change added tests.\r\n\r\n## Does this pull request potentially affect one of the following parts:\r\n\r\n  - Dependencies (does it add or upgrade a dependency): (no)\r\n  - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: (no)\r\n  - The serializers: no)\r\n  - The runtime per-record code paths (performance sensitive): (no)\r\n  - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Yarn/Mesos, ZooKeeper: (no)\r\n\r\n## Documentation\r\n\r\n  - Does this pull request introduce a new feature? (no)\r\n  - If yes, how is the feature documented? (not applicable)\r\n\r\n","created_at":"2017-08-21T14:35:08Z","updated_at":"2017-08-23T08:25:31Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f22da2774cee8f0a5f4310084b55dd7051f14087","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/flink/pulls/4569/commits","review_comments_url":"https://api.github.com/repos/apache/flink/pulls/4569/comments","review_comment_url":"https://api.github.com/repos/apache/flink/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/flink/issues/4569/comments","statuses_url":"https://api.github.com/repos/apache/flink/statuses/9763c95750a12810223f0ccaa0c7ca169a645d5c","head":{"label":"zentol:rest_client_final","ref":"rest_client_final","sha":"9763c95750a12810223f0ccaa0c7ca169a645d5c","user":{"login":"zentol","id":5725237,"avatar_url":"https://avatars1.githubusercontent.com/u/5725237?v=4","gravatar_id":"","url":"https://api.github.com/users/zentol","html_url":"https://github.com/zentol","followers_url":"https://api.github.com/users/zentol/followers","following_url":"https://api.github.com/users/zentol/following{/other_user}","gists_url":"https://api.github.com/users/zentol/gists{/gist_id}","starred_url":"https://api.github.com/users/zentol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zentol/subscriptions","organizations_url":"https://api.github.com/users/zentol/orgs","repos_url":"https://api.github.com/users/zentol/repos","events_url":"https://api.github.com/users/zentol/events{/privacy}","received_events_url":"https://api.github.com/users/zentol/received_events","type":"User","site_admin":false},"repo":{"id":20647396,"name":"flink","full_name":"zentol/flink","owner":{"login":"zentol","id":5725237,"avatar_url":"https://avatars1.githubusercontent.com/u/5725237?v=4","gravatar_id":"","url":"https://api.github.com/users/zentol","html_url":"https://github.com/zentol","followers_url":"https://api.github.com/users/zentol/followers","following_url":"https://api.github.com/users/zentol/following{/other_user}","gists_url":"https://api.github.com/users/zentol/gists{/gist_id}","starred_url":"https://api.github.com/users/zentol/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zentol/subscriptions","organizations_url":"https://api.github.com/users/zentol/orgs","repos_url":"https://api.github.com/users/zentol/repos","events_url":"https://api.github.com/users/zentol/events{/privacy}","received_events_url":"https://api.github.com/users/zentol/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/zentol/flink","description":"Mirror of Apache Flink","fork":true,"url":"https://api.github.com/repos/zentol/flink","forks_url":"https://api.github.com/repos/zentol/flink/forks","keys_url":"https://api.github.com/repos/zentol/flink/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zentol/flink/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zentol/flink/teams","hooks_url":"https://api.github.com/repos/zentol/flink/hooks","issue_events_url":"https://api.github.com/repos/zentol/flink/issues/events{/number}","events_url":"https://api.github.com/repos/zentol/flink/events","assignees_url":"https://api.github.com/repos/zentol/flink/assignees{/user}","branches_url":"https://api.github.com/repos/zentol/flink/branches{/branch}","tags_url":"https://api.github.com/repos/zentol/flink/tags","blobs_url":"https://api.github.com/repos/zentol/flink/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zentol/flink/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zentol/flink/git/refs{/sha}","trees_url":"https://api.github.com/repos/zentol/flink/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zentol/flink/statuses/{sha}","languages_url":"https://api.github.com/repos/zentol/flink/languages","stargazers_url":"https://api.github.com/repos/zentol/flink/stargazers","contributors_url":"https://api.github.com/repos/zentol/flink/contributors","subscribers_url":"https://api.github.com/repos/zentol/flink/subscribers","subscription_url":"https://api.github.com/repos/zentol/flink/subscription","commits_url":"https://api.github.com/repos/zentol/flink/commits{/sha}","git_commits_url":"https://api.github.com/repos/zentol/flink/git/commits{/sha}","comments_url":"https://api.github.com/repos/zentol/flink/comments{/number}","issue_comment_url":"https://api.github.com/repos/zentol/flink/issues/comments{/number}","contents_url":"https://api.github.com/repos/zentol/flink/contents/{+path}","compare_url":"https://api.github.com/repos/zentol/flink/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zentol/flink/merges","archive_url":"https://api.github.com/repos/zentol/flink/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zentol/flink/downloads","issues_url":"https://api.github.com/repos/zentol/flink/issues{/number}","pulls_url":"https://api.github.com/repos/zentol/flink/pulls{/number}","milestones_url":"https://api.github.com/repos/zentol/flink/milestones{/number}","notifications_url":"https://api.github.com/repos/zentol/flink/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zentol/flink/labels{/name}","releases_url":"https://api.github.com/repos/zentol/flink/releases{/id}","deployments_url":"https://api.github.com/repos/zentol/flink/deployments","created_at":"2014-06-09T13:27:33Z","updated_at":"2016-10-28T13:45:08Z","pushed_at":"2017-08-22T12:29:51Z","git_url":"git://github.com/zentol/flink.git","ssh_url":"git@github.com:zentol/flink.git","clone_url":"https://github.com/zentol/flink.git","svn_url":"https://github.com/zentol/flink","homepage":null,"size":127612,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"9077e5169d28efc701ca49cbc6a30df1e33b416b","user":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":20587599,"name":"flink","full_name":"apache/flink","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars0.githubusercontent.com/u/47359?v=4","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/flink","description":"Mirror of Apache Flink","fork":false,"url":"https://api.github.com/repos/apache/flink","forks_url":"https://api.github.com/repos/apache/flink/forks","keys_url":"https://api.github.com/repos/apache/flink/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/flink/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/flink/teams","hooks_url":"https://api.github.com/repos/apache/flink/hooks","issue_events_url":"https://api.github.com/repos/apache/flink/issues/events{/number}","events_url":"https://api.github.com/repos/apache/flink/events","assignees_url":"https://api.github.com/repos/apache/flink/assignees{/user}","branches_url":"https://api.github.com/repos/apache/flink/branches{/branch}","tags_url":"https://api.github.com/repos/apache/flink/tags","blobs_url":"https://api.github.com/repos/apache/flink/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/flink/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/flink/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/flink/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/flink/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/flink/languages","stargazers_url":"https://api.github.com/repos/apache/flink/stargazers","contributors_url":"https://api.github.com/repos/apache/flink/contributors","subscribers_url":"https://api.github.com/repos/apache/flink/subscribers","subscription_url":"https://api.github.com/repos/apache/flink/subscription","commits_url":"https://api.github.com/repos/apache/flink/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/flink/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/flink/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/flink/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/flink/contents/{+path}","compare_url":"https://api.github.com/repos/apache/flink/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/flink/merges","archive_url":"https://api.github.com/repos/apache/flink/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/flink/downloads","issues_url":"https://api.github.com/repos/apache/flink/issues{/number}","pulls_url":"https://api.github.com/repos/apache/flink/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/flink/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/flink/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/flink/labels{/name}","releases_url":"https://api.github.com/repos/apache/flink/releases{/id}","deployments_url":"https://api.github.com/repos/apache/flink/deployments","created_at":"2014-06-07T07:00:10Z","updated_at":"2017-08-23T08:00:52Z","pushed_at":"2017-08-23T08:15:29Z","git_url":"git://github.com/apache/flink.git","ssh_url":"git@github.com:apache/flink.git","clone_url":"https://github.com/apache/flink.git","svn_url":"https://github.com/apache/flink","homepage":null,"size":132145,"stargazers_count":2633,"watchers_count":2633,"language":"Java","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1833,"mirror_url":"git://git.apache.org/flink.git","open_issues_count":273,"forks":1833,"open_issues":273,"watchers":2633,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/flink/pulls/4569"},"html":{"href":"https://github.com/apache/flink/pull/4569"},"issue":{"href":"https://api.github.com/repos/apache/flink/issues/4569"},"comments":{"href":"https://api.github.com/repos/apache/flink/issues/4569/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/flink/pulls/4569/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/flink/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/flink/pulls/4569/commits"},"statuses":{"href":"https://api.github.com/repos/apache/flink/statuses/9763c95750a12810223f0ccaa0c7ca169a645d5c"}}}}
{"actor":{"display_login":"kl0u"}}