Browse Source

[impala] More explict error when no active session in query browser

Romain Rigaux 4 years ago
parent
commit
f1e292d8a5
2 changed files with 14 additions and 3 deletions
  1. 7 1
      apps/impala/src/impala/server.py
  2. 7 2
      apps/impala/src/impala/server_tests.py

+ 7 - 1
apps/impala/src/impala/server.py

@@ -21,6 +21,9 @@ import json
 import logging
 import threading
 
+from django.utils.translation import ugettext as _
+
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.rest.http_client import HttpClient
 from desktop.lib.rest.resource import Resource
 from beeswax.server.dbms import QueryServerException
@@ -41,12 +44,15 @@ def get_api(user, url):
 
 
 def _get_impala_server_url(session):
-  properties = session.get_properties()
   http_addr = ""
   if COORDINATOR_URL.get():
     http_addr = COORDINATOR_URL.get()
   else:
+    if not session:
+      raise PopupException(_('No active Thrift session with Impala Coordinator, please run a query first.'))
+    properties = session.get_properties()
     http_addr = properties.get('coordinator_host', properties.get('http_addr'))
+
   http_addr = http_addr.replace('http://', '').replace('https://', '')
   return ('https://' if get_webserver_certificate_file() else 'http://') + http_addr
 

+ 7 - 2
apps/impala/src/impala/server_tests.py

@@ -19,12 +19,13 @@
 import logging
 import sys
 
-from nose.tools import assert_equal, assert_not_equal, assert_true, assert_false
+from nose.tools import assert_equal, assert_not_equal, assert_true, assert_false, assert_raises
 
+from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.django_test_util import make_logged_in_client
 from useradmin.models import User
 
-from impala.server import ImpalaDaemonApi
+from impala.server import ImpalaDaemonApi, _get_impala_server_url
 
 if sys.version_info[0] > 2:
   from unittest.mock import patch, Mock, MagicMock
@@ -41,6 +42,10 @@ class TestImpalaDaemonApi():
     self.client = make_logged_in_client(username="test", groupname="default", recreate=True, is_superuser=False)
     self.user = User.objects.get(username="test")
 
+  def test_get_impala_server_url_when_no_session(self):
+    assert_raises(PopupException, _get_impala_server_url, session=None)
+
+
   def test_digest_auth(self):
 
     with patch('impala.server.DAEMON_API_USERNAME.get') as DAEMON_API_USERNAME_get: