瀏覽代碼

HUE-1934 [beeswax] Flag for automatic closing the queries

Hue will try to close the Hive query when the user leaves the editor page.
This will free all the query resources in HiveServer2 but also make its results inaccessible.
close_queries=false
Romain Rigaux 11 年之前
父節點
當前提交
4af49f7

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

@@ -71,6 +71,14 @@ DOWNLOAD_ROW_LIMIT = Config(
   type=int,
   type=int,
   help=_t('A limit to the number of rows that can be downloaded from a query. A value of -1 means there will be no limit. A maximum of 65,000 is applied to XLS downloads.'))
   help=_t('A limit to the number of rows that can be downloaded from a query. A value of -1 means there will be no limit. A maximum of 65,000 is applied to XLS downloads.'))
 
 
+CLOSE_QUERIES = Config(
+  key="close_queries",
+  help=_t("Hue will try to close the Hive query when the user leaves the editor page. "
+          "This will free all the query resources in HiveServer2, but also make its results inaccessible."),
+  type=coerce_bool,
+  default=True
+)
+
 SSL = ConfigSection(
 SSL = ConfigSection(
   key='ssl',
   key='ssl',
   help=_t('SSL configuration for the server.'),
   help=_t('SSL configuration for the server.'),

+ 13 - 1
apps/beeswax/src/beeswax/templates/execute.mako

@@ -16,6 +16,7 @@
 <%!
 <%!
   from desktop.lib.django_util import extract_field_data
   from desktop.lib.django_util import extract_field_data
   from desktop.views import commonheader, commonfooter
   from desktop.views import commonheader, commonfooter
+  from beeswax.conf import CLOSE_QUERIES
   from django.utils.translation import ugettext as _
   from django.utils.translation import ugettext as _
 %>
 %>
 
 
@@ -25,6 +26,7 @@
 ${ commonheader(_('Query'), app_name, user) | n,unicode }
 ${ commonheader(_('Query'), app_name, user) | n,unicode }
 ${layout.menubar(section='query')}
 ${layout.menubar(section='query')}
 
 
+
 <div id="query-editor" class="container-fluid hide section">
 <div id="query-editor" class="container-fluid hide section">
 <div class="row-fluid">
 <div class="row-fluid">
 <div class="span2" id="advanced-settings">
 <div class="span2" id="advanced-settings">
@@ -1767,7 +1769,6 @@ $(document).ready(function () {
 
 
 % if app_name == 'impala':
 % if app_name == 'impala':
 $(document).ready(function () {
 $(document).ready(function () {
-
   $("#downloadQuery").click(function () {
   $("#downloadQuery").click(function () {
     $("<input>").attr("type", "hidden").attr("name", "button-submit").attr("value", "Execute").appendTo($("#advancedSettingsForm"));
     $("<input>").attr("type", "hidden").attr("name", "button-submit").attr("value", "Execute").appendTo($("#advancedSettingsForm"));
     $("<input>").attr("type", "hidden").attr("name", "download").attr("value", "true").appendTo($("#advancedSettingsForm"));
     $("<input>").attr("type", "hidden").attr("name", "download").attr("value", "true").appendTo($("#advancedSettingsForm"));
@@ -1781,6 +1782,17 @@ $(document).ready(function () {
     'html': true
     'html': true
   });
   });
 
 
+  $("#refresh-tip").popover({
+    'title': "${_('Missing some tables? In order to update the list of tables/metadata seen by Impala, execute one of these queries:')}",
+    'content': $("#refresh-content").html(),
+    'trigger': 'hover',
+    'html': true
+  });
+});
+% endif
+
+% if CLOSE_QUERIES.get() or app_name == 'impala':
+$(document).ready(function () {
   $(document).on('explain.query', function() {
   $(document).on('explain.query', function() {
     viewModel.closeQuery();
     viewModel.closeQuery();
   });
   });

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

@@ -1825,6 +1825,24 @@ def test_metastore_security():
     shutil.rmtree(tmpdir)
     shutil.rmtree(tmpdir)
 
 
 
 
+def test_close_queries_flag():
+  c = make_logged_in_client()
+
+  finish = conf.CLOSE_QUERIES.set_for_testing(False)
+  try:
+    resp = c.get('/beeswax/execute')
+    assert_false('closeQuery()' in resp.content, resp.content)
+  finally:
+    finish()
+
+  finish = conf.CLOSE_QUERIES.set_for_testing(True)
+  try:
+    resp = c.get('/beeswax/execute')
+    assert_true('closeQuery()' in resp.content, resp.content)
+  finally:
+    finish()
+
+
 def hive_site_xml(is_local=False, use_sasl=False, thrift_uris='thrift://darkside-1234:9999',
 def hive_site_xml(is_local=False, use_sasl=False, thrift_uris='thrift://darkside-1234:9999',
                   warehouse_dir='/abc', kerberos_principal='test/test.com@TEST.COM',
                   warehouse_dir='/abc', kerberos_principal='test/test.com@TEST.COM',
                   hs2_kerberos_principal='hs2test/test.com@TEST.COM',
                   hs2_kerberos_principal='hs2test/test.com@TEST.COM',

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

@@ -594,6 +594,10 @@
   # A maximum of 65,000 is applied to XLS downloads.
   # A maximum of 65,000 is applied to XLS downloads.
   ## download_row_limit=1000000
   ## download_row_limit=1000000
 
 
+  # Hue will try to close the Hive query when the user leaves the editor page.
+  # This will free all the query resources in HiveServer2, but also make its results inaccessible.
+  ## close_queries=false
+
   [[ssl]]
   [[ssl]]
     # SSL communication enabled for this server.
     # SSL communication enabled for this server.
     ## enabled=false
     ## enabled=false

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

@@ -636,6 +636,10 @@
   # A maximum of 65,000 is applied to XLS downloads.
   # A maximum of 65,000 is applied to XLS downloads.
   ## download_row_limit=1000000
   ## download_row_limit=1000000
 
 
+  # Hue will try to close the Hive query when the user leaves the editor page.
+  # This will free all the query resources in HiveServer2, but also make its results inaccessible.
+  ## close_queries=false
+
   [[ssl]]
   [[ssl]]
     # SSL communication enabled for this server.
     # SSL communication enabled for this server.
     ## enabled=false
     ## enabled=false