Browse Source

HUE-8330 [cluster] Add fake namespace to compute without a namespace

Romain Rigaux 7 years ago
parent
commit
a3c9ae6086

+ 16 - 7
desktop/core/src/desktop/api2.py

@@ -88,7 +88,7 @@ def get_context_namespaces(request, interface):
     namespaces.extend([{
         'id': cluster['id'],
         'name': cluster['name'],
-        'status': 'RUNNING',
+        'status': 'CREATED',
         'computes': [cluster]
       } for cluster in clusters if cluster.get('type') == 'direct' # and interface == 'hive'
     ])
@@ -97,16 +97,25 @@ def get_context_namespaces(request, interface):
     if [cluster for cluster in clusters if cluster['type'] == 'altus']:
       # Note: attaching computes to namespaces might be done via the frontend in the future
       if interface == 'impala':
-        adb_clusters = AnalyticDbApi(request.user).list_clusters()['clusters']
+        adb_clusters =  AnalyticDbApi(request.user).list_clusters()['clusters']
+        for _cluster in adb_clusters: # Add "fake" namespace if needed
+          if not _cluster.get('namespaceCrn'):
+            _cluster['namespaceCrn'] = _cluster['crn']
+            _cluster['id'] = _cluster['crn']
+            _cluster['namespaceName'] = _cluster['clusterName']
+            _cluster['name'] = _cluster['clusterName']
       else:
         adb_clusters = []
 
       namespaces.extend([{
           'id': namespace.get('crn', 'None'),
-          'name': namespace.get('namespaceName', 'Unknown'),
+          'name': namespace.get('namespaceName'),
           'status': namespace.get('status'),
           'computes': [_cluster for _cluster in adb_clusters if _cluster.get('namespaceCrn') == namespace.get('crn')]
-        } for namespace in SdxApi(request.user).list_namespaces()]
+        } for namespace in SdxApi(request.user).list_namespaces() +
+             # Adding "fake" namespace for cluster without one
+             [_cluster for _cluster in adb_clusters if not cluster.get('namespaceCrn')]
+        ]
       )
       response['dynamicClusters'] = True
 
@@ -136,10 +145,10 @@ def get_context_computes(request, interface):
   if interface == 'impala' or interface == 'jobs':
     if [cluster for cluster in clusters if cluster['type'] == 'altus']:
       computes.extend([{
-          'id': cluster.get('crn', 'None'),
-          'name': cluster.get('clusterName', 'Unknown'),
+          'id': cluster.get('crn'),
+          'name': cluster.get('clusterName'),
           'status': cluster.get('status'),
-          'namespace': cluster.get('namespaceCrn'),
+          'namespace': cluster.get('namespaceCrn', cluster.get('clusterName')),
           'type': 'altus-adb'
         } for cluster in AnalyticDbApi(request.user).list_clusters()['clusters']]
       )

+ 3 - 3
desktop/core/src/desktop/static/desktop/js/dataCatalog.js

@@ -179,7 +179,7 @@ var DataCatalog = (function () {
       }
       var deferred = $.Deferred();
 
-      var identifier = dataCatalogEntry.namespace.id + '_' + (dataCatalogEntry.compute ? dataCatalogEntry.compute.id : '');
+      var identifier = (dataCatalogEntry.namespace ? dataCatalogEntry.namespace.id : '') + '_' + (dataCatalogEntry.compute ? dataCatalogEntry.compute.id : '');
       if (dataCatalogEntry.path.length) {
         identifier += '_' + dataCatalogEntry.path.join('.');
       }
@@ -345,7 +345,7 @@ var DataCatalog = (function () {
     DataCatalog.prototype.getKnownEntry = function (options) {
       var self = this;
       var identifier = typeof options.path === 'string' ? options.path : options.path.join('.');
-      identifier = options.namespace.id + '_' + options.compute.id + (identifier ? '_' + identifier : '');
+      identifier = (options.namespace ? options.namespace.id : '') + '_' + (options.compute ? options.compute.id : '') + (identifier ? '_' + identifier : '');
       return self.entries[identifier];
     };
 
@@ -361,7 +361,7 @@ var DataCatalog = (function () {
     DataCatalog.prototype.getEntry = function (options) {
       var self = this;
       var identifier = typeof options.path === 'string' ? options.path : options.path.join('.');
-      identifier = options.namespace.id + '_' + (options.compute ? options.compute.id : '') + (identifier ? '_' + identifier : '');
+      identifier = (options.namespace ? options.namespace.id : '') + '_' + (options.compute ? options.compute.id : '') + (identifier ? '_' + identifier : '');
       if (self.entries[identifier]) {
         return self.entries[identifier];
       }

+ 8 - 0
desktop/libs/notebook/src/notebook/static/notebook/js/notebook.ko.js

@@ -367,6 +367,14 @@ var EditorViewModel = (function() {
     });*/
 
     self.compute = ko.observable();
+    self.compute.subscribe(function(newCompute) {
+      $.each(self.availableNamespaces(), function(index, namespace) {console.log(newCompute.namespace); console.log(namespace.name);
+        if (namespace.name == newCompute.namespace) {
+          self.namespace(namespace);
+          return;
+        }
+      });
+    });
 
     var computesPromise = ContextCatalog.getComputes({ sourceType: self.type() }).done(function (computes) {
       self.availableComputes(computes);

+ 1 - 1
desktop/libs/notebook/src/notebook/templates/editor_components.mako

@@ -950,7 +950,7 @@ ${ sqlSyntaxDropdown.sqlSyntaxDropdown() }
     <span class="editor-header-title"><i class="fa fa-warning"></i> ${ _('No computes found') }</span>
     <!-- /ko -->
     <!-- /ko -->
-    <!-- ko if: (availableNamespaces().length > 1 || namespaceRefreshEnabled() -->
+    <!-- ko if: (availableNamespaces().length > 1 || namespaceRefreshEnabled()) -->
     <span class="editor-header-title">${ _('Namespace') }</span>
     <div data-bind="component: { name: 'hue-drop-down', params: { value: namespace, entries: availableNamespaces, labelAttribute: 'name', searchable: true, linkTitle: '${ _ko('Active namespace') }' } }" style="display: inline-block"></div>
     <!-- /ko -->