ソースを参照

HUE-3286 [cluster] Cleaning-up various modes so that it works in Editor only

Romain Rigaux 8 年 前
コミット
1ef784c

+ 2 - 2
apps/beeswax/src/beeswax/server/dbms.py

@@ -26,7 +26,7 @@ from django.utils.translation import ugettext as _
 from desktop.lib.django_util import format_preserving_redirect
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.parameterization import substitute_variables
-from desktop.models import Cluster, IMPALAUI
+from desktop.models import Cluster, ANALYTIC_DB
 from filebrowser.views import location_to_url
 
 from beeswax import hive_site
@@ -50,7 +50,7 @@ def get(user, query_server=None):
 
   if query_server is None:
     cluster_type = Cluster(user).get_type()
-    if cluster_type == IMPALAUI:
+    if cluster_type == ANALYTIC_DB:
       kwargs = {'name': 'impala'}
     else:
       kwargs = {}

+ 1 - 1
apps/jobbrowser/src/jobbrowser/apis/schedule_api.py

@@ -41,7 +41,7 @@ class ScheduleApi(Api):
 
   def apps(self, filters):
     oozie_api = get_oozie(self.user)
-    kwargs = {'cnt': OOZIE_JOBS_COUNT.get(), 'filters': []}
+    kwargs = {'cnt': hasattr(OOZIE_JOBS_COUNT, 'get') and OOZIE_JOBS_COUNT.get(), 'filters': []}
 
     _filter_oozie_jobs(self.user, filters, kwargs)
 

+ 2 - 2
apps/jobbrowser/src/jobbrowser/apis/workflow_api.py

@@ -208,12 +208,12 @@ def _filter_oozie_jobs(user, filters, kwargs):
     if 'time' in filters:
       kwargs['filters'].extend([('startcreatedtime', '-%s%s' % (filters['time']['time_value'], filters['time']['time_unit'][:1]))])
 
-    if ENABLE_OOZIE_BACKEND_FILTERING.get() and text_filters.get('text'):
+    if hasattr(ENABLE_OOZIE_BACKEND_FILTERING, 'get') and ENABLE_OOZIE_BACKEND_FILTERING.get() and text_filters.get('text'):
       kwargs['filters'].extend([('text', text_filters.get('text'))])
 
     if filters['pagination']:
       kwargs['offset'] = filters['pagination']['offset']
-      kwargs['cnt'] = min(filters['pagination']['limit'], OOZIE_JOBS_COUNT.get())
+      kwargs['cnt'] = min(filters['pagination']['limit'], hasattr(OOZIE_JOBS_COUNT, 'get') and OOZIE_JOBS_COUNT.get())
 
     if filters.get('states'):
       states_filters = {'running': ['RUNNING', 'PREP', 'SUSPENDED'], 'completed': ['SUCCEEDED'], 'failed': ['FAILED', 'KILLED'],}

+ 1 - 1
apps/oozie/src/oozie/forms.py

@@ -348,7 +348,7 @@ class CoordinatorForm(forms.ModelForm):
   class Meta:
     model = Coordinator
     exclude = ('owner', 'deployment_dir')
-    if ENABLE_CRON_SCHEDULING.get():
+    if hasattr(ENABLE_CRON_SCHEDULING, 'get') and ENABLE_CRON_SCHEDULING.get():
         exclude += ('frequency_number', 'frequency_unit')
     widgets = {
       'description': forms.TextInput(attrs={'class': 'span5'}),

+ 2 - 2
desktop/core/src/desktop/middleware.py

@@ -298,8 +298,8 @@ class LoginAndPermissionMiddleware(object):
       try:
         access_view = 'access_view:%s:%s' % (request._desktop_app, resolve(request.path)[0].__name__)
       except Exception, e:
-        access_log(request, 'error checking view perm: %s', e, level=access_log_level)
-        access_view =''
+        access_log(request, 'error checking view perm: %s' % e, level=access_log_level)
+        access_view = ''
 
       # Accessing an app can access an underlying other app.
       # e.g. impala or spark uses code from beeswax and so accessing impala shows up as beeswax here.

+ 27 - 19
desktop/core/src/desktop/models.py

@@ -1549,7 +1549,7 @@ def get_cluster_config(user):
 
 
 DATAENG = 'dataeng'
-IMPALAUI = 'impalaui'
+ANALYTIC_DB = 'analyticdb'
 
 
 class ClusterConfig():
@@ -1646,7 +1646,7 @@ class ClusterConfig():
     _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 == IMPALAUI:
+    elif self.cluster_type == ANALYTIC_DB:
       _interpreters = [interpreter for interpreter in _interpreters if interpreter['type'] == 'impala']
 
     for interpreter in _interpreters:
@@ -1660,7 +1660,7 @@ class ClusterConfig():
         'is_sql': interpreter['is_sql']
       })
 
-    if SHOW_NOTEBOOKS.get() and (self.cluster_type not in (DATAENG, IMPALAUI)):
+    if SHOW_NOTEBOOKS.get() and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
       try:
         first_non_sql_index = [interpreter['is_sql'] for interpreter in interpreters].index(False)
       except ValueError:
@@ -1691,7 +1691,7 @@ class ClusterConfig():
   def _get_dashboard(self):
     interpreters = get_engines(self.user)
 
-    if interpreters and (self.cluster_type not in (DATAENG, IMPALAUI)):
+    if interpreters and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
       return {
         'name': 'dashboard',
         'displayName': _('Dashboard'),
@@ -1711,7 +1711,7 @@ class ClusterConfig():
   def _get_browser(self):
     interpreters = []
 
-    if 'filebrowser' in self.apps and (self.cluster_type not in (DATAENG, IMPALAUI)):
+    if 'filebrowser' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
       interpreters.append({
         'type': 'hdfs',
         'displayName': _('Files'),
@@ -1720,7 +1720,7 @@ class ClusterConfig():
         'page': '/filebrowser/' + (not self.user.is_anonymous() and 'view=' + self.user.get_home_directory() or '')
       })
 
-    if is_s3_enabled() and has_s3_access(self.user):
+    if is_s3_enabled() and has_s3_access(self.user) and self.cluster_type != ANALYTIC_DB:
       interpreters.append({
         'type': 's3',
         'displayName': _('S3'),
@@ -1729,7 +1729,7 @@ class ClusterConfig():
         'page': '/filebrowser/view=S3A://'
       })
 
-    if is_adls_enabled() and has_adls_access(self.user):
+    if is_adls_enabled() and has_adls_access(self.user) and self.cluster_type != ANALYTIC_DB:
       interpreters.append({
         'type': 'adls',
         'displayName': _('ADLS'),
@@ -1747,7 +1747,7 @@ class ClusterConfig():
         'page': '/metastore/tables'
       })
 
-    if 'search' in self.apps and (self.cluster_type not in (DATAENG, IMPALAUI)):
+    if 'search' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
       interpreters.append({
         'type': 'indexes',
         'displayName': _('Indexes'),
@@ -1756,7 +1756,7 @@ class ClusterConfig():
         'page': '/indexer/'
       })
 
-    if 'jobbrowser' in self.apps and self.cluster_type != IMPALAUI:
+    if 'jobbrowser' in self.apps:
       if self.cluster_type == DATAENG:
         interpreters.append({
           'type': 'dataeng',
@@ -1767,16 +1767,19 @@ class ClusterConfig():
         })
       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': _('Jobs'),
-            'buttonName': _('Jobs'),
-            'tooltip': _('Jobs'),
+            'displayName': title,
+            'buttonName': title,
+            'tooltip': title,
             'page': '/jobbrowser/'
           })
 
-    if 'hbase' in self.apps and (self.cluster_type not in (DATAENG, IMPALAUI)):
+    if 'hbase' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
       interpreters.append({
         'type': 'hbase',
         'displayName': _('HBase'),
@@ -1785,7 +1788,7 @@ class ClusterConfig():
         'page': '/hbase/'
       })
 
-    if 'security' in self.apps and (self.cluster_type not in (DATAENG, IMPALAUI)):
+    if 'security' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
       interpreters.append({
         'type': 'security',
         'displayName': _('Security'),
@@ -1794,7 +1797,7 @@ class ClusterConfig():
         'page': '/security/hive'
       })
 
-    if 'sqoop' in self.apps and (self.cluster_type not in (DATAENG, IMPALAUI)):
+    if 'sqoop' in self.apps and (self.cluster_type not in (DATAENG, ANALYTIC_DB)):
       interpreters.append({
         'type': 'sqoop',
         'displayName': _('Sqoop'),
@@ -1903,11 +1906,16 @@ class Cluster():
     default_cluster = get_user_preferences(self.user, key=USER_PREFERENCE_CLUSTER)
 
     if clusters and default_cluster:
-      default_cluster_json = json.loads(default_cluster[USER_PREFERENCE_CLUSTER])
-      default_cluster_name = default_cluster_json.get('name')
+      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', '')
+        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
 

+ 1 - 0
desktop/core/src/desktop/settings.py

@@ -129,6 +129,7 @@ STATIC_URL = '/static/'
 
 STATIC_ROOT = os.path.join(BASE_DIR, 'build', 'static')
 
+
 # List of callables that know how to import templates from various sources.
 TEMPLATE_LOADERS = (
   'django.template.loaders.filesystem.Loader',

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

@@ -22,7 +22,7 @@
   from desktop.conf import DEV_EMBEDDED
   from desktop.views import _ko, commonshare, login_modal
   from desktop.lib.i18n import smart_unicode
-  from desktop.models import PREFERENCE_IS_WELCOME_TOUR_SEEN
+  from desktop.models import PREFERENCE_IS_WELCOME_TOUR_SEEN, ANALYTIC_DB
 
   from dashboard.conf import IS_ENABLED as IS_DASHBOARD_ENABLED
   from indexer.conf import ENABLE_NEW_INDEXER
@@ -199,7 +199,7 @@ ${ hueIcons.symbols() }
 
       <div class="top-nav-middle">
 
-        <!-- ko if: cluster.clusters().length > 1 -->
+        <!-- ko if: cluster.clusters().length > 1 && cluster.clusters()[0].type() != ANALYTIC_DB -->
         <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">
@@ -245,7 +245,7 @@ ${ hueIcons.symbols() }
 
       <div class="top-nav-right">
 
-        % if user.is_authenticated() and section != 'login':
+        % if user.is_authenticated() and section != 'login' and cluster != ANALYTIC_DB:
         <div class="dropdown navbar-dropdown pull-right">
           <%
             view_profile = user.has_hue_permission(action="access_view:useradmin:edit_user", app="useradmin") or user.is_superuser

+ 3 - 1
desktop/core/src/desktop/views.py

@@ -70,6 +70,7 @@ 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, {
     'apps': apps,
@@ -86,7 +87,8 @@ 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)),
-    'clusters_config_json': json.dumps(get_clusters().values()),
+    '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
   })