GitHub user zentol opened a pull request:
https://github.com/apache/flink/pull/4569
[FLINK-7040] [REST] Add basics for REST communication
## What is the purpose of the change
This PR implements the fundamentals for generic Client/Server REST
communication that will be used for the client/cluster communication, the
WebRuntimeMonitor and queryable state.
#### Endpoints
`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.
The `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).
The `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.
#### Messages
To send a request the client accepts 3 arguments:
* a `MessageHeaders`
* a `RequestBody`
* a `ParameterMapper`
`RequestBodies` represent the http message body, and will be converted to
JSON using jackson-databind.
`ParameterMappers` are used to assemble the final url, including query and
path parameters
`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.
Essentially, headers provide a tight coupling between handlers, clients,
requests and responses (provided that implementations don't define arbitrary
headers on the fly).
For 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).
#### Handlers
Someone 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);`
A `HandlerRequest` contains a `RequestBody` and maps for path/query
parameters.
A `HandlerResponse` contains either a `ResponseBody`, or an `ErrorResponse`.
## Brief change log
- Add `MessageHeaders`, `Request-/ResponseBody` for modeling messages
- Add `AbstractRestHandler`, `HandlerRequest/-Response` for message
processing
- Add `RestClient-/-ServerEndpoint` that setup netty
## Verifying this change
This change added tests.
## Does this pull request potentially affect one of the following parts:
- Dependencies (does it add or upgrade a dependency): (no)
- The public API, i.e., is any changed class annotated with
`@Public(Evolving)`: (no)
- The serializers: no)
- The runtime per-record code paths (performance sensitive): (no)
- Anything that affects deployment or recovery: JobManager (and its
components), Checkpointing, Yarn/Mesos, ZooKeeper: (no)
## Documentation
- Does this pull request introduce a new feature? (no)
- If yes, how is the feature documented? (not applicable)
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/zentol/flink rest_client_final
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/flink/pull/4569.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #4569
----
commit 6085639ad5438228ff56d66a4988cf52cbe850b2
Author: zentol <[email protected]>
Date: 2017-08-16T13:17:45Z
[FLINK-7040] [rest] Add basics for REST communication
commit af95d0729595d1c707ef3041b8fbdbc21c0d0d4a
Author: zentol <[email protected]>
Date: 2017-08-21T09:53:13Z
Add better error message for get requests with a body
commit 5a7a8c2877f2b25cc6281462007a5ff03de40781
Author: zentol <[email protected]>
Date: 2017-08-21T12:40:09Z
Consistent error message for 404
commit bc3b4afd075182cc17b1cb9343215a04b17e5253
Author: zentol <[email protected]>
Date: 2017-08-21T13:00:28Z
Rework resolve URL generation
commit efbcb82076d01f176d8fff903cfcba461591fedc
Author: zentol <[email protected]>
Date: 2017-08-21T13:03:27Z
Rework handler registration
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---