Эх сурвалжийг харах

HUE-6162 [core] Display a warning and offer to switch to the LB port if Hue is on a non-LB port

Jenny Kim 8 жил өмнө
parent
commit
5201b17

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

@@ -28,6 +28,9 @@
   http_host=0.0.0.0
   http_port=8888
 
+  # A comma-separated list of available Hue load balancers
+  ## hue_load_balancer=
+
   # Time zone name
   time_zone=America/Los_Angeles
 

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

@@ -32,6 +32,9 @@
   http_host=0.0.0.0
   http_port=8000
 
+  # A comma-separated list of available Hue load balancers
+  ## hue_load_balancer=
+
   # Time zone name
   time_zone=America/Los_Angeles
 

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

@@ -131,6 +131,13 @@ HTTP_ALLOWED_METHODS = Config(
   private=True,
   default=['OPTIONS', 'GET', 'HEAD', 'POST', 'PUT', 'DELETE', 'CONNECT'])
 
+HUE_LOAD_BALANCER = Config(
+  key="hue_load_balancer",
+  help=_("A comma-separated list of available Hue load balancers."),
+  type=coerce_csv,
+  default=[]
+)
+
 X_FRAME_OPTIONS = Config(
   key="http_x_frame_options",
   help=_("X-Frame-Options HTTP header value."),

+ 3 - 3
desktop/core/src/desktop/templates/common_header.mako

@@ -66,7 +66,7 @@ if USE_NEW_EDITOR.get():
   <link href="${ static('desktop/css/hue3-extra.css') }" rel="stylesheet">
 
   <style type="text/css">
-    % if conf.CUSTOM.BANNER_TOP_HTML.get():
+    % if banner_message or conf.CUSTOM.BANNER_TOP_HTML.get():
       body {
         display: none;
         visibility: hidden;
@@ -186,9 +186,9 @@ if USE_NEW_EDITOR.get():
 
 ${ hueIcons.symbols() }
 
-% if conf.CUSTOM.BANNER_TOP_HTML.get():
+% if banner_message or conf.CUSTOM.BANNER_TOP_HTML.get():
   <div class="banner">
-    ${ conf.CUSTOM.BANNER_TOP_HTML.get() | n,unicode }
+    ${ banner_message or conf.CUSTOM.BANNER_TOP_HTML.get() | n,unicode }
   </div>
 % endif
 

+ 11 - 2
desktop/core/src/desktop/views.py

@@ -45,7 +45,7 @@ import desktop.conf
 import desktop.log.log_buffer
 
 from desktop.api import massaged_tags_for_json, massaged_documents_for_json, _get_docs
-from desktop.conf import USE_NEW_EDITOR, IS_HUE_4
+from desktop.conf import USE_NEW_EDITOR, IS_HUE_4, HUE_LOAD_BALANCER, HTTP_PORT
 from desktop.converters import DocumentConverter
 from desktop.lib import django_mako
 from desktop.lib.conf import GLOBAL_CONFIG, BoundConfig
@@ -475,9 +475,18 @@ def commonheader(title, section, user, request=None, padding="90px", skip_topbar
     },
     'is_demo': desktop.conf.DEMO_ENABLED.get(),
     'is_ldap_setup': 'desktop.auth.backend.LdapBackend' in desktop.conf.AUTH.BACKEND.get(),
-    'is_s3_enabled': is_s3_enabled() and has_s3_access(user)
+    'is_s3_enabled': is_s3_enabled() and has_s3_access(user),
+    'banner_message': get_banner_message(request)
   })
 
+def get_banner_message(request):
+  banner_message = None
+  if HUE_LOAD_BALANCER.get() and request.META.get('SERVER_PORT') and str(request.META['SERVER_PORT']) == str(HTTP_PORT.get()):
+    banner_message = '<div style="padding: 4px; text-align: center; background-color: #003F6C; height: 40px; color: #DBE8F1">%s: %s</div>' % \
+      (_('You are accessing Hue from a non-load balanced port, please switch to one of the available load-balanced hosts'),
+      ", ".join(['<a href="%s" style="color: #FFF; font-weight: bold">%s</a>' % (host, host) for host in HUE_LOAD_BALANCER.get()]))
+  return banner_message
+
 def commonshare():
   return django_mako.render_to_string("common_share.mako", {})