Răsfoiți Sursa

HUE-1097 [beeswax] Decouple from Impala

Impala app can be unregistered without breaking Beeswax
Fix version and name of the app
Some imports are dynamic in order to avoid circular dependencies
Romain Rigaux 12 ani în urmă
părinte
comite
b0851c26a8

+ 4 - 3
apps/beeswax/src/beeswax/models.py

@@ -36,7 +36,6 @@ from cli_service.ttypes import TSessionHandle, THandleIdentifier,\
   TOperationState, TOperationHandle, TOperationType
 
 
-
 LOG = logging.getLogger(__name__)
 
 QUERY_SUBMISSION_TIMEOUT = datetime.timedelta(0, 60 * 60)               # 1 hour
@@ -101,8 +100,10 @@ class QueryHistory(models.Model):
 
 
   def get_query_server_config(self):
-    return dict(zip(['server_name', 'server_host', 'server_port', 'server_type'],
-                    [self.server_name, self.server_host, self.server_port, self.server_type]))
+    from beeswax.server.dbms import get_query_server_config
+    principal = get_query_server_config(self.server_type)['principal']
+    return dict(zip(['server_name', 'server_host', 'server_port', 'server_type', 'principal'],
+                    [self.server_name, self.server_host, self.server_port, self.server_type, principal]))
 
 
   def get_current_statement(self):

+ 2 - 3
apps/beeswax/src/beeswax/server/beeswax_lib.py

@@ -34,7 +34,6 @@ from beeswax import models
 from beeswax import hive_site
 from beeswax.models import BeeswaxQueryHandle
 from beeswax.server.dbms import Table, DataTable
-from impala.conf import IMPALA_PRINCIPAL
 
 LOG = logging.getLogger(__name__)
 
@@ -208,8 +207,8 @@ class BeeswaxClient:
     cluster_conf = hadoop.cluster.get_cluster_conf_for_job_submission()
     use_sasl = cluster_conf is not None and cluster_conf.SECURITY_ENABLED.get()
 
-    if query_server is not None and query_server.get('server_name') == 'impala':
-      principal = IMPALA_PRINCIPAL.get()
+    if query_server is not None:
+      principal = query_server['principal']
     else:
       principal = KERBEROS.HUE_PRINCIPAL.get()
 

+ 5 - 2
apps/beeswax/src/beeswax/server/dbms.py

@@ -22,12 +22,12 @@ import time
 from django.utils.encoding import force_unicode
 from django.utils.translation import ugettext as _
 
-from filebrowser.views import location_to_url
 from beeswaxd.ttypes import BeeswaxException
+from desktop.conf import KERBEROS
+from filebrowser.views import location_to_url
 
 from beeswax.conf import BEESWAX_SERVER_HOST, BEESWAX_SERVER_PORT,\
   BROWSE_PARTITIONED_TABLE_LIMIT
-from impala.conf import SERVER_HOST, SERVER_PORT
 from beeswax.design import hql_query
 from beeswax.models import QueryHistory, HIVE_SERVER2
 from beeswax.conf import SERVER_INTERFACE
@@ -53,11 +53,13 @@ def get(user, query_server=None):
 
 def get_query_server_config(name='beeswax', requires_ddl=False):
   if name == 'impala' and not requires_ddl:
+    from impala.conf import SERVER_HOST, SERVER_PORT, IMPALA_PRINCIPAL
     query_server = {
         'server_name': 'impala',
         'server_host': SERVER_HOST.get(),
         'server_port': SERVER_PORT.get(),
         'support_ddl': False,
+        'principal': IMPALA_PRINCIPAL.get()
     }
   else:
     query_server = {
@@ -65,6 +67,7 @@ def get_query_server_config(name='beeswax', requires_ddl=False):
         'server_host': BEESWAX_SERVER_HOST.get(),
         'server_port': BEESWAX_SERVER_PORT.get(),
         'support_ddl': True,
+        'principal': KERBEROS.HUE_PRINCIPAL.get()
       }
 
   return query_server

+ 19 - 9
apps/beeswax/src/beeswax/tests.py

@@ -1198,6 +1198,13 @@ for x in sys.stdin:
     assert_equal('localhost', history.server_host)
     assert_equal(BEESWAXD_TEST_PORT, history.server_port)
 
+    query_server = history.get_query_server_config()
+    assert_equal('beeswax', query_server['server_name'])
+    assert_equal('localhost', query_server['server_host'])
+    assert_equal(BEESWAXD_TEST_PORT, query_server['server_port'])
+    assert_equal('beeswax', query_server['server_type'])
+    assert_true(query_server['principal'].startswith('hue/'), query_server['principal'])
+
 
   def test_select_multi_db(self):
     response = _make_query(self.client, 'SELECT * FROM test LIMIT 5', local=False, database='default')
@@ -1477,20 +1484,23 @@ def test_search_log_line():
 
 
 def test_beeswax_get_kerberos_security():
-  query_server = {'server_name': 'beeswax'}
-  assert_equal((False, 'hue'), BeeswaxClient.get_security(query_server))
+  principal = get_query_server_config('beeswax')['principal']
+  assert_true(principal.startswith('hue/'), principal)
+
+  principal = get_query_server_config('impala')['principal']
+  assert_true(principal.startswith('impala/'), principal)
 
-  query_server = {'server_name': 'impala'}
-  assert_equal((False, 'impala'), BeeswaxClient.get_security(query_server))
+  beeswax_query_server = {'server_name': 'beeswax', 'principal': 'hue'}
+  impala_query_server = {'server_name': 'impala', 'principal': 'impala'}
+
+  assert_equal((False, 'hue'), BeeswaxClient.get_security(beeswax_query_server))
+  assert_equal((False, 'impala'), BeeswaxClient.get_security(impala_query_server))
 
   cluster_conf = hadoop.cluster.get_cluster_conf_for_job_submission()
   finish = cluster_conf.SECURITY_ENABLED.set_for_testing(True)
   try:
-    query_server = {'server_name': 'beeswax'}
-    assert_equal((True, 'hue'), BeeswaxClient.get_security(query_server))
-
-    query_server = {'server_name': 'impala'}
-    assert_equal((True, 'impala'), BeeswaxClient.get_security(query_server))
+    assert_equal((True, 'hue'), BeeswaxClient.get_security(beeswax_query_server))
+    assert_equal((True, 'impala'), BeeswaxClient.get_security(impala_query_server))
   finally:
     finish()
 

+ 0 - 20
apps/impala/hueversion.py

@@ -1,20 +0,0 @@
-# Licensed to Cloudera, Inc. under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  Cloudera, Inc. licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-# This file should be the one source of truth for for versions within HUE.
-# It is at least included by each of the default hue app's setup.py.
-
-VERSION="2.1.0"

+ 1 - 0
apps/impala/hueversion.py

@@ -0,0 +1 @@
+../../VERSION

+ 1 - 1
apps/impala/setup.py

@@ -17,7 +17,7 @@ from setuptools import setup, find_packages
 from hueversion import VERSION
 
 setup(
-      name = "Impala",
+      name = "impala",
       version = VERSION,
       author = "Hue",
       url = 'http://github.com/cloudera/hue',