DRILL-7582: Moved Drillbits REST API communication to the back end layer#1999
DRILL-7582: Moved Drillbits REST API communication to the back end layer#1999agozhiy wants to merge 1 commit intoapache:masterfrom
Conversation
| * Build an URL of a remote Drillbit endpoint. | ||
| * | ||
| * @param work {@link WorkManager} instance needed to retrieve the Drillbit address. | ||
| * @param request {@link HttpServletRequest} instance needed to to set the URL schema. |
| .orElse(null); | ||
| if (drillbit == null) { | ||
| throw new RuntimeException(String.format("No such drillbit: %s", hostname)); | ||
| } |
There was a problem hiding this comment.
| .orElse(null); | |
| if (drillbit == null) { | |
| throw new RuntimeException(String.format("No such drillbit: %s", hostname)); | |
| } | |
| .orElseThrow(() -> new RuntimeException("No such drillbit: " + hostname)); |
| if (drillbit == null) { | ||
| throw new RuntimeException(String.format("No such drillbit: %s", hostname)); | ||
| } | ||
| URL url; |
There was a problem hiding this comment.
No need to declare this variable, the value may be returned in the place where it is assigned.
| try { | ||
| url = new URL(request.getScheme(), hostname, drillbit.getHttpPort(), path); | ||
| } catch (MalformedURLException e) { | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
Is there any reason for wrapping the exception into RuntimeException here?
There was a problem hiding this comment.
More broadly, we have a REST call asking for a table of values. Do we want that request to fail for issues such as this (or for HTTP timeouts or other errors)? My guess is we don't. So, maybe map this kind of exception to a single form of exception which can be a) logged, and b) mapped to a value of "Unavailable" in the UI.
Actually, the malformed URL is in the programmers' control (not the user's.) So, throwing an IllegalStateException might help indicate that this is a "should never occur" kind of error.
Still need to handle network timeouts, etc.
There was a problem hiding this comment.
Changed to IllegalStateException.
| } | ||
| URL url; | ||
| try { | ||
| url = new URL(request.getScheme(), hostname, drillbit.getHttpPort(), path); |
There was a problem hiding this comment.
Instead of obtaining DrillbitEndpoint and then obtaining its port, may be added additional map call into stream chain right after the filter:
.map(DrillbitEndpoint::getHttpPort)
| localHttpClient = httpClient; | ||
| if (httpClient == null){ | ||
| if (drillConfig.getBoolean(ExecConstants.HTTP_ENABLE_SSL)) { | ||
| SSLContext sslContext = SSLContexts.custom() |
There was a problem hiding this comment.
Wouldn't it be better to obtain this instance using SSLConfigBuilder/SSLConfigClient and specify SslContext obtained from here instead of specifying SSLStrategy?
| fillQueryCount(i); | ||
| } | ||
| currentRow.find("#status").text(status_map[key]).css('font-style','').prop('title','');; | ||
| currentRow.find("#status").text(status_map[key]).css('font-style', '').prop('title', ''); |
There was a problem hiding this comment.
Something bad with indentation here.
| .filter(db -> db.getAddress().equals(hostname)) | ||
| .findAny() | ||
| .orElse(null); | ||
| if (drillbit == null) { |
There was a problem hiding this comment.
This is a programming invariant check. Maybe use wither assert or Preconditions.
| try { | ||
| url = new URL(request.getScheme(), hostname, drillbit.getHttpPort(), path); | ||
| } catch (MalformedURLException e) { | ||
| throw new RuntimeException(e); |
There was a problem hiding this comment.
More broadly, we have a REST call asking for a table of values. Do we want that request to fail for issues such as this (or for HTTP timeouts or other errors)? My guess is we don't. So, maybe map this kind of exception to a single form of exception which can be a) logged, and b) mapped to a value of "Unavailable" in the UI.
Actually, the malformed URL is in the programmers' control (not the user's.) So, throwing an IllegalStateException might help indicate that this is a "should never occur" kind of error.
Still need to handle network timeouts, etc.
| } | ||
|
|
||
| /** | ||
| * Send an HTTP request and returns response body as String. |
There was a problem hiding this comment.
Parallel constuctin: "Send ... and return ..." (no "s" on "return").
| * @throws Exception if unable to create HTTP client or in case of HTTP timeout. | ||
| */ | ||
| static String doHTTPRequest(HttpRequestBase httpRequest, DrillConfig drillConfig) throws Exception { | ||
| CloseableHttpAsyncClient httpClient = getHttpClient(drillConfig); |
There was a problem hiding this comment.
Reasonable timeout? Give Drillbit 2 seconds to respond, else display "Unavailable"?
| if (localHttpClient == null) { | ||
| synchronized (WebUtils.class) { | ||
| localHttpClient = httpClient; | ||
| if (httpClient == null){ |
There was a problem hiding this comment.
Nit: ){ --> ') {`.
More substantially, maybe separate the create-if-null hokey-pokey with actual creation. Call a method to build the client rather than doing it deeply nested here.
vvysotskyi
left a comment
There was a problem hiding this comment.
Thanks for making changes, +1
DRILL-7582: Moved Drillbits REST API communication to the back end layer
Description
There is a list of Drillbits on the Web UI index page and some statistics, such as Heap Memory Usage, Direct Memory Usage, CPU Usage, Avg Sys Load, Uptime.
Retrieving these stats is implemented by javascript REST API calls from client side. This causes the following problems:
Now all these HTTP requests are sent by org.apache.http.impl.nio.client.CloseableHttpAsyncClient in back end.
Documentation
Statistics should be displayed in all cases.
Testing
Tested manually with SSL enabled/disabled as well as authentication.
Unit / Functional tests were passed.