hive-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From khorg...@apache.org
Subject hive git commit: HIVE-14207 : Strip HiveConf hidden params in webui conf (Sushanth Sowmyan, reviewed by Thejas Nair)
Date Thu, 14 Jul 2016 21:00:58 GMT
Repository: hive
Updated Branches:
  refs/heads/master 7f27c83a9 -> 3522f3f4c


HIVE-14207 : Strip HiveConf hidden params in webui conf (Sushanth Sowmyan, reviewed by Thejas
Nair)


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

Branch: refs/heads/master
Commit: 3522f3f4c56773db70150798275ad35ef7c978a1
Parents: 7f27c83
Author: Sushanth Sowmyan <khorgath@gmail.com>
Authored: Thu Jul 14 13:34:50 2016 -0700
Committer: Sushanth Sowmyan <khorgath@gmail.com>
Committed: Thu Jul 14 14:00:50 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/hive/http/HttpServer.java   |  5 +-
 .../hadoop/hive/metastore/MetaStoreUtils.java   | 27 +++++++++
 .../apache/hive/service/server/HiveServer2.java | 13 ++--
 .../hive/service/server/TestHS2HttpServer.java  | 64 ++++++++++++++++++--
 4 files changed, 98 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/3522f3f4/common/src/java/org/apache/hive/http/HttpServer.java
----------------------------------------------------------------------
diff --git a/common/src/java/org/apache/hive/http/HttpServer.java b/common/src/java/org/apache/hive/http/HttpServer.java
index 9ceaf3f..0eb5fa9 100644
--- a/common/src/java/org/apache/hive/http/HttpServer.java
+++ b/common/src/java/org/apache/hive/http/HttpServer.java
@@ -130,9 +130,10 @@ public class HttpServer {
       return new HttpServer(this);
     }
 
-    public Builder setConf(HiveConf conf) {
+    public Builder setConf(HiveConf origConf) {
+      this.conf = new HiveConf(origConf);
+      origConf.stripHiddenConfigurations(conf);
       setContextAttribute(CONF_CONTEXT_ATTRIBUTE, conf);
-      this.conf = conf;
       return this;
     }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/3522f3f4/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
----------------------------------------------------------------------
diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
index 2f1e460..f632542 100644
--- a/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
+++ b/metastore/src/java/org/apache/hadoop/hive/metastore/MetaStoreUtils.java
@@ -1302,6 +1302,33 @@ public class MetaStoreUtils {
   }
 
   /**
+   * Finds a free port on the machine, but allow the
+   * ability to specify a port number to not use, no matter what.
+   */
+  public static int findFreePortExcepting(int portToExclude) throws IOException {
+    ServerSocket socket1 = null;
+    ServerSocket socket2 = null;
+    try {
+      socket1 = new ServerSocket(0);
+      socket2 = new ServerSocket(0);
+      if (socket1.getLocalPort() != portToExclude) {
+        return socket1.getLocalPort();
+      }
+      // If we're here, then socket1.getLocalPort was the port to exclude
+      // Since both sockets were open together at a point in time, we're
+      // guaranteed that socket2.getLocalPort() is not the same.
+      return socket2.getLocalPort();
+    } finally {
+      if (socket1 != null){
+        socket1.close();
+      }
+      if (socket2 != null){
+        socket2.close();
+      }
+    }
+  }
+
+  /**
    * Catches exceptions that can't be handled and bundles them to MetaException
    *
    * @param e

http://git-wip-us.apache.org/repos/asf/hive/blob/3522f3f4/service/src/java/org/apache/hive/service/server/HiveServer2.java
----------------------------------------------------------------------
diff --git a/service/src/java/org/apache/hive/service/server/HiveServer2.java b/service/src/java/org/apache/hive/service/server/HiveServer2.java
index 14e1e0d..0ecaa76 100644
--- a/service/src/java/org/apache/hive/service/server/HiveServer2.java
+++ b/service/src/java/org/apache/hive/service/server/HiveServer2.java
@@ -145,14 +145,19 @@ public class HiveServer2 extends CompositeService {
     }
     // Setup web UI
     try {
-      if (hiveConf.getBoolVar(ConfVars.HIVE_IN_TEST)) {
-        LOG.info("Web UI is disabled since in test mode");
-      } else {
-        int webUIPort =
+      int webUIPort =
           hiveConf.getIntVar(ConfVars.HIVE_SERVER2_WEBUI_PORT);
+      // We disable web UI in tests unless the test is explicitly setting a
+      // unique web ui port so that we don't mess up ptests.
+      boolean uiDisabledInTest = hiveConf.getBoolVar(ConfVars.HIVE_IN_TEST) &&
+          (webUIPort == Integer.valueOf(ConfVars.HIVE_SERVER2_WEBUI_PORT.getDefaultValue()));
+      if (uiDisabledInTest) {
+        LOG.info("Web UI is disabled in test mode since webui port was not specified");
+      } else {
         if (webUIPort <= 0) {
           LOG.info("Web UI is disabled since port is set to " + webUIPort);
         } else {
+          LOG.info("Starting Web UI on port "+ webUIPort);
           HttpServer.Builder builder = new HttpServer.Builder("hiveserver2");
           builder.setPort(webUIPort).setConf(hiveConf);
           builder.setHost(hiveConf.getVar(ConfVars.HIVE_SERVER2_WEBUI_BIND_HOST));

http://git-wip-us.apache.org/repos/asf/hive/blob/3522f3f4/service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java
----------------------------------------------------------------------
diff --git a/service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java b/service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java
index c06ea26..2d2a81b 100644
--- a/service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java
+++ b/service/src/test/org/apache/hive/service/server/TestHS2HttpServer.java
@@ -25,22 +25,39 @@ import java.net.URL;
 
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
+import org.apache.hadoop.hive.metastore.MetaStoreUtils;
 import org.junit.AfterClass;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+import org.apache.http.util.EntityUtils;
+
 /**
  * TestHS2HttpServer -- executes tests of HiveServer2 HTTP Server
  */
 public class TestHS2HttpServer {
 
   private static HiveServer2 hiveServer2 = null;
+  private static HiveConf hiveConf = null;
+  private static String metastorePasswd = "61ecbc41cdae3e6b32712a06c73606fa"; //random md5
+  private static Integer webUIPort = null;
 
   @BeforeClass
   public static void beforeTests() throws Exception {
-    HiveConf hiveConf = new HiveConf();
-    hiveConf.setBoolVar(ConfVars.HIVE_IN_TEST, false);
+    webUIPort = MetaStoreUtils.findFreePortExcepting(
+        Integer.valueOf(ConfVars.HIVE_SERVER2_WEBUI_PORT.getDefaultValue()));
+    hiveConf = new HiveConf();
+    hiveConf.set(ConfVars.METASTOREPWD.varname, metastorePasswd);
+    hiveConf.set(ConfVars.HIVE_SERVER2_WEBUI_PORT.varname, webUIPort.toString());
     hiveServer2 = new HiveServer2();
     hiveServer2.init(hiveConf);
     hiveServer2.start();
@@ -48,9 +65,8 @@ public class TestHS2HttpServer {
   }
 
   @Test
-  public void testStackServket() throws Exception {
-    String baseURL = "http://localhost:"
-      + ConfVars.HIVE_SERVER2_WEBUI_PORT.getDefaultValue() + "/stacks";
+  public void testStackServlet() throws Exception {
+    String baseURL = "http://localhost:" + webUIPort + "/stacks";
     URL url = new URL(baseURL);
     HttpURLConnection conn = (HttpURLConnection) url.openConnection();
     Assert.assertEquals(HttpURLConnection.HTTP_OK, conn.getResponseCode());
@@ -66,6 +82,44 @@ public class TestHS2HttpServer {
     Assert.assertTrue(contents);
   }
 
+  @Test
+  public void testConfStrippedFromWebUI() throws Exception {
+
+    String pwdValFound = null;
+    String pwdKeyFound = null;
+    CloseableHttpClient httpclient = null;
+    try {
+      httpclient = HttpClients.createDefault();
+      HttpGet httpGet = new HttpGet("http://localhost:"+webUIPort+"/conf");
+      CloseableHttpResponse response1 = httpclient.execute(httpGet);
+
+      try {
+        HttpEntity entity1 = response1.getEntity();
+        BufferedReader br = new BufferedReader(new InputStreamReader(entity1.getContent()));
+        String line;
+        while ((line = br.readLine())!= null) {
+          if (line.contains(metastorePasswd)){
+            pwdValFound = line;
+          }
+          if (line.contains(ConfVars.METASTOREPWD.varname)){
+            pwdKeyFound = line;
+          }
+        }
+        EntityUtils.consume(entity1);
+      } finally {
+        response1.close();
+      }
+    } finally {
+      if (httpclient != null){
+        httpclient.close();
+      }
+    }
+
+    assertNotNull(pwdKeyFound);
+    assertNull(pwdValFound);
+  }
+
+
   @AfterClass
   public static void afterTests() throws Exception {
     hiveServer2.stop();


Mime
View raw message