Selaa lähdekoodia

HUE-3802 [oozie] Fix HS2 action on SSL enabled cluster

Chris Conner 9 vuotta sitten
vanhempi
commit
ad0b9ba09a

+ 10 - 1
apps/beeswax/src/beeswax/hive_site.py

@@ -47,6 +47,8 @@ _CNF_HIVESERVER2_AUTHENTICATION = 'hive.server2.authentication'
 _CNF_HIVESERVER2_IMPERSONATION = 'hive.server2.enable.doAs'
 
 _CNF_HIVESERVER2_USE_SSL = 'hive.server2.use.SSL'
+_CNF_HIVESERVER2_TRUSTSTORE_PATH = 'hive.server2.truststore.path'
+_CNF_HIVESERVER2_TRUSTSTORE_PASSWORD = 'hive.server2.truststore.password'
 
 _CNF_HIVESERVER2_TRANSPORT_MODE = 'hive.server2.transport.mode'
 _CNF_HIVESERVER2_THRIFT_HTTP_PORT = 'hive.server2.thrift.http.port'
@@ -130,7 +132,14 @@ def hiveserver2_impersonation_enabled():
   return get_conf().get(_CNF_HIVESERVER2_IMPERSONATION, 'FALSE').upper() == 'TRUE'
 
 def hiveserver2_jdbc_url():
-  return 'jdbc:hive2://%s:%s/default' % (beeswax.conf.HIVE_SERVER_HOST.get(), beeswax.conf.HIVE_SERVER_PORT.get())
+  urlbase = 'jdbc:hive2://%s:%s/default' % (beeswax.conf.HIVE_SERVER_HOST.get(),
+                                            beeswax.conf.HIVE_SERVER_PORT.get())
+  if get_conf().get(_CNF_HIVESERVER2_USE_SSL, 'FALSE').upper() == 'TRUE':
+    return '%s;ssl=true;sslTrustStore=%s;trustStorePassword=%s' % (urlbase,
+            get_conf().get(_CNF_HIVESERVER2_TRUSTSTORE_PATH),
+            get_conf().get(_CNF_HIVESERVER2_TRUSTSTORE_PASSWORD))
+  else:
+     return urlbase
 
 def hiveserver2_use_ssl():
   return get_conf().get(_CNF_HIVESERVER2_USE_SSL, 'FALSE').upper() == 'TRUE'

+ 27 - 1
apps/beeswax/src/beeswax/tests.py

@@ -80,7 +80,7 @@ from beeswax.server.hive_server2_lib import HiveServerClient,\
   PartitionKeyCompatible, PartitionValueCompatible, HiveServerTable,\
   HiveServerTColumnValue2
 from beeswax.test_base import BeeswaxSampleProvider, is_hive_on_spark
-from beeswax.hive_site import get_metastore
+from beeswax.hive_site import get_metastore, hiveserver2_jdbc_url
 
 
 LOG = logging.getLogger(__name__)
@@ -3378,3 +3378,29 @@ def test_apply_natural_sort():
                                                             {'name': 'test_2', 'comment': 'Test'},
                                                             {'name': 'test_100', 'comment': 'Test'},
                                                             {'name': 'test_200', 'comment': 'Test'}])
+
+def test_hiveserver2_jdbc_url():
+  try:
+    url = hiveserver2_jdbc_url()
+    assert_equal(url, 'jdbc:hive2://localhost:10000/default')
+
+    beeswax.conf.HIVE_SERVER_HOST.set_for_testing('server-with-ssl-enabled.com')
+    beeswax.conf.HIVE_SERVER_PORT.set_for_testing('10000')
+    url = hiveserver2_jdbc_url()
+    assert_equal(url, 'jdbc:hive2://server-with-ssl-enabled.com:10000/default')
+
+    beeswax.hive_site.reset()
+    beeswax.hive_site.get_conf()[hive_site._CNF_HIVESERVER2_USE_SSL] = 'TRUE'
+    beeswax.hive_site.get_conf()[hive_site._CNF_HIVESERVER2_TRUSTSTORE_PATH] = '/path/to/truststore.jks'
+    beeswax.hive_site.get_conf()[hive_site._CNF_HIVESERVER2_TRUSTSTORE_PASSWORD] = 'password'
+    url = hiveserver2_jdbc_url()
+    assert_equal(url, 'jdbc:hive2://server-with-ssl-enabled.com:10000/default;ssl=true;sslTrustStore=/path/to/truststore.jks;trustStorePassword=password')
+
+    beeswax.hive_site.get_conf()[hive_site._CNF_HIVESERVER2_USE_SSL] = 'FALSE'
+    url = hiveserver2_jdbc_url()
+    assert_equal(url, 'jdbc:hive2://server-with-ssl-enabled.com:10000/default')
+  finally:
+    beeswax.hive_site.reset()
+
+
+

+ 2 - 2
apps/oozie/src/oozie/models2.py

@@ -1074,8 +1074,8 @@ class HiveAction(Action):
 
 def _get_hiveserver2_url():
   try:
-    from beeswax.conf import HIVE_SERVER_HOST, HIVE_SERVER_PORT
-    return 'jdbc:hive2://%s:%s/default' % (HIVE_SERVER_HOST.get(), HIVE_SERVER_PORT.get())
+    from beeswax.hive_site import hiveserver2_jdbc_url
+    return hiveserver2_jdbc_url()
   except Exception, e:
     # Might fail is Hive is disabled
     LOG.warn('Could not guess HiveServer2 URL: %s' % smart_str(e))