This is an automated email from the ASF dual-hosted git repository.

sammichen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 7c40dde7b29 HDDS-14334. Fix JMX query failures when 
hdds.datanode.http.auth.type is set to Kerberos (#9577)
7c40dde7b29 is described below

commit 7c40dde7b296cb05ace739e41402d01de4e19740
Author: Priyesh Karatha <[email protected]>
AuthorDate: Mon Jan 5 18:46:24 2026 +0530

    HDDS-14334. Fix JMX query failures when hdds.datanode.http.auth.type is set 
to Kerberos (#9577)
---
 .../ozone/recon/MetricsServiceProviderFactory.java |  2 +-
 .../recon/spi/impl/JmxServiceProviderImpl.java     | 40 +++++++++++++++-------
 2 files changed, 28 insertions(+), 14 deletions(-)

diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/MetricsServiceProviderFactory.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/MetricsServiceProviderFactory.java
index ee99ec9fa2e..1d6ddb87369 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/MetricsServiceProviderFactory.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/MetricsServiceProviderFactory.java
@@ -92,7 +92,7 @@ public MetricsServiceProvider getMetricsServiceProvider() {
    * @return MetricsServiceProvider instance for Jmx
    */
   public MetricsServiceProvider getJmxMetricsServiceProvider(String endpoint) {
-    return new JmxServiceProviderImpl(reconUtils, endpoint, connectionFactory);
+    return new JmxServiceProviderImpl(reconUtils, endpoint, connectionFactory, 
configuration);
   }
 
   /**
diff --git 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/JmxServiceProviderImpl.java
 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/JmxServiceProviderImpl.java
index 4249d215e33..d3de292945b 100644
--- 
a/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/JmxServiceProviderImpl.java
+++ 
b/hadoop-ozone/recon/src/main/java/org/apache/hadoop/ozone/recon/spi/impl/JmxServiceProviderImpl.java
@@ -17,6 +17,8 @@
 
 package org.apache.hadoop.ozone.recon.spi.impl;
 
+import static 
org.apache.hadoop.hdds.HddsConfigKeys.HDDS_DATANODE_HTTP_AUTH_TYPE;
+
 import java.io.InputStream;
 import java.net.HttpURLConnection;
 import java.util.Collections;
@@ -24,11 +26,13 @@
 import java.util.Map;
 import javax.inject.Singleton;
 import javax.ws.rs.core.Response;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
 import org.apache.hadoop.hdds.server.JsonUtils;
 import org.apache.hadoop.hdfs.web.URLConnectionFactory;
 import org.apache.hadoop.ozone.recon.ReconUtils;
 import org.apache.hadoop.ozone.recon.metrics.Metric;
 import org.apache.hadoop.ozone.recon.spi.MetricsServiceProvider;
+import org.apache.hadoop.security.SecurityUtil;
 
 /**
  * Implementation of the Jmx Metrics Service provider.
@@ -39,12 +43,14 @@ public class JmxServiceProviderImpl implements 
MetricsServiceProvider {
   public static final String JMX_INSTANT_QUERY_API = "qry";
   private URLConnectionFactory connectionFactory;
   private final String jmxEndpoint;
+  private final OzoneConfiguration configuration;
   private ReconUtils reconUtils;
 
   public JmxServiceProviderImpl(
       ReconUtils reconUtils,
       String jmxEndpoint,
-      URLConnectionFactory connectionFactory) {
+      URLConnectionFactory connectionFactory,
+      OzoneConfiguration configuration) {
     // Remove the trailing slash from endpoint url.
     if (jmxEndpoint != null && jmxEndpoint.endsWith("/")) {
       jmxEndpoint = jmxEndpoint.substring(0, jmxEndpoint.length() - 1);
@@ -52,6 +58,7 @@ public JmxServiceProviderImpl(
     this.jmxEndpoint = jmxEndpoint;
     this.reconUtils = reconUtils;
     this.connectionFactory = connectionFactory;
+    this.configuration = configuration;
   }
 
   /**
@@ -69,7 +76,7 @@ public HttpURLConnection getMetricsResponse(String api, 
String queryString)
     String url = String.format("%s?%s=%s", jmxEndpoint, api,
         queryString);
     return reconUtils.makeHttpCall(connectionFactory,
-        url, false);
+        url, isKerberosEnabled());
   }
 
   @Override
@@ -100,18 +107,25 @@ public List<Map<String, Object>> getMetrics(String 
queryString)
    */
   private List<Map<String, Object>> getMetrics(String api, String queryString)
       throws Exception {
-    HttpURLConnection urlConnection =
-        getMetricsResponse(api, queryString);
-    if (Response.Status.fromStatusCode(urlConnection.getResponseCode())
-        .getFamily() == Response.Status.Family.SUCCESSFUL) {
-      try (InputStream inputStream = urlConnection.getInputStream()) {
-        Map<String, Object> jsonMap = 
JsonUtils.getDefaultMapper().readValue(inputStream, Map.class);
-        Object beansObj = jsonMap.get("beans");
-        if (beansObj instanceof List) {
-          return (List<Map<String, Object>>) beansObj;
+    return SecurityUtil.doAsLoginUser(() -> {
+      HttpURLConnection urlConnection =
+          getMetricsResponse(api, queryString);
+      if (Response.Status.fromStatusCode(urlConnection.getResponseCode())
+          .getFamily() == Response.Status.Family.SUCCESSFUL) {
+        try (InputStream inputStream = urlConnection.getInputStream()) {
+          Map<String, Object> jsonMap = 
JsonUtils.getDefaultMapper().readValue(inputStream, Map.class);
+          Object beansObj = jsonMap.get("beans");
+          if (beansObj instanceof List) {
+            return (List<Map<String, Object>>) beansObj;
+          }
         }
       }
-    }
-    return Collections.emptyList();
+      return Collections.emptyList();
+    });
+  }
+
+  private boolean isKerberosEnabled() {
+    return configuration.get(HDDS_DATANODE_HTTP_AUTH_TYPE, "simple")
+        .equals("kerberos");
   }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to