ソースを参照

HUE-8949 [catalog] Add support for atlas-application.properties

Jean-Francois Desjeans Gauthier 6 年 前
コミット
57fb03fe2c

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

@@ -2037,6 +2037,9 @@
     # Set to true when authenticating via kerberos instead of username/password
     ## kerberos_enabled=core_site.is_kerberos_enabled()
 
+    # Directory of the configurations.
+    ## conf_dir=HUE_CONF_DIR/hive-conf
+
   # Deprecated by [[catalog]]
   [[navigator]]
     # Navigator API URL (without version suffix).

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

@@ -2026,6 +2026,9 @@
     # Set to true when authenticating via kerberos instead of username/password
     ## kerberos_enabled=core_site.is_kerberos_enabled()
 
+    # Directory of the configurations.
+    ## conf_dir=HUE_CONF_DIR/hive-conf
+
   # Deprecated by [[catalog]]
   [[navigator]]
     # Navigator API URL (without version suffix).

+ 65 - 0
desktop/libs/metadata/src/metadata/catalog/atlas_flags.py

@@ -0,0 +1,65 @@
+#!/usr/bin/env python
+# 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.
+
+import errno
+import logging
+import os.path
+
+LOG = logging.getLogger(__name__)
+
+_FLAGS = None
+
+_ADDRESS = 'atlas.rest.address'
+_KERBEROS = 'atlas.authentication.method.kerberos'
+
+
+def reset():
+  global _FLAGS
+  _FLAGS = None
+
+
+def get_conf():
+  if _FLAGS is None:
+    _parse_flags()
+  return _FLAGS
+
+
+def get_address():
+  return get_conf().get(_ADDRESS)
+
+def get_api_url():
+  address = get_address()
+  return address + 'api/atlas/' if address else None
+
+def is_kerberos_enabled():
+  return get_conf().get(_KERBEROS,'').upper() == 'TRUE'
+
+
+def _parse_flags():
+  from metadata import conf
+  global _FLAGS
+
+  try:
+    flags_path = os.path.join(conf.CATALOG.CONF_DIR.get(), 'atlas-application.properties')
+    _FLAGS = dict(line.strip().split('=', 1) for line in open(flags_path) if '=' in line)
+  except IOError as err:
+    if err.errno != errno.ENOENT:
+      LOG.error('Cannot read from "%s": %s' % (flags_path, err))
+    _FLAGS = {}
+  except Exception as ex:
+    LOG.error('Failed to parse config from "%s": %s' % (flags_path, ex))
+    _FLAGS = {}

+ 15 - 10
desktop/libs/metadata/src/metadata/conf.py

@@ -16,6 +16,7 @@
 # limitations under the License.
 
 import logging
+import os
 
 from subprocess import CalledProcessError
 
@@ -23,11 +24,10 @@ from django.utils.translation import ugettext_lazy as _t
 
 from desktop.conf import AUTH_USERNAME as DEFAULT_AUTH_USERNAME, CLUSTER_ID as DEFAULT_CLUSTER_ID
 from desktop.lib.conf import Config, ConfigSection, coerce_bool, coerce_password_from_script
-from desktop.lib.paths import get_config_root
-
-from hadoop.core_site import is_kerberos_enabled
+from desktop.lib.paths import get_config_root, get_desktop_root
 
 from metadata.settings import DJANGO_APPS
+from metadata.catalog import atlas_flags
 
 
 OPTIMIZER_AUTH_PASSWORD = None
@@ -40,18 +40,17 @@ def get_auth_username():
   """Get from top level default from desktop"""
   return DEFAULT_AUTH_USERNAME.get()
 
-
 def default_catalog_url():
   """Get from main Hue config directory if present"""
-  return None
+  return atlas_flags.get_api_url() if atlas_flags.get_api_url() else None
 
 def default_catalog_config_dir():
   """Get from usual main Hue config directory"""
-  return get_config_root()
+  return os.environ.get("HUE_CONF_DIR", get_desktop_root("conf")) + '/hive-conf'
 
 def default_catalog_interface():
   """Detect if the configured catalog is Navigator or default to Atlas"""
-  return 'navigator' if default_navigator_url() else 'atlas'
+  return 'atlas' if atlas_flags.get_api_url() else 'navigator'
 
 def default_navigator_config_dir():
   """Get from usual main Hue config directory"""
@@ -225,7 +224,7 @@ DEFAULT_PUBLIC_KEY = Config(
 # Data Catalog
 
 def get_catalog_url():
-  return (CATALOG.API_URL.get() and CATALOG.API_URL.get().strip('/')[:-3]) or get_navigator_url()
+  return (CATALOG.API_URL.get() and CATALOG.API_URL.get().strip('/')) or get_navigator_url()
 
 def has_catalog(user):
   from desktop.auth.backend import is_admin
@@ -239,10 +238,11 @@ def get_catalog_search_cluster():
   return CATALOG.SEARCH_CLUSTER.get()
 
 def get_kerberos_enabled_default():
-  '''Use core-site is_kerberos_enabled'''
-  return is_kerberos_enabled()
+  '''Use atlas.authentication.method.kerberos if catalog interface is atlas else False '''
+  return atlas_flags.is_kerberos_enabled() if CATALOG.INTERFACE.get() == 'atlas' else False
 
 def get_catalog_server_password_script():
+  '''Execute script at path'''
   return CATALOG.SERVER_PASSWORD_SCRIPT.get()
 
 
@@ -288,6 +288,11 @@ CATALOG = ConfigSection(
       help=_t("Set to true when authenticating via kerberos instead of username/password"),
       type=coerce_bool,
       dynamic_default=get_kerberos_enabled_default
+    ),
+    CONF_DIR=Config(
+      key="conf_dir",
+      help=_t("Directory of the configuration. Defaults to HUE_CONF_DIR/hue-conf"),
+      dynamic_default=default_catalog_config_dir
     )
   )
 )