hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mit...@apache.org
Subject hive git commit: HIVE-17218: Canonical-ize hostnames for Hive metastore, and HS2 servers.
Date Tue, 15 Aug 2017 23:50:49 GMT
Repository: hive
Updated Branches:
  refs/heads/master 0b81d5d81 -> 506168370


HIVE-17218: Canonical-ize hostnames for Hive metastore, and HS2 servers.


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/50616837
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/50616837
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/50616837

Branch: refs/heads/master
Commit: 50616837010dd157f879c668e1b00612cfa0b7a9
Parents: 0b81d5d
Author: Mithun RK <mithunr@yahoo-inc.com>
Authored: Mon Jul 31 14:54:02 2017 -0700
Committer: Mithun RK <mithun@apache.org>
Committed: Tue Aug 15 16:35:10 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/hive/jdbc/HiveConnection.java   |  5 +++--
 .../hadoop/hive/metastore/HiveMetaStoreClient.java  | 10 +++++++++-
 .../hadoop/hive/thrift/HadoopThriftAuthBridge.java  | 16 ++++++++++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/50616837/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
----------------------------------------------------------------------
diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
index 73e4734..1311d2d 100644
--- a/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
+++ b/jdbc/src/java/org/apache/hive/jdbc/HiveConnection.java
@@ -20,6 +20,7 @@ package org.apache.hive.jdbc;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.hive.common.auth.HiveAuthUtils;
+import org.apache.hadoop.hive.shims.ShimLoader;
 import org.apache.hive.jdbc.Utils.JdbcConnectionParams;
 import org.apache.hive.service.auth.HiveAuthConstants;
 import org.apache.hive.service.auth.KerberosSaslHelper;
@@ -148,7 +149,7 @@ public class HiveConnection implements java.sql.Connection {
     // sess_var_list -> sessConfMap
     // hive_conf_list -> hiveConfMap
     // hive_var_list -> hiveVarMap
-    host = connParams.getHost();
+    host = ShimLoader.getHadoopThriftAuthBridge().getCanonicalHostName(connParams.getHost());
     port = connParams.getPort();
     sessConfMap = connParams.getSessionVars();
     isEmbeddedMode = connParams.isEmbeddedMode();
@@ -213,7 +214,7 @@ public class HiveConnection implements java.sql.Connection {
             }
             // Update with new values
             jdbcUriString = connParams.getJdbcUriString();
-            host = connParams.getHost();
+            host = ShimLoader.getHadoopThriftAuthBridge().getCanonicalHostName(connParams.getHost());
             port = connParams.getPort();
           } else {
             errMsg = warnMsg;

http://git-wip-us.apache.org/repos/asf/hive/blob/50616837/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
index ad51dfd..b37c677 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStoreClient.java
@@ -191,7 +191,15 @@ public class HiveMetaStoreClient implements IMetaStoreClient, AutoCloseable
{
             throw new IllegalArgumentException("URI: " + s
                 + " does not have a scheme");
           }
-          metastoreUris[i++] = tmpUri;
+          metastoreUris[i++] = new URI(
+              tmpUri.getScheme(),
+              tmpUri.getUserInfo(),
+              ShimLoader.getHadoopThriftAuthBridge().getCanonicalHostName(tmpUri.getHost()),
+              tmpUri.getPort(),
+              tmpUri.getPath(),
+              tmpUri.getQuery(),
+              tmpUri.getFragment()
+          );
 
         }
         // make metastore URIS random

http://git-wip-us.apache.org/repos/asf/hive/blob/50616837/shims/common/src/main/java/org/apache/hadoop/hive/thrift/HadoopThriftAuthBridge.java
----------------------------------------------------------------------
diff --git a/shims/common/src/main/java/org/apache/hadoop/hive/thrift/HadoopThriftAuthBridge.java
b/shims/common/src/main/java/org/apache/hadoop/hive/thrift/HadoopThriftAuthBridge.java
index fd86fed..6c8b362 100644
--- a/shims/common/src/main/java/org/apache/hadoop/hive/thrift/HadoopThriftAuthBridge.java
+++ b/shims/common/src/main/java/org/apache/hadoop/hive/thrift/HadoopThriftAuthBridge.java
@@ -22,6 +22,7 @@ import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_SECURITY_AUTHE
 import java.io.IOException;
 import java.net.InetAddress;
 import java.net.Socket;
+import java.net.UnknownHostException;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedExceptionAction;
 import java.util.Locale;
@@ -114,6 +115,21 @@ public abstract class HadoopThriftAuthBridge {
     return serverPrincipal;
   }
 
+  /**
+   * Method to get canonical-ized hostname, given a hostname (possibly a CNAME).
+   * This should allow for service-principals to use simplified CNAMEs.
+   * @param hostName The hostname to be canonical-ized.
+   * @return Given a CNAME, the canonical-ized hostname is returned. If not found, the original
hostname is returned.
+   */
+  public String getCanonicalHostName(String hostName) {
+    try {
+      return InetAddress.getByName(hostName).getCanonicalHostName();
+    }
+    catch(UnknownHostException exception) {
+      LOG.warn("Could not retrieve canonical hostname for " + hostName, exception);
+      return hostName;
+    }
+  }
 
   public UserGroupInformation getCurrentUGIWithConf(String authMethod)
       throws IOException {


Mime
View raw message