priyeshkaratha commented on code in PR #8995:
URL: https://github.com/apache/ozone/pull/8995#discussion_r2329310070
##########
hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/ReconUtils.java:
##########
@@ -875,4 +886,105 @@ public static String
constructObjectPathWithPrefix(long... ids) {
}
return pathBuilder.toString();
}
+
+ private static HttpURLConnection makeHttpGetCall(String urlString) throws
IOException {
+ Objects.requireNonNull(urlString, "urlString");
+ URL url = new URL(urlString);
+ final HttpURLConnection conn = openURLConnection(url);
+ conn.setRequestMethod("GET");
+ conn.setConnectTimeout(HTTP_TIMEOUT_MS);
+ conn.setReadTimeout(HTTP_TIMEOUT_MS);
+ conn.setRequestProperty("Accept", "application/json");
+ return conn;
+ }
+
+ private static HttpURLConnection openURLConnection(URL url) throws
IOException {
+ final String protocol = url.getProtocol().toLowerCase(Locale.ROOT);
+ switch (protocol) {
+ case "https":
+ return (HttpsURLConnection) url.openConnection();
+ case "http":
+ return (HttpURLConnection) url.openConnection();
+ default:
+ throw new IOException("Unsupported protocol: " + protocol + " for URL: "
+ url);
+ }
+ }
+
+ public static long getMetricsFromDatanode(DatanodeDetails datanode, String
service, String name, String keyName)
+ throws IOException {
+ // Construct metrics URL for DataNode JMX endpoint
+ String metricsUrl =
String.format("http://%s:%d/jmx?qry=Hadoop:service=%s,name=%s",
+ datanode.getIpAddress(),
+ datanode.getPort(DatanodeDetails.Port.Name.HTTP).getValue(),
+ service,
+ name);
+
+ HttpURLConnection conn = makeHttpGetCall(metricsUrl);
+ try {
+ String jsonResponse = getResponseData(conn);
+ return parseMetrics(jsonResponse, name, keyName);
+ } finally {
+ try {
+ conn.disconnect();
+ } catch (Exception ignored) {
+ // no-op
Review Comment:
In UI, it will always get value of 0 or the actual values. So errors will be
logged at server side.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]