Bläddra i källkod

HUE-6245 [cluster] Load cluster list from ini configuration

Romain Rigaux 8 år sedan
förälder
incheckning
dad1e7e

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

@@ -22,6 +22,11 @@ import os
 import socket
 import stat
 
+try:
+  from collections import OrderedDict
+except ImportError:
+  from ordereddict import OrderedDict # Python 2.6
+
 from django.utils.translation import ugettext_lazy as _
 
 from metadata.metadata_sites import get_navigator_audit_log_dir, get_navigator_audit_max_file_size
@@ -1337,13 +1342,17 @@ IS_HUE_4 = Config( # To remove in Hue 5
 
 def get_clusters():
   if CLUSTERS.get():
-    engines = CLUSTERS.get()
-    return dict([
-      (i, {
-        'analytics': engines[i].TYPE.get(),
-        'nesting': engines[i].NESTING.get()
-      }) for i in engines]
-    )
+    clusters = CLUSTERS.get()
+  else:
+    clusters = []
+    
+  return OrderedDict([
+    (i, {
+      'name': i,
+      'type': clusters[i].TYPE.get(),
+      'interfaces': clusters[i].INTERFACES.get()
+    }) for i in clusters]
+  )
 
 
 CLUSTERS = UnspecifiedConfigSection(
@@ -1358,6 +1367,13 @@ CLUSTERS = UnspecifiedConfigSection(
           default='local',
           type=str,
       ),
+      INTERFACES=Config(
+          "interfaces",
+          help=_("List of cluster instances of the cluster (optional)."),
+          default=[],
+          type=list,
+      ),
+
       PRODUCT_SECRET=Config(
         key="product_secret",
         help=_("A secret passphrase associated with the productName."),

+ 4 - 8
desktop/core/src/desktop/templates/hue.mako

@@ -155,6 +155,7 @@ ${ hueIcons.symbols() }
 
       <div class="top-nav-middle">
 
+        <!-- ko if: cluster.clusters().length > 0 -->
         <div class="btn-group pull-right">
           <button class="btn" data-bind="text: cluster.cluster().name"></button>
           <button class="btn dropdown-toggle" data-toggle="dropdown">
@@ -196,6 +197,7 @@ ${ hueIcons.symbols() }
             <!-- /ko -->
           </ul>
         </div>
+        <!-- /ko -->
 
         <div class="search-container-top">
           <input placeholder="${ _('Search data and saved documents...') }" type="text"
@@ -1181,14 +1183,8 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           var self = this;
           self.apiHelper = ApiHelper.getInstance();
 
-          self.clusters = ko.observableArray([
-            {'name': 'Ro\'s Cluster', 'type': 'ini'},
-            {'name': 'Team', 'type': 'ini', 'clusters': ko.observableArray()},
-            {'name': 'Nightly', 'type': 'cm', 'clusters': ko.observableArray()},
-            {'name': 'DataEng', 'type': 'dataeng', 'clusters': ko.observableArray()},
-            {'name': 'Athena', 'type': 'athena'}
-          ]);
-          self.cluster = ko.observable(self.clusters()[0]);
+          self.clusters = ko.mapping.fromJS(${ clusters_config_json | n,unicode });
+          self.cluster = ko.observable(self.clusters().length > 0 ? self.clusters()[0] : null);
           self.cluster.subscribe(function(newValue) {
             new ClusterConfig(ko.mapping.toJS(newValue));
           });

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

@@ -47,7 +47,7 @@ import desktop.log.log_buffer
 from desktop import appmanager
 from desktop.api import massaged_tags_for_json, massaged_documents_for_json, _get_docs
 
-from desktop.conf import USE_NEW_EDITOR, IS_HUE_4, HUE_LOAD_BALANCER
+from desktop.conf import USE_NEW_EDITOR, IS_HUE_4, HUE_LOAD_BALANCER, get_clusters
 from desktop.lib import django_mako
 from desktop.lib.conf import GLOBAL_CONFIG, BoundConfig
 from desktop.lib.django_util import JsonResponse, login_notrequired, render
@@ -56,7 +56,7 @@ from desktop.lib.paths import get_desktop_root
 from desktop.lib.thread_util import dump_traceback
 from desktop.log.access import access_log_level, access_warn
 from desktop.log import set_all_debug as _set_all_debug, reset_all_debug as _reset_all_debug, get_all_debug as _get_all_debug
-from desktop.models import Settings, hue_version, ClusterConfig, _get_apps, UserPreferences
+from desktop.models import Settings, hue_version, _get_apps, UserPreferences
 
 
 LOG = logging.getLogger(__name__)
@@ -80,10 +80,11 @@ def hue(request):
     },
     'is_demo': desktop.conf.DEMO_ENABLED.get(),
     'banner_message': get_banner_message(request),
-    'cluster_config': ClusterConfig(request.user),
-    'user_preferences': dict((x.key, x.value) for x in UserPreferences.objects.filter(user=request.user))
+    'user_preferences': dict((x.key, x.value) for x in UserPreferences.objects.filter(user=request.user)),
+    'clusters_config_json': json.dumps(get_clusters().values())
   })
 
+
 def ko_editor(request):
   apps = appmanager.get_apps_dict(request.user)
 
@@ -91,6 +92,7 @@ def ko_editor(request):
     'apps': apps,
   })
 
+
 def ko_metastore(request):
   apps = appmanager.get_apps_dict(request.user)
 
@@ -98,6 +100,7 @@ def ko_metastore(request):
     'apps': apps,
   })
 
+
 def home(request):
   docs = _get_docs(request.user)