Skip to content

Conversation

@zentol
Copy link
Contributor

@zentol zentol commented Feb 21, 2017

This PR allows RequestHandlers to define the REST URLs under which they should be registered.

For this purpose the following method was added to the RequestHandler interface: String[] getPaths();

Additionally, a utility class RestUtils was added that contains a number of often used REST URL components as constants (things like "job" or ":jobid"), and a utility method to concatenate these components into a REST URL (basically concat with "/"). The idea here is to prevent typos and such.

Tests were added for every single handler to verify that the correct paths are returned. As a result if any URL should be changed, which isn't allowed since the REST API is considered stable, a test will now fail.

Copy link
Contributor

@uce uce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good addition with the tests. Just to verify: for the history server we take the returned paths and "expand" the variables:

/subtasks/:subtasknum =>
/subtasks/0
/subtasks/1
...
/subtasks/N

I like the idea of the RestUtils, but I think they decrease readability of the handlers. Would you mind removing it? :( The tests you added should catch all typos etc.

this.httpsEnabled = httpsEnabled;
}

public abstract String[] getPaths();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the other methods are also not commented well, but could you add comments here?

// send an Access Denied message
JarAccessDeniedHandler jad = new JarAccessDeniedHandler();
GET(router, jad);
POST(router, jad);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add the POST and DELETE here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because there are Jar-related handlers that accept POST and DELETE requests. Having the JarAccessDeniedHandler reject these as well seemed more consistent.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK I thought that they are automatically rejected because we did not register a route for them (only for GET before)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they got a 404 previously as unmatched paths are handled by the StaticFileServer.

LOG.info("Web frontend listening at " + address + ':' + port);
}

private void GET(Router router, RequestHandler handler) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a high level comment that says that we have these helpers in order to do the route path setup?


@Override
public String[] getPaths() {
if (serveLogFile) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the proper way to do this would be to have an abstract TaskManagerLogHandler and inherit it once for the logs and once for stdout.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding 2 classes for a single flag is overkill.

}

@Override
public String[] getPaths() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to double check: The handler is OK to handle both requests, right? Before we created two instances of the handler. I think this is actually a case where this works better than before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, the same handler can handle both requests. The handlers that we created before were identical.

@Override
public String[] getPaths() {
return new String[]{CHECKPOINT_STATS_DETAILS_SUBTASKS_REST_PATH};
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty line

*/
package org.apache.flink.runtime.webmonitor.utils;

public class RestUtils {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see why you added this, but I'm again skeptical 😄 The problem I have is that it really decreases readability in my opinion in the handlers. I would actually vote to remove it and keep the complete paths in the handlers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this class will be more apparent when the Archiver pattern is integrated. see zentol@83eff62

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm removing it.

@zentol zentol force-pushed the 5870_handler_url branch from 920eee3 to 3c6e2ed Compare March 1, 2017 12:41
@zentol
Copy link
Contributor Author

zentol commented Mar 1, 2017

@uce I've update the PR.

@zentol zentol force-pushed the 5870_handler_url branch from 3c6e2ed to d611489 Compare March 1, 2017 12:45
@uce
Copy link
Contributor

uce commented Mar 1, 2017

Thanks for addressing my comments. +1 to merge. Really looking forward to the next PRs with the history server.

zentol added a commit to zentol/flink that referenced this pull request Mar 1, 2017
@zentol
Copy link
Contributor Author

zentol commented Mar 1, 2017

merging.

@asfgit asfgit closed this in 999bace Mar 2, 2017
@zentol zentol deleted the 5870_handler_url branch March 2, 2017 10:43
p16i pushed a commit to p16i/flink that referenced this pull request Apr 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants