Browse Source

[beeswax] Metastore client supports SASL

Support browsing a table data with a transactional DB
Query resource does not prepend fs name each time the query is saved
Romain Rigaux 13 years ago
parent
commit
ca07f7f8ef

+ 1 - 1
apps/beeswax/src/beeswax/design.py

@@ -36,7 +36,7 @@ SERIALIZATION_VERSION = '0.4.1'
 
 
 def hql_query(hql, database='default'):
-  data_dict = simplejson.loads('{"query": {"email_notify": null, "query": null, "type": 0, "is_parameterized": true, "database": "default"}, '
+  data_dict = simplejson.loads('{"query": {"email_notify": false, "query": null, "type": 0, "is_parameterized": true, "database": "default"}, '
                                '"functions": [], "VERSION": "0.4.1", "file_resources": [], "settings": []}')
   if not (isinstance(hql, str) or isinstance(hql, unicode)):
     raise Exception('Requires a SQL text query of type <str>, <unicode> and not %s' % type(hql))

+ 0 - 4
apps/beeswax/src/beeswax/forms.py

@@ -18,7 +18,6 @@
 from django import forms
 from django.utils.translation import ugettext as _, ugettext_lazy as _t
 
-import hadoop
 import hive_metastore
 
 from desktop.lib.django_forms import simple_formset_factory, DependencyAwareForm
@@ -172,9 +171,6 @@ class FileResourceForm(forms.Form):
 
   path = forms.CharField(required=True, help_text=_t("Path to file on HDFS."))
 
-  def clean_path(self):
-    return hadoop.conf.HDFS_CLUSTERS['default'].FS_DEFAULTFS.get() + self.cleaned_data['path']
-
 
 FileResourceFormSet = simple_formset_factory(FileResourceForm)
 

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

@@ -198,6 +198,13 @@ class BeeswaxClient:
   def get_default_configuration(self, *args, **kwargs):
     return self.db_client.get_default_configuration(*args, **kwargs)
 
+  @classmethod
+  def get_security(cls):
+    cluster_conf = hadoop.cluster.get_cluster_conf_for_job_submission()
+    use_sasl = cluster_conf is not None and cluster_conf.SECURITY_ENABLED.get()
+    kerberos_principal_short_name = KERBEROS.HUE_PRINCIPAL.get().split('/', 1)[0]
+
+    return use_sasl, kerberos_principal_short_name
 
   def db_client(self, query_server):
     """Get the Thrift client to talk to beeswax server"""
@@ -272,9 +279,7 @@ class BeeswaxClient:
         res = self._client.get_results_metadata(*args, **kwargs)
         return _decode_struct_attr(res, 'table_dir')
 
-    cluster_conf = hadoop.cluster.get_cluster_conf_for_job_submission()
-    use_sasl = cluster_conf is not None and cluster_conf.SECURITY_ENABLED.get()
-    kerberos_principal_short_name = KERBEROS.HUE_PRINCIPAL.get().split('/', 1)[0]
+    use_sasl, kerberos_principal_short_name = BeeswaxClient.get_security()
 
     client = thrift_util.get_client(BeeswaxService.Client,
                                     query_server['server_host'],
@@ -374,10 +379,13 @@ class BeeswaxClient:
         return self._client.alter_partition(db_name, tbl_name, new_part)
 
     _, host, port = hive_site.get_metastore()
+    use_sasl, kerberos_principal_short_name = BeeswaxClient.get_security()
     client = thrift_util.get_client(ThriftHiveMetastore.Client,
                                     host,
                                     port,
                                     service_name="Hive Metastore Server",
+                                    kerberos_principal=kerberos_principal_short_name,
+                                    use_sasl=use_sasl,
                                     timeout_seconds=conf.METASTORE_CONN_TIMEOUT.get())
     return UnicodeMetastoreClient(client)
 

+ 5 - 1
apps/beeswax/src/beeswax/templates/hql_resource.mako

@@ -13,4 +13,8 @@
 ## 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.
-ADD ${type} ${path}
+<%!
+  import hadoop
+%>
+
+ADD ${type} ${hadoop.conf.HDFS_CLUSTERS['default'].FS_DEFAULTFS.get() + path}

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

@@ -156,6 +156,7 @@ for x in sys.stdin:
       resources=[("FILE", "/square.py")], local=False)
     response = wait_for_query_to_finish(self.client, response, max=180.0)
     assert_equal([['0'], ['1'], ['4'], ['9']], response.context["results"][0:4])
+    assert_true('converting to local %s/square.py' % self.cluster._fs_default_name in response.context["log"], response.context["log"])
 
   def test_query_with_setting(self):
     response = _make_query(self.client, "CREATE TABLE test2 AS SELECT foo+1 FROM test WHERE foo=4",