Bläddra i källkod

HUE-9374 [editor] Support Thrift on HTTP to Impala

Ying Chen 5 år sedan
förälder
incheckning
9a3909d352

+ 8 - 0
apps/impala/src/impala/conf.py

@@ -241,6 +241,14 @@ USE_SASL = Config(
   dynamic_default=get_use_sasl_default
 )
 
+USE_THRIFT_HTTP = Config(
+  key="use_thrift_http",
+  help=_t("Use Thrift over HTTP for the transport mode."),
+  private=False,
+  type=coerce_bool,
+  default=False
+)
+
 
 def config_validator(user):
   # dbms is dependent on beeswax.conf, import in method to avoid circular dependency

+ 10 - 2
apps/impala/src/impala/dbms.py

@@ -30,6 +30,7 @@ from beeswax.server.dbms import HiveServer2Dbms, QueryServerException, QueryServ
   get_query_server_config as beeswax_query_server_config, get_query_server_config_via_connector
 
 from impala import conf
+from impala.impala_flags import get_hs2_http_port
 
 
 LOG = logging.getLogger(__name__)
@@ -39,19 +40,26 @@ def get_query_server_config(connector=None):
   if connector and has_connectors():
     query_server = get_query_server_config_via_connector(connector)
   else:
+    server_port = get_hs2_http_port() if conf.USE_THRIFT_HTTP.get() else conf.SERVER_PORT.get()
     query_server = {
         'server_name': 'impala',
         'dialect': 'impala',
         'server_host': conf.SERVER_HOST.get(),
-        'server_port': conf.SERVER_PORT.get(),
+        'server_port': server_port,
         'principal': conf.IMPALA_PRINCIPAL.get(),
+        'http_url': '%(protocol)s://%(host)s:%(port)s' % {
+            'protocol': 'https' if conf.SSL.ENABLED.get() else 'http',
+            'host': conf.SERVER_HOST.get(),
+            'port': server_port
+          },
         'impersonation_enabled': conf.IMPERSONATION_ENABLED.get(),
         'querycache_rows': conf.QUERYCACHE_ROWS.get(),
         'QUERY_TIMEOUT_S': conf.QUERY_TIMEOUT_S.get(),
         'SESSION_TIMEOUT_S': conf.SESSION_TIMEOUT_S.get(),
         'auth_username': conf.AUTH_USERNAME.get(),
         'auth_password': conf.AUTH_PASSWORD.get(),
-        'use_sasl': conf.USE_SASL.get()
+        'use_sasl': conf.USE_SASL.get(),
+        'transport_mode': 'http' if conf.USE_THRIFT_HTTP else 'socket',
     }
 
   debug_query_server = query_server.copy()

+ 5 - 0
apps/impala/src/impala/impala_flags.py

@@ -31,6 +31,7 @@ _AUTHORIZED_PROXY_USER_CONFIG = '-authorized_proxy_user_config'
 _PRINCIPAL = '-principal'
 _DEFAULT_QUERY_OPTIONS = '-default_query_options'
 _DEFAULT_TRANSACTIONAL_TYPE = 'default_transactional_type'
+_DEFAULT_HS2_HTTP_PORT='-hs2_http_port'
 
 
 def reset():
@@ -102,6 +103,10 @@ def is_webserver_spnego_enabled():
    """
   return get_conf().get(_WEBSERVER_REQUIRE_SPNEGO)
 
+def get_hs2_http_port():
+  return get_conf().get(_DEFAULT_HS2_HTTP_PORT, 28000)
+
+
 def _parse_impala_flags():
   from impala import conf # Cyclic dependency
   global _IMPALA_FLAGS

+ 18 - 0
apps/impala/src/impala/tests.py

@@ -503,6 +503,24 @@ def test_ssl_validate():
         reset()
 
 
+def test_thrift_over_http_config():
+  resets = [
+      conf.SERVER_HOST.set_for_testing('impalad_host'),
+      conf.SERVER_PORT.set_for_testing(21050),
+      conf.USE_THRIFT_HTTP.set_for_testing(True)
+  ]
+  with patch('impala.dbms.get_hs2_http_port') as get_hs2_http_port:
+    get_hs2_http_port.return_value = 30000
+    try:
+      query_server = get_query_server_config(name='impala')
+      assert_equal(query_server['server_port'], 30000)
+      assert_equal(query_server['transport_mode'], 'http')
+      assert_equal(query_server['http_url'], 'http://impalad_host:30000')
+    finally:
+      for reset in resets:
+        reset()
+
+
 class TestImpalaDbms(object):
 
   def test_get_impala_nested_select(self):

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -1372,6 +1372,9 @@
   # Use SASL framework to establish connection to host.
   ## use_sasl=true
 
+  # Use Thrift over HTTP for the transport mode.
+  ## use_thrift_http=false
+
   [[ssl]]
     # SSL communication enabled for this server.
     ## enabled=false

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -1357,6 +1357,9 @@
   # Use SASL framework to establish connection to host.
   ## use_sasl=true
 
+  # Use Thrift over HTTP for the transport mode.
+  ## use_thrift_http=false
+
   [[ssl]]
     # SSL communication enabled for this server.
     ## enabled=false