paul-rogers commented on a change in pull request #1999: DRILL-7582: Moved
Drillbits REST API communication to the back end layer
URL: https://github.com/apache/drill/pull/1999#discussion_r384878225
##########
File path:
exec/java-exec/src/main/java/org/apache/drill/exec/server/rest/WebUtils.java
##########
@@ -48,4 +68,87 @@ public static String generateCsrfToken() {
new SecureRandom().nextBytes(buffer);
return Base64.getUrlEncoder().withoutPadding().encodeToString(buffer);
}
+
+ /**
+ * 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.
+ * @param hostname hostname of the Drillbit.
+ * @param path relative path to the endpoint.
+ * @return remote Drillbit endpoint URL.
+ * @throws RuntimeException if there is no Drillbit at the given hostname.
+ */
+ static URL getDrillbitURL(WorkManager work, HttpServletRequest request,
String hostname, String path) {
+ DrillbitEndpoint drillbit = work.getContext().getAvailableBits().stream()
+ .filter(db -> db.getAddress().equals(hostname))
+ .findAny()
+ .orElse(null);
+ if (drillbit == null) {
+ throw new RuntimeException(String.format("No such drillbit: %s",
hostname));
+ }
+ URL url;
+ try {
+ url = new URL(request.getScheme(), hostname, drillbit.getHttpPort(),
path);
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
Review 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.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services