Browse Source

HUE-8330 [core] Remove old main dropdown multi cluster configuration

Romain Rigaux 7 years ago
parent
commit
6ea3df3051

+ 1 - 5
desktop/core/src/desktop/api2.py

@@ -44,7 +44,7 @@ from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.export_csvxls import make_response
 from desktop.lib.i18n import smart_str, force_unicode
 from desktop.models import Document2, Document, Directory, FilesystemException, uuid_default, \
-  UserPreferences, get_user_preferences, set_user_preferences, USER_PREFERENCE_CLUSTER, get_cluster_config
+  UserPreferences, get_user_preferences, set_user_preferences, get_cluster_config
 
 
 LOG = logging.getLogger(__name__)
@@ -69,10 +69,6 @@ def api_error_handler(func):
 
 @api_error_handler
 def get_config(request):
-  if request.POST.get(USER_PREFERENCE_CLUSTER):
-    set_user_preferences(request.user, USER_PREFERENCE_CLUSTER, request.POST.get(USER_PREFERENCE_CLUSTER))
-
-
   config = get_cluster_config(request.user)
   config['status'] = 0
 

+ 5 - 9
desktop/core/src/desktop/conf.py

@@ -1479,18 +1479,14 @@ def get_clusters():
       (i, {
         'name': i,
         'type': cluster_config[i].TYPE.get(),
-        'interfaces': [{'name': i, 'type': cluster_config[i].TYPE.get(), 'interface': interface} for interface in cluster_config[i].INTERFACES.get()]
+        'interfaces': [
+            {'name': i, 'type': cluster_config[i].TYPE.get(), 'interface': interface}
+            for interface in cluster_config[i].INTERFACES.get()
+        ]
       }) for i in cluster_config]
     )
   else:
-    if IS_EMBEDDED.get():
-      clusters = OrderedDict([('Default', {'name': 'Analytic DB', 'type': 'analyticdb', 'interfaces': []})])
-    else:
-      clusters = OrderedDict([('Default', {'name': 'Default', 'type': 'ini', 'interfaces': []})])
-
-  if 'Data Eng' in clusters:
-    clusters['Data Eng']['interfaces'].append({'name': 'Data Eng', 'type': 'dataeng', 'interface': 'c1'})
-    clusters['Data Eng']['interfaces'].append({'name': 'Data Eng', 'type': 'dataeng', 'interface': 'c2'})
+    clusters = OrderedDict([('Default', {'name': 'Default', 'type': 'ini', 'interfaces': []})])
 
   return clusters
 

+ 20 - 64
desktop/core/src/desktop/models.py

@@ -65,8 +65,6 @@ SAMPLE_USER_OWNERS = ['hue', 'sample']
 UTC_TIME_FORMAT = "%Y-%m-%dT%H:%MZ"
 HUE_VERSION = None
 
-USER_PREFERENCE_CLUSTER = 'cluster'
-
 
 def uuid_default():
   return str(uuid.uuid4())
@@ -1558,7 +1556,6 @@ def get_cluster_config(user):
   return cluster_config.get_config()
 
 
-DATAENG = 'dataeng'
 ANALYTIC_DB = 'analyticdb'
 
 
@@ -1654,9 +1651,8 @@ class ClusterConfig():
     interpreters = []
 
     _interpreters = get_ordered_interpreters(self.user)
-    if self.cluster_type == DATAENG:
-      _interpreters = [interpreter for interpreter in _interpreters if interpreter['type'] in ('hive', 'spark2', 'mapreduce')]
-    elif self.cluster_type == ANALYTIC_DB:
+
+    if self.cluster_type == ANALYTIC_DB:
       _interpreters = [interpreter for interpreter in _interpreters if interpreter['type'] == 'impala']
 
     for interpreter in _interpreters:
@@ -1670,7 +1666,7 @@ class ClusterConfig():
         'is_sql': interpreter['is_sql']
       })
 
-    if SHOW_NOTEBOOKS.get() and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
+    if SHOW_NOTEBOOKS.get() and self.cluster_type != ANALYTIC_DB:
       try:
         first_non_sql_index = [interpreter['is_sql'] for interpreter in interpreters].index(False)
       except ValueError:
@@ -1701,7 +1697,7 @@ class ClusterConfig():
   def _get_dashboard(self):
     interpreters = get_engines(self.user)
 
-    if interpreters and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
+    if interpreters and self.cluster_type != ANALYTIC_DB:
       _interpreters = [{
           'type': interpreter['type'],
           'displayName': interpreter['type'].title(),
@@ -1735,7 +1731,7 @@ class ClusterConfig():
   def _get_browser(self):
     interpreters = []
 
-    if 'filebrowser' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
+    if 'filebrowser' in self.apps and self.cluster_type != ANALYTIC_DB:
       interpreters.append({
         'type': 'hdfs',
         'displayName': _('Files'),
@@ -1771,7 +1767,7 @@ class ClusterConfig():
         'page': '/metastore/tables'
       })
 
-    if 'search' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
+    if 'search' in self.apps and self.cluster_type != ANALYTIC_DB:
       interpreters.append({
         'type': 'indexes',
         'displayName': _('Indexes'),
@@ -1781,29 +1777,20 @@ class ClusterConfig():
       })
 
     if 'jobbrowser' in self.apps:
-      if self.cluster_type == DATAENG:
+      from hadoop.cluster import get_default_yarncluster # Circular loop
+
+      title =  _('Jobs') if self.cluster_type != ANALYTIC_DB else _('Queries')
+
+      if get_default_yarncluster():
         interpreters.append({
-          'type': 'dataeng',
-          'displayName': _('Jobs'),
-          'buttonName': _('Jobs'),
-          'tooltip': _('Jobs'),
+          'type': 'yarn',
+          'displayName': title,
+          'buttonName': title,
+          'tooltip': title,
           'page': '/jobbrowser/'
         })
-      else:
-        from hadoop.cluster import get_default_yarncluster # Circular loop
-
-        title =  _('Jobs') if self.cluster_type != ANALYTIC_DB else _('Queries')
 
-        if get_default_yarncluster():
-          interpreters.append({
-            'type': 'yarn',
-            'displayName': title,
-            'buttonName': title,
-            'tooltip': title,
-            'page': '/jobbrowser/'
-          })
-
-    if has_kafka() and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
+    if has_kafka() and self.cluster_type != ANALYTIC_DB:
       interpreters.append({
         'type': 'kafka',
         'displayName': _('Streams'),
@@ -1812,7 +1799,7 @@ class ClusterConfig():
         'page': '/kafka/'
       })
 
-    if 'hbase' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
+    if 'hbase' in self.apps and self.cluster_type != ANALYTIC_DB:
       interpreters.append({
         'type': 'hbase',
         'displayName': _('HBase'),
@@ -1821,7 +1808,7 @@ class ClusterConfig():
         'page': '/hbase/'
       })
 
-    if 'security' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
+    if 'security' in self.apps and self.cluster_type != ANALYTIC_DB:
       interpreters.append({
         'type': 'security',
         'displayName': _('Security'),
@@ -1830,7 +1817,7 @@ class ClusterConfig():
         'page': '/security/hive'
       })
 
-    if 'sqoop' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
+    if 'sqoop' in self.apps and self.cluster_type != ANALYTIC_DB:
       interpreters.append({
         'type': 'sqoop',
         'displayName': _('Sqoop'),
@@ -1914,46 +1901,15 @@ class Cluster():
 
   def __init__(self, user):
     self.user = user
-    self.default_cluster = get_user_preferences(self.user, key=USER_PREFERENCE_CLUSTER)
     self.data = {}
 
-    if IS_EMBEDDED.get():
+    if IS_EMBEDDED.get(): # ANALYTIC_DB
       self.data = get_clusters()['Default']
     elif self.default_cluster:
       clusters = get_clusters()
       cluster_name = json.loads(self.default_cluster[USER_PREFERENCE_CLUSTER]).get('name')
       self.data = cluster_name and clusters.get(cluster_name) and clusters[cluster_name] or None
 
-  def get_type(self):
-    return self.data and self.data['type'] or 'ini'
-
-  def get_interface(self):
-    return json.loads(self.default_cluster[USER_PREFERENCE_CLUSTER]).get('interface')
-
-  def get_id(self):
-    return json.loads(self.default_cluster[USER_PREFERENCE_CLUSTER]).get('id')
-
-  def get_list_interface_indexes(self):
-    default_cluster_index = 0
-    default_cluster_interface = ''
-
-    clusters = get_clusters()
-    default_cluster = get_user_preferences(self.user, key=USER_PREFERENCE_CLUSTER)
-
-    if clusters and default_cluster:
-      if len(clusters) == 1:
-        default_cluster = clusters.values()[0]
-        default_cluster_index = 0
-        default_cluster_interface = ANALYTIC_DB
-      else:
-        default_cluster_json = json.loads(default_cluster[USER_PREFERENCE_CLUSTER])
-        default_cluster_name = default_cluster_json.get('name')
-
-        default_cluster_index = default_cluster_name in clusters.keys() and clusters.keys().index(default_cluster_name) or 0
-        default_cluster_interface = default_cluster_json.get('interface', '')
-
-    return default_cluster_index, default_cluster_interface
-
 
 def _get_apps(user, section=None):
   current_app = None

+ 0 - 92
desktop/core/src/desktop/templates/hue.mako

@@ -223,48 +223,6 @@ ${ hueIcons.symbols() }
 
 
       <div class="top-nav-middle">
-
-        <!-- ko if: cluster.clusters().length > 1 && cluster.clusters()[0].type() != "analyticdbs" -->
-        <div class="btn-group pull-right" style="display: none;" data-bind="visible: cluster.clusters().length > 1">
-          <button class="btn" data-bind="text: cluster.cluster().name() + (cluster.cluster().interface ? ' ' + cluster.cluster().interface() : '')"></button>
-          <button class="btn dropdown-toggle" data-toggle="dropdown">
-            <span class="caret"></span>
-          </button>
-
-          <ul class="dropdown-menu">
-            <!-- ko foreach: cluster.clusters -->
-              <!-- ko if: ['dataeng', 'cm'].indexOf(type()) != -1 && interfaces().length > 0 -->
-                <li class="dropdown-submenu">
-                  <a data-rel="navigator-tooltip" href="javascript: void(0)">
-                    <i class="fa fa-fw fa-th-large inline-block"></i> <span data-bind="text: name"></span>
-                  </a>
-                  <ul class="dropdown-menu">
-                    <li data-bind="visible: type() == 'dataeng'">
-                      <a data-rel="navigator-tooltip" href="#">
-                        <span class="dropdown-no-icon"><i class="fa fa-fw fa-plus inline-block"></i></span>
-                      </a>
-                    </li>
-                    <!-- ko foreach: interfaces -->
-                      <li>
-                        <a href="javascript: void(0)" data-bind="click: function() { $root.cluster.cluster($data) }">
-                          <span class="dropdown-no-icon" data-bind="text: interface"></span>
-                        </a>
-                      </li>
-                    <!-- /ko -->
-                  </ul>
-                </li>
-                <!-- /ko -->
-                <!-- ko if: ['dataeng', 'cm'].indexOf(type()) == -1 || interfaces().length == 0 -->
-                  <li><a href="javascript: void(0)" data-bind="click: function(){  $root.cluster.cluster($data) }">
-                    <i class="fa fa-fw fa-square"></i> <span data-bind="text: name"></span></a>
-                  </li>
-                <!-- /ko -->
-              <!-- /ko -->
-            <!-- /ko -->
-          </ul>
-        </div>
-        <!-- /ko -->
-
         <div class="search-container-top" data-bind="component: 'hue-global-search'"></div>
       </div>
 
@@ -1590,56 +1548,6 @@ ${ smart_unicode(login_modal(request).content) | n,unicode }
           huePubSub.publish('cluster.config.refresh.config');
         });
 
-        var ClusterPanelViewModel = function() {
-          var self = this;
-          self.apiHelper = ApiHelper.getInstance();
-
-          self.clusters = ko.mapping.fromJS(${ clusters_config_json | n,unicode });
-          self.cluster = ko.observable(self.clusters().length > 0 ? self.clusters()[${ default_cluster_index }] : self.clusters()[0]);
-          self.cluster.subscribe(function(newValue) {
-            new ClusterConfig({'cluster': ko.mapping.toJSON(newValue)});
-          });
-
-          self.contextPanelVisible = ko.observable(false);
-
-          self._loadInterface = function() {
-            var interfaces = self.cluster().interfaces().filter(function (i) {return i.interface() == '${ default_cluster_interface }'});
-            if (interfaces.length > 0) {
-              self.cluster(interfaces[0]);
-            }
-          };
-          var dataEngCluster = $.grep(self.clusters(), function(cluster) {
-            return cluster.type() == 'dataeng';
-          });
-          if (dataEngCluster.length > 0) {
-            $.post("/jobbrowser/api/jobs", {
-              interface: ko.mapping.toJSON('dataeng-clusters'),
-              filters: ko.mapping.toJSON([]),
-            }, function (data) {
-              if (data.status == 0) {
-                var interfaces = [];
-                if (data && data.apps) {
-                  data.apps.forEach(function(cluster) {
-                    interfaces.push(ko.mapping.fromJS({'name': dataEngCluster[0].name(), 'type': 'dataeng', 'interface': cluster.name, 'id': cluster.id}));
-                  });
-                }
-                dataEngCluster[0]['interfaces'](interfaces);
-
-                if (dataEngCluster[0].type() == 'dataeng') {
-                  self._loadInterface();
-                }
-              } else {
-                $(document).trigger("error", data.message);
-              }
-            });
-          }
-          if (self.cluster().type() != 'dataeng') {
-            self._loadInterface();
-          }
-        };
-        self.cluster = new ClusterPanelViewModel();
-      }
-
       var topNavViewModel = new TopNavViewModel(onePageViewModel);
       % if not IS_EMBEDDED.get():
       ko.applyBindings(topNavViewModel, $('.top-nav')[0]);

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

@@ -59,7 +59,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, AccessInfo
 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, _get_apps, UserPreferences, Cluster
+from desktop.models import Settings, hue_version, _get_apps, UserPreferences
 
 
 
@@ -73,7 +73,6 @@ def is_alive(request):
 def hue(request):
   apps = appmanager.get_apps_dict(request.user)
   current_app, other_apps, apps_list = _get_apps(request.user, '')
-  default_cluster_index, default_cluster_interface = Cluster(request.user).get_list_interface_indexes()
   clusters = get_clusters().values()
 
   return render('hue.mako', request, {
@@ -91,10 +90,7 @@ def hue(request):
     'is_demo': desktop.conf.DEMO_ENABLED.get(),
     'banner_message': get_banner_message(request),
     'user_preferences': dict((x.key, x.value) for x in UserPreferences.objects.filter(user=request.user)),
-    'cluster': clusters[0]['type'] if clusters else None,
-    'clusters_config_json': json.dumps(clusters),
-    'default_cluster_index': default_cluster_index,
-    'default_cluster_interface': default_cluster_interface
+    'cluster': clusters[0]['type'] if clusters else None
   })