Explorar el Código

HUE-1173 [beeswax] Config check for Hive

- Add "user" param to validators
- Check for server existance (and if its up).
Abraham Elmahrek hace 12 años
padre
commit
79e2258

+ 32 - 16
apps/beeswax/src/beeswax/conf.py

@@ -16,19 +16,21 @@
 # limitations under the License.
 import os.path
 
-from django.utils.translation import ugettext_lazy as _
+from django.utils.translation import ugettext_lazy as _t, ugettext as _
 
 from desktop.lib.conf import Config, coerce_bool
 
+from beeswax.settings import NICE_NAME
+
 
 SERVER_INTERFACE = Config(
   key="server_interface",
-  help=_("Beeswax or Hive Server 2 Thrift API used. Choices are: 'beeswax' or 'hiveserver2'."),
+  help=_t("Beeswax or Hive Server 2 Thrift API used. Choices are: 'beeswax' or 'hiveserver2'."),
   default="beeswax")
 
 BEESWAX_SERVER_HOST = Config(
   key="beeswax_server_host",
-  help=_("Host where Beeswax server Thrift daemon is running. If Kerberos security is enabled, "
+  help=_t("Host where Beeswax server Thrift daemon is running. If Kerberos security is enabled, "
          "the fully-qualified domain name (FQDN) is required, even if the Thrift daemon is running "
          "on the same host as Hue."),
   private=True,
@@ -36,32 +38,32 @@ BEESWAX_SERVER_HOST = Config(
 
 BEESWAX_SERVER_PORT = Config(
   key="beeswax_server_port",
-  help=_("Configure the port the Beeswax Thrift server runs on."),
+  help=_t("Configure the port the Beeswax Thrift server runs on."),
   default=8002,
   type=int)
 
 BEESWAX_META_SERVER_HOST = Config(
   key="beeswax_meta_server_host",
-  help=_("Host where internal metastore Thrift daemon is running."),
+  help=_t("Host where internal metastore Thrift daemon is running."),
   private=True,
   default="localhost")
 
 BEESWAX_META_SERVER_PORT = Config(
   key="beeswax_meta_server_port",
-  help=_("Configure the port the internal metastore daemon runs on. Used only if "
+  help=_t("Configure the port the internal metastore daemon runs on. Used only if "
        "hive.metastore.local is true."),
   default=8003,
   type=int)
 
 BEESWAX_SERVER_BIN = Config(
   key="beeswax_server_bin",
-  help=_("Path to beeswax_server.sh"),
+  help=_t("Path to beeswax_server.sh"),
   private=True,
   default=os.path.join(os.path.dirname(__file__), "..", "..", "beeswax_server.sh"))
 
 BEESWAX_SERVER_HEAPSIZE = Config(
   key="beeswax_server_heapsize",
-  help=_("Maximum Java heap size (in megabytes) used by Beeswax Server.  " + \
+  help=_t("Maximum Java heap size (in megabytes) used by Beeswax Server.  " + \
     "Note that the setting of HADOOP_HEAPSIZE in $HADOOP_CONF_DIR/hadoop-env.sh " + \
     "may override this setting."),
   default="1000")
@@ -69,45 +71,59 @@ BEESWAX_SERVER_HEAPSIZE = Config(
 BEESWAX_HIVE_HOME_DIR = Config(
   key="hive_home_dir",
   default=os.environ.get("HIVE_HOME", "/usr/lib/hive"),
-  help=_("Path to the root of the Hive installation; " +
+  help=_t("Path to the root of the Hive installation; " +
         "defaults to environment variable when not set."))
 
 BEESWAX_HIVE_CONF_DIR = Config(
   key='hive_conf_dir',
-  help=_('Hive configuration directory, where hive-site.xml is located.'),
+  help=_t('Hive configuration directory, where hive-site.xml is located.'),
   default=os.environ.get("HIVE_CONF_DIR", '/etc/hive/conf'))
 
 LOCAL_EXAMPLES_DATA_DIR = Config(
   key='local_examples_data_dir',
   default=os.path.join(os.path.dirname(__file__), "..", "..", "data"),
-  help=_('The local filesystem path containing the Beeswax examples.'))
+  help=_t('The local filesystem path containing the Beeswax examples.'))
 
 BEESWAX_SERVER_CONN_TIMEOUT = Config(
   key='beeswax_server_conn_timeout',
   default=120,
   type=int,
-  help=_('Timeout in seconds for Thrift calls to Beeswax service.'))
+  help=_t('Timeout in seconds for Thrift calls to Beeswax service.'))
 
 METASTORE_CONN_TIMEOUT= Config(
   key='metastore_conn_timeout',
   default=10,
   type=int,
-  help=_('Timeouts in seconds for Thrift calls to the Hive metastore. This timeout should take into account that the metastore could talk to an external database.'))
+  help=_t('Timeouts in seconds for Thrift calls to the Hive metastore. This timeout should take into account that the metastore could talk to an external database.'))
 
 BEESWAX_RUNNING_QUERY_LIFETIME = Config(
   key='beeswax_running_query_lifetime',
   default=604800000L, # 7*24*60*60*1000 (1 week)
   type=long,
-  help=_('Time in milliseconds for Beeswax to persist queries in its cache.'))
+  help=_t('Time in milliseconds for Beeswax to persist queries in its cache.'))
 
 BROWSE_PARTITIONED_TABLE_LIMIT = Config(
   key='browse_partitioned_table_limit',
   default=250,
   type=int,
-  help=_('Set a LIMIT clause when browsing a partitioned table. A positive value will be set as the LIMIT. If 0 or negative, do not set any limit.'))
+  help=_t('Set a LIMIT clause when browsing a partitioned table. A positive value will be set as the LIMIT. If 0 or negative, do not set any limit.'))
 
 SHARE_SAVED_QUERIES = Config(
   key='share_saved_queries',
   default=True,
   type=coerce_bool,
-  help=_('Share saved queries with all users. If set to false, saved queries are visible only to the owner and administrators.'))
+  help=_t('Share saved queries with all users. If set to false, saved queries are visible only to the owner and administrators.'))
+
+def config_validator(user):
+  # dbms is dependent on beeswax.conf (this file)
+  # import in method to avoid circular dependency
+  from beeswax.server import dbms
+
+  res = []
+  try:
+    server = dbms.get(user)
+    server.get_databases()
+  except:
+    res.append((NICE_NAME, _("The app won't work without a running Beeswax/HiveServer2 server and/or Hive Metastore.")))
+
+  return res

+ 1 - 1
apps/oozie/src/oozie/conf.py

@@ -63,7 +63,7 @@ OOZIE_JOBS_COUNT = Config(
   help=_t('Maximum number of Oozie workflows or coodinators to retrieve in one API call.'))
 
 
-def config_validator():
+def config_validator(user):
   res = []
 
   status = get_oozie_status()

+ 1 - 1
apps/pig/src/pig/conf.py

@@ -38,7 +38,7 @@ REMOTE_SAMPLE_DIR = Config(
   help=_t("Location on HDFS where the Pig examples are stored."))
 
 
-def config_validator():
+def config_validator(user):
   res = []
 
   if not 'test' in sys.argv: # Avoid tests hanging

+ 1 - 1
apps/shell/src/shell/conf.py

@@ -91,7 +91,7 @@ SHELL_DELEGATION_TOKEN_DIR = Config(
   type=str
 )
 
-def config_validator():
+def config_validator(user):
   """
   config_validator() -> [ (config_variable, error_message) ]
 

+ 1 - 1
desktop/core/src/desktop/conf.py

@@ -470,7 +470,7 @@ DJANGO_EMAIL_BACKEND = Config(
 )
 
 
-def config_validator():
+def config_validator(user):
   """
   config_validator() -> [ (config_variable, error_message) ]
 

+ 4 - 4
desktop/core/src/desktop/views.py

@@ -338,7 +338,7 @@ CONFIG_VALIDATOR = 'config_validator'
 #
 _CONFIG_ERROR_LIST = None
 
-def _get_config_errors(cache=True):
+def _get_config_errors(request, cache=True):
   """Returns a list of (confvar, err_msg) tuples."""
   global _CONFIG_ERROR_LIST
 
@@ -357,7 +357,7 @@ def _get_config_errors(cache=True):
         continue
 
       try:
-        error_list.extend(validator())
+        error_list.extend(validator(request.user))
       except Exception, ex:
         LOG.exception("Error in config validation by %s: %s" % (module.nice_name, ex))
     _CONFIG_ERROR_LIST = error_list
@@ -371,7 +371,7 @@ def check_config(request):
 
   conf_dir = os.path.realpath(os.getenv("HUE_CONF_DIR", get_desktop_root("conf")))
   return render('check_config.mako', request, dict(
-                    error_list=_get_config_errors(cache=False),
+                    error_list=_get_config_errors(request, cache=False),
                     conf_dir=conf_dir))
 
 def check_config_ajax(request):
@@ -379,7 +379,7 @@ def check_config_ajax(request):
   if not request.user.is_superuser:
     return HttpResponse('')
 
-  error_list = _get_config_errors()
+  error_list = _get_config_errors(request)
   if not error_list:
     # Return an empty response, rather than using the mako template, for performance.
     return HttpResponse('')

+ 1 - 1
desktop/libs/hadoop/src/hadoop/conf.py

@@ -227,7 +227,7 @@ YARN_CLUSTERS = UnspecifiedConfigSection(
 )
 
 
-def config_validator():
+def config_validator(user):
   """
   config_validator() -> [ (config_variable, error_message) ]
 

+ 1 - 1
desktop/libs/liboozie/src/liboozie/conf.py

@@ -53,7 +53,7 @@ def get_oozie_status():
 
   return status
 
-def config_validator():
+def config_validator(user):
   """
   config_validator() -> [ (config_variable, error_message) ]
 

+ 2 - 2
docs/sdk/sdk.md

@@ -509,9 +509,9 @@ the admin. To take advantage of this feature, create a `config_validator`
 function in your `conf.py`:
 
 <pre>
-  def config_validator():
+  def config_validator(user):
     """
-    config_validator() -> [(config_variable, error_msg)] or None
+    config_validator(user) -> [(config_variable, error_msg)] or None
     Called by core check_config() view.
     """
     res = [ ]