[
https://issues.apache.org/jira/browse/DRILL-7582?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17045807#comment-17045807
]
ASF GitHub Bot commented on DRILL-7582:
---------------------------------------
vvysotskyi commented on pull request #1999: DRILL-7582: Moved Drillbits REST
API communication to the back end layer
URL: https://github.com/apache/drill/pull/1999#discussion_r384686554
##########
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);
+ }
+ return url;
+ }
+
+ /**
+ * Send an HTTP request and returns response body as String.
+ *
+ * @param httpRequest {@link org.apache.http.client.methods.HttpGet} or
{@link org.apache.http.client.methods.HttpPost} instance representing an HTTP
request.
+ * @param drillConfig {@link DrillConfig} instance needed to setup HTTP
Client.
+ * @return String response body.
+ * @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);
+ try (BufferedReader reader = new BufferedReader(new InputStreamReader(
+ httpClient.execute(httpRequest, null)
+ .get(5, TimeUnit.SECONDS)
+ .getEntity()
+ .getContent()))) {
+ return reader.lines().collect(Collectors.joining("\n"));
+ }
+ }
+
+ /**
+ * Get singleton instance of an HTTP Client.
+ *
+ * @param drillConfig {@link DrillConfig} instance needed to retrieve Drill
SSL parameters.
+ * @return HTTP Client instance.
+ * @throws Exception if unable to create an HTTP Client.
+ */
+ private static CloseableHttpAsyncClient getHttpClient(DrillConfig
drillConfig) throws Exception {
+ CloseableHttpAsyncClient localHttpClient = httpClient;
+ if (localHttpClient == null) {
+ synchronized (WebUtils.class) {
+ localHttpClient = httpClient;
+ if (httpClient == null){
+ if (drillConfig.getBoolean(ExecConstants.HTTP_ENABLE_SSL)) {
+ SSLContext sslContext = SSLContexts.custom()
Review comment:
Wouldn't it be better to obtain this instance using
`SSLConfigBuilder`/`SSLConfigClient` and specify `SslContext` obtained from
here instead of specifying `SSLStrategy`?
----------------------------------------------------------------
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]
> Drill docker Web UI doesn't show resources usage information if map the
> container to a non-default port
> -------------------------------------------------------------------------------------------------------
>
> Key: DRILL-7582
> URL: https://issues.apache.org/jira/browse/DRILL-7582
> Project: Apache Drill
> Issue Type: Bug
> Affects Versions: 1.17.0
> Reporter: Anton Gozhiy
> Assignee: Anton Gozhiy
> Priority: Major
> Fix For: 1.18.0
>
>
> *Steps:*
> # Run Drill docker container with non-default port published:
> {noformat}
> $ docker container run -it --rm -p 9047:8047 apache/drill
> {noformat}
> # Open Drill Web UI (localhost:9047)
> *Expected result:*
> The following fields should contain relevant information:
> * Heap Memory Usage
> * Direct Memory Usage
> * CPU Usage
> * Avg Sys Load
> * Uptime
> *Actual result:*
> "Not Available" is displayed.
> *Note:* if publish the default port (-p 8047:8047), everything is showed
> correctly.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)