Преглед на файлове

[HUE-337] Load all libs AND all apps before binding configs.

Note that this patch also amends the config_validator system to support
either (Config, str) or (str, str) tuples.
Aaron T. Myers преди 15 години
родител
ревизия
31ecef5d04

+ 17 - 13
desktop/core/src/desktop/appmanager.py

@@ -38,7 +38,7 @@ LOG = logging.getLogger(__name__)
 ######################################################################
 
 # List of DesktopModuleInfo that have been loaded and skipped
-SKIPPED_APPS = None
+BROKEN_APPS = None
 DESKTOP_LIBS = None
 DESKTOP_APPS = None
 DESKTOP_MODULES = [ ]           # Sum of APPS and LIBS
@@ -201,31 +201,35 @@ def load_apps():
   """
   global DESKTOP_MODULES
   global DESKTOP_APPS
-  global SKIPPED_APPS
 
   if DESKTOP_APPS is not None:
     raise Exception("load_apps already has been called!")
   DESKTOP_APPS = []
-  SKIPPED_APPS = []
-
-  hadoop_ok = desktop.lib.apputil.has_hadoop()
 
   for sdk_app in pkg_resources.iter_entry_points("desktop.sdk.application"):
     m = sdk_app.load()
     dmi = DesktopModuleInfo(m)
-    # If there is no hadoop installation, skips apps that requires hadoop
-    if not hadoop_ok:
-      app_settings = dmi.settings
-      # <app_module>.settings.REQUIRES_HADOOP is True by default
-      if app_settings is None or getattr(app_settings, 'REQUIRES_HADOOP', True):
-        LOG.warn('Skipping app %s because Hadoop is not found' % (sdk_app,))
-        SKIPPED_APPS.append(dmi)
-        continue
     DESKTOP_APPS.append(dmi)
 
   LOG.debug("Loaded Desktop Applications: " + ", ".join(a.name for a in DESKTOP_APPS))
   DESKTOP_MODULES += DESKTOP_APPS
 
+def determine_broken_apps():
+  global DESKTOP_APPS
+  global BROKEN_APPS
+  BROKEN_APPS = []
+
+  hadoop_ok = desktop.lib.apputil.has_hadoop()
+  # If there is no hadoop installation, note which apps were loaded which
+  # require Hadoop.
+  if not hadoop_ok:
+    for dmi in DESKTOP_APPS:
+      app_settings = dmi.settings
+      # <app_module>.settings.REQUIRES_HADOOP is True by default
+      if app_settings is None or getattr(app_settings, 'REQUIRES_HADOOP', True):
+        LOG.warn('App %s requires Hadoop but Hadoop not present.' % (dmi,))
+        BROKEN_APPS.append(dmi)
+
 def get_desktop_module(name):
   """
   Harmless linear search.

+ 4 - 0
desktop/core/src/desktop/conf.py

@@ -16,6 +16,7 @@
 # limitations under the License.
 """General configuration for core Desktop features (authentication, etc)"""
 
+from desktop import appmanager
 from desktop.lib.conf import Config, ConfigSection, UnspecifiedConfigSection
 from desktop.lib.conf import coerce_bool, validate_path
 from desktop.lib.paths import get_desktop_root
@@ -338,4 +339,7 @@ def config_validator():
     res.extend(validate_path(KERBEROS.KINIT_PATH, is_dir=False))
     res.extend(validate_path(KERBEROS.CCACHE_PATH, is_dir=False))
 
+  for broken_app in appmanager.BROKEN_APPS:
+    res.append(('Working Hadoop', 'App %s requires Hadoop but Hadoop is not present.' % (broken_app,)))
+
   return res

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

@@ -53,7 +53,7 @@ def entry():
 
     # See if this command belongs to a disabled app
     commands = { }
-    skipped_apps = sum([ app.django_apps for app in appmanager.SKIPPED_APPS ], [])
+    skipped_apps = sum([ app.django_apps for app in appmanager.BROKEN_APPS ], [])
     for app_name in skipped_apps:
       try:
         path = find_management_module(app_name)

+ 6 - 2
desktop/core/src/desktop/settings.py

@@ -151,11 +151,11 @@ PYLINTRC = get_desktop_root('.pylintrc')
 # Part 4: Installation of apps
 ############################################################
 
+_config_dir = os.getenv("HUE_CONF_DIR", get_desktop_root("conf"))
+
 # Libraries are loaded and configured before the apps
 appmanager.load_libs()
 _lib_conf_modules = filter(None, [app.conf for app in appmanager.DESKTOP_LIBS])
-_config_dir = os.getenv("HUE_CONF_DIR", get_desktop_root("conf"))
-conf.initialize(_lib_conf_modules, _config_dir)
 
 appmanager.load_apps()
 for app in appmanager.DESKTOP_APPS:
@@ -166,8 +166,12 @@ logging.debug("Installed Django modules: %s" % ",".join(map(str, appmanager.DESK
 # Load app configuration
 _app_conf_modules = filter(None, [app.conf for app in appmanager.DESKTOP_APPS])
 _app_conf_modules.append(desktop.conf)
+
+conf.initialize(_lib_conf_modules, _config_dir)
 conf.initialize(_app_conf_modules, _config_dir)
 
+appmanager.determine_broken_apps()
+
 # Now that we've loaded the desktop conf, set the django DEBUG mode based on the conf.
 DEBUG = desktop.conf.DJANGO_DEBUG_MODE.get()
 TEMPLATE_DEBUG = DEBUG

+ 11 - 3
desktop/core/src/desktop/templates/check_config.mako

@@ -15,7 +15,7 @@
 ## limitations under the License.
 
 <%!
-from desktop.lib.conf import BoundContainer
+from desktop.lib.conf import BoundConfig
 %>
 
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
@@ -37,10 +37,18 @@ from desktop.lib.conf import BoundContainer
       <h3>Potential misconfiguration detected. Please fix and restart HUE.</h3>
       <dl>
       % for confvar, error in error_list:
-        <dt><code>${confvar.get_fully_qualifying_key()}</code></dt>
+        <dt>
+          <code>
+            % if isinstance(confvar, str):
+              ${confvar | n}
+            % else:
+              ${confvar.get_fully_qualifying_key()}
+            % endif
+          </code>
+        </dt>
         <dd>
           ## Doesn't make sense to print the value of a BoundContainer
-          % if not isinstance(confvar, BoundContainer):
+          % if type(confvar) is BoundConfig:
             Current value: <code>${confvar.get()}</code><br/>
           % endif
           ${error | n}