Pārlūkot izejas kodu

HUE-8758 [connectors] Update page with the new attributes like dialect

Romain 6 gadi atpakaļ
vecāks
revīzija
fe2b0d4824

+ 36 - 38
desktop/core/src/desktop/lib/connectors/api.py

@@ -32,8 +32,8 @@ LOG = logging.getLogger(__name__)
 # TODO: automatically load modules from lib module
 # TODO: offer to white/black list available connector classes
 CONNECTOR_TYPES = [{
-    'name': connector.NAME,
-    'type': connector.TYPE,
+    'nice_name': connector.NAME,
+    'dialect': connector.TYPE,
     'interface': connector.INTERFACE,
     'settings': connector.PROPERTIES,
     'id': None,
@@ -44,48 +44,46 @@ CONNECTOR_TYPES = [{
     Impala(), Hive()
   ]
 ]
-
-
 CONNECTOR_TYPES += [
-  {'name': "Hive Tez", 'type': 'hive-tez', 'interface': 'hiveserver2', 'settings': [{'name': 'server_host', 'value': ''}, {'name': 'server_port', 'value': ''},], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Hive LLAP", 'type': 'hive-llap', 'interface': 'hiveserver2', 'settings': [{'name': 'server_host', 'value': ''}, {'name': 'server_port', 'value': ''},], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Druid", 'type': 'sql-druid', 'interface': 'sqlalchemy', 'settings': [{'name': 'connection_url', 'value': 'druid://druid-host.com:8082/druid/v2/sql/'}], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Kafka SQL", 'type': 'kafka-sql', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "SparkSQL", 'type': 'spark-sql', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "MySQL", 'type': 'sql-mysql', 'interface': 'sqlalchemy', 'settings': [{'name': 'connection_url', 'value': 'mysql://username:password@mysq-host:3306/hue'}], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Presto", 'type': 'presto', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Athena", 'type': 'athena', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Redshift", 'type': 'redshift', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Big Query", 'type': 'bigquery', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Oracle", 'type': 'oracle', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "SQL Database", 'type': 'sql-alchemy', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "SQL Database (JDBC)", 'type': 'sql-jdbc', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': 'Deprecated: older way to connect to any database.'},
+  {'nice_name': "Hive Tez", 'dialect': 'hive-tez', 'interface': 'hiveserver2', 'settings': [{'name': 'server_host', 'value': ''}, {'name': 'server_port', 'value': ''},], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Hive LLAP", 'dialect': 'hive-llap', 'interface': 'hiveserver2', 'settings': [{'name': 'server_host', 'value': ''}, {'name': 'server_port', 'value': ''},], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Druid", 'dialect': 'sql-druid', 'interface': 'sqlalchemy', 'settings': [{'name': 'connection_url', 'value': 'druid://druid-host.com:8082/druid/v2/sql/'}], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Kafka SQL", 'dialect': 'kafka-sql', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "SparkSQL", 'dialect': 'spark-sql', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "MySQL", 'dialect': 'sql-mysql', 'interface': 'sqlalchemy', 'settings': [{'name': 'connection_url', 'value': 'mysql://username:password@mysq-host:3306/hue'}], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Presto", 'dialect': 'presto', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Athena", 'dialect': 'athena', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Redshift", 'dialect': 'redshift', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Big Query", 'dialect': 'bigquery', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Oracle", 'dialect': 'oracle', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "SQL Database", 'dialect': 'sql-alchemy', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "SQL Database (JDBC)", 'dialect': 'sql-jdbc', 'interface': 'sqlalchemy', 'settings': [], 'id': None, 'category': 'editor', 'description': 'Deprecated: older way to connect to any database.'},
   # solr
   # hbase
   # kafka
 
-  {'name': "PySpark", 'type': 'pyspark', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Spark", 'type': 'spark', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Pig", 'type': 'pig', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
-  {'name': "Java", 'type': 'java', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "PySpark", 'dialect': 'pyspark', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Spark", 'dialect': 'spark', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Pig", 'dialect': 'pig', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
+  {'nice_name': "Java", 'dialect': 'java', 'settings': [], 'id': None, 'category': 'editor', 'description': ''},
 
-  {'name': "HDFS", 'type': 'hdfs', 'settings': [], 'id': None, 'category': 'browsers', 'description': ''},
-  {'name': "YARN", 'type': 'yarn', 'settings': [], 'id': None, 'category': 'browsers', 'description': ''},
-  {'name': "S3", 'type': 's3', 'settings': [], 'id': None, 'category': 'browsers', 'description': ''},
-  {'name': "ADLS", 'type': 'adls-v1', 'settings': [], 'id': None, 'category': 'browsers', 'description': ''},
+  {'nice_name': "HDFS", 'dialect': 'hdfs', 'settings': [], 'id': None, 'category': 'browsers', 'description': ''},
+  {'nice_name': "YARN", 'dialect': 'yarn', 'settings': [], 'id': None, 'category': 'browsers', 'description': ''},
+  {'nice_name': "S3", 'dialect': 's3', 'settings': [], 'id': None, 'category': 'browsers', 'description': ''},
+  {'nice_name': "ADLS", 'dialect': 'adls-v1', 'settings': [], 'id': None, 'category': 'browsers', 'description': ''},
 
-  {'name': "Hive Metastore", 'type': 'hms', 'settings': [], 'id': None, 'category': 'catalogs', 'description': ''},
-  {'name': "Atlas", 'type': 'atlas', 'settings': [], 'id': None, 'category': 'catalogs', 'description': ''},
-  {'name': "Navigator", 'type': 'navigator', 'settings': [], 'id': None, 'category': 'catalogs', 'description': ''},
+  {'nice_name': "Hive Metastore", 'dialect': 'hms', 'settings': [], 'id': None, 'category': 'catalogs', 'description': ''},
+  {'nice_name': "Atlas", 'dialect': 'atlas', 'settings': [], 'id': None, 'category': 'catalogs', 'description': ''},
+  {'nice_name': "Navigator", 'dialect': 'navigator', 'settings': [], 'id': None, 'category': 'catalogs', 'description': ''},
 
-  {'name': "Optimizer", 'type': 'optimizer', 'settings': [], 'id': None, 'category': 'optimizers', 'description': ''},
+  {'nice_name': "Optimizer", 'dialect': 'optimizer', 'settings': [], 'id': None, 'category': 'optimizers', 'description': ''},
 
-  {'name': "Oozie", 'type': 'oozie', 'settings': [], 'id': None, 'category': 'schedulers', 'description': ''},
-  {'name': "Celery", 'type': 'celery', 'settings': [], 'id': None, 'category': 'schedulers', 'description': '' },
+  {'nice_name': "Oozie", 'dialect': 'oozie', 'settings': [], 'id': None, 'category': 'schedulers', 'description': ''},
+  {'nice_name': "Celery", 'dialect': 'celery', 'settings': [], 'id': None, 'category': 'schedulers', 'description': '' },
 ]
 
 CATEGORIES = [
-  {"name": "Editor", 'type': 'engines', 'description': ''},
+  {"name": "Editor", 'type': 'editor', 'description': ''},
   {"name": "Browsers", 'type': 'browsers', 'description': ''},
   {"name": "Catalogs", 'type': 'catalogs', 'description': ''},
   {"name": "Optimizers", 'type': 'optimizers', 'description': ''},
@@ -162,10 +160,10 @@ def get_installed_connectors(request):
   })
 
 
-def new_connector(request, type):
-  instance = _get_connector_by_type(type)
+def new_connector(request, dialect):
+  instance = _get_connector_by_type(dialect)
 
-  instance['connector_name'] = ''
+  instance['nice_name'] = ''
 
   return JsonResponse({'connector': instance})
 
@@ -190,7 +188,7 @@ def update_connector(request):
     saved_as = True
     instance = connector
     instance['id'] = CONNECTOR_IDS
-    instance['connector_name'] = instance['type']
+    instance['nice_name'] = instance['nice_name']
     instance['type'] = '%s-%s' % (instance['type'], CONNECTOR_IDS)
     CONNECTOR_IDS += 1
     CONNECTOR_INSTANCES.append(instance)
@@ -198,10 +196,10 @@ def update_connector(request):
   return JsonResponse({'connector': instance, 'saved_as': saved_as})
 
 
-def _get_connector_by_type(type):
+def _get_connector_by_type(dialect):
   global CONNECTOR_TYPES
 
-  instance = filter(lambda connector: connector['type'] == type, CONNECTOR_TYPES)
+  instance = filter(lambda connector: connector['dialect'] == dialect, CONNECTOR_TYPES)
 
   if instance:
     return instance[0]

+ 1 - 1
desktop/core/src/desktop/lib/connectors/urls.py

@@ -26,7 +26,7 @@ urlpatterns = [
   url(r'^api/types/?$', api.get_connector_classes, name='connectors.api.get_connector_classes'),
   url(r'^api/instances/?$', api.get_installed_connectors, name='connectors.api.get_installed_connectors'),
 
-  url(r'^api/instance/new/(?P<type>[\w\-]+)$', api.new_connector, name='connectors.api.new_connector'),
+  url(r'^api/instance/new/(?P<dialect>[\w\-]+)$', api.new_connector, name='connectors.api.new_connector'),
   url(r'^api/instance/get/(?P<id>\d+)$', api.get_connector, name='connectors.api.get_connector'),
   url(r'^api/instance/delete/?$', api.delete_connector, name='connectors.api.delete_connector'),
   url(r'^api/instance/update/?$', api.update_connector, name='connectors.api.update_connector'),

+ 45 - 29
desktop/core/src/desktop/templates/connectors.mako

@@ -64,7 +64,11 @@ else:
           var lowerQuery = self.connectorsFilter().toLowerCase();
           var filteredConnectors = []
           connectors.forEach(function (connector) {
-            var _connector = {"category": connector.category, "category_name": $.grep(categories, function(cat) { return cat.type == connector.category})[0].category_name, "values": []};
+            var _connector = {
+                "category": connector.category,
+                "category_name": $.grep(self.categories(), function(cat) { return cat.type == connector.category})[0].category_name,
+                "values": []
+            };
             _connector.values = connector.values.filter(function (subMetricKey) {
               return subMetricKey.name.toLowerCase().indexOf(lowerQuery) !== -1;
             });
@@ -84,49 +88,61 @@ else:
 
       self.fetchConnectors = function () {
         self.fetchConnectorTypes(); // TODO: might be cleaner to chain below
-        self.apiHelper.simpleGet('/desktop/connectors/api/instances/', {}, {successCallback: function (data) {
-          self.instances(data.connectors);
-        }});
+        self.apiHelper.simpleGet('/desktop/connectors/api/instances/', {}, {
+          successCallback: function (data) {
+            self.instances(data.connectors);
+          }
+        });
       };
       self.editConnector = function (data) {
         if (self.section() == 'installed-connectors-page') {
           self.instance(data);
         } else {
-          self.newConnector(data.type);
+          self.newConnector(data.dialect);
         }
         self.section('connector-page');
       };
 
-      self.newConnector = function (type) {
-        self.apiHelper.simpleGet('/desktop/connectors/api/instance/new/' + type, {}, {successCallback: function (data) {
+      self.newConnector = function (dialect) {
+        self.apiHelper.simpleGet('/desktop/connectors/api/instance/new/' + dialect, {}, {
+          successCallback: function (data) {
           self.instance(ko.mapping.fromJS(data.connector));
-        }});
+          }
+        });
       };
       self.fetchConnector = function (id) {
-        self.apiHelper.simpleGet('/desktop/connectors/api/instance/get/' + id, {}, {successCallback: function (data) {
-          self.instance(ko.mapping.fromJS(data.connector));
-        }});
+        self.apiHelper.simpleGet('/desktop/connectors/api/instance/get/' + id, {}, {
+          successCallback: function (data) {
+            self.instance(ko.mapping.fromJS(data.connector));
+          }
+        });
       };
       self.deleteConnector = function (connector) {
-        self.apiHelper.simplePost('/desktop/connectors/api/instance/delete', {'connector': ko.mapping.toJSON(connector)}, {successCallback: function (data) {
-          self.section('installed-connectors-page');
-          self.fetchConnectors();
-          huePubSub.publish('cluster.config.refresh.config');
-        }});
+        self.apiHelper.simplePost('/desktop/connectors/api/instance/delete', {'connector': ko.mapping.toJSON(connector)}, {
+          successCallback: function (data) {
+            self.section('installed-connectors-page');
+            self.fetchConnectors();
+            huePubSub.publish('cluster.config.refresh.config');
+          }
+        });
       };
       self.updateConnector = function (connector) {
-        self.apiHelper.simplePost('/desktop/connectors/api/instance/update', {'connector': ko.mapping.toJSON(connector)}, {successCallback: function (data) {
-          connector.id = data.connector.id;
-          self.section('installed-connectors-page');
-          self.fetchConnectors();
-          huePubSub.publish('cluster.config.refresh.config');
-        }});
+        self.apiHelper.simplePost('/desktop/connectors/api/instance/update', {'connector': ko.mapping.toJSON(connector)}, {
+          successCallback: function (data) {
+            connector.id = data.connector.id;
+            self.section('installed-connectors-page');
+            self.fetchConnectors();
+            huePubSub.publish('cluster.config.refresh.config');
+          }
+        });
       };
       self.fetchConnectorTypes = function () {
-        self.apiHelper.simpleGet('/desktop/connectors/api/types/', {}, {successCallback: function (data) {
-          self.connectors(data.connectors);
-          self.categories(data.categories);
-        }});
+        self.apiHelper.simpleGet('/desktop/connectors/api/types/', {}, {
+          successCallback: function (data) {
+            self.connectors(data.connectors);
+            self.categories(data.categories);
+          }
+        });
       };
     }
 
@@ -228,7 +244,7 @@ ${ layout.menubar(section='connectors') }
               <!-- ko if: $data.values.length > 0 -->
               <tbody data-bind="foreach: values">
                 <tr data-bind="click: $root.editConnector">
-                  <td data-bind="text: name"></td>
+                  <td data-bind="text: nice_name"></td>
                   <td data-bind="text: description"></td>
                 </tr>
               </tbody>
@@ -282,10 +298,10 @@ ${ layout.menubar(section='connectors') }
 
 <script type="text/html" id="connector-page">
   <div class="row-fluid">
-    <input data-bind="value: name">
+    <input data-bind="value: nice_name">
     <!-- ko if: typeof id != 'undefined' -->
       <!-- ko if: id -->
-        (<span data-bind="text: connector_name"></span>)
+        (<span data-bind="text: name"></span>)
         <a href="javascript:void(0)" data-bind="click: $root.updateConnector">
           ${ _('Update') }
         </a>

+ 1 - 1
desktop/libs/notebook/src/notebook/conf.py

@@ -90,7 +90,7 @@ def get_ordered_interpreters(user=None):
     ]
 
   return [{
-      "name": i['name'],
+      "name": i.get('nice_name', i['name']),
       "type": i['type'],
       "interface": i['interface'],
       "options": i['options'],