浏览代码

HUE-3450 [metadata] Enable enrichment of table list

Romain Rigaux 9 年之前
父节点
当前提交
d37815f

+ 5 - 0
apps/metastore/src/metastore/static/metastore/js/metastore.ko.js

@@ -115,7 +115,11 @@
       $.post('/metadata/api/optimizer_api/top_tables', function(data){
       $.post('/metadata/api/optimizer_api/top_tables', function(data){
         if (data && data.status == 0) {
         if (data && data.status == 0) {
           self.optimizerStats(ko.mapping.fromJS(data.top_tables));
           self.optimizerStats(ko.mapping.fromJS(data.top_tables));
+        } else {
+          $(document).trigger("error", data.message);
         }
         }
+      }).fail(function (xhr, textStatus, errorThrown) {
+        $(document).trigger("error", xhr.responseText);
       });
       });
     }
     }
 
 
@@ -453,6 +457,7 @@
     self.isLeftPanelVisible = ko.observable();
     self.isLeftPanelVisible = ko.observable();
     self.assistHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
     self.assistHelper.withTotalStorage('assist', 'assist_panel_visible', self.isLeftPanelVisible, true);
     self.optimizerEnabled = options.optimizerEnabled || false;
     self.optimizerEnabled = options.optimizerEnabled || false;
+    self.optimizerUrl = ko.observable(options.optimizer_url);
 
 
     huePubSub.subscribe("assist.db.panel.ready", function () {
     huePubSub.subscribe("assist.db.panel.ready", function () {
       huePubSub.publish('assist.set.database', {
       huePubSub.publish('assist.set.database', {

+ 19 - 1
apps/metastore/src/metastore/templates/metastore.mako

@@ -374,7 +374,7 @@ ${ assist.assistPanel() }
       </div>
       </div>
       <!-- /ko -->
       <!-- /ko -->
 
 
-      %if is_optimizer_enabled:
+      %if is_optimizer_enabled and False:
       <!-- ko with: optimizerStats  -->
       <!-- ko with: optimizerStats  -->
       <div class="span4 tile chart-container">
       <div class="span4 tile chart-container">
         <h4>${ _('Navigator optimizer') }</h4>
         <h4>${ _('Navigator optimizer') }</h4>
@@ -417,6 +417,13 @@ ${ assist.assistPanel() }
               </form>
               </form>
             </div>
             </div>
           % endif
           % endif
+          <!-- ko with: $root.optimizerEnabled  -->
+          &nbsp;
+          &nbsp;
+          <button class="btn toolbarBtn" title="${_('View the selected table')}" data-bind="click: function () { location.href = $root.optimizerUrl() + 'optimizer/#/table/12'; }, disable: $parent.selectedTables().length !== 1">
+            <i class="fa fa-eye"></i> ${_('View in Optimizer')}
+          </button>          
+          <!-- /ko -->
         </div>
         </div>
 
 
         <table id="tablesTable" class="table table-striped table-condensed table-nowrap" style="margin-bottom: 10px; width: 100%" data-bind="visible: filteredTables().length > 0">
         <table id="tablesTable" class="table table-striped table-condensed table-nowrap" style="margin-bottom: 10px; width: 100%" data-bind="visible: filteredTables().length > 0">
@@ -426,6 +433,10 @@ ${ assist.assistPanel() }
             <th>&nbsp;</th>
             <th>&nbsp;</th>
             <th>${ _('Table Name') }</th>
             <th>${ _('Table Name') }</th>
             <th width="50%">${ _('Comment') }</th>
             <th width="50%">${ _('Comment') }</th>
+            <!-- ko with: $root.optimizerEnabled  -->
+            <th width="10%">${ _('Popularity') }</th>
+            <th width="10%">${ _('Columns') }</th>
+            <!-- /ko -->
             <th width="1%">${ _('Type') }</th>
             <th width="1%">${ _('Type') }</th>
           </tr>
           </tr>
           </thead>
           </thead>
@@ -447,6 +458,10 @@ ${ assist.assistPanel() }
                 <a class="tableLink" href="javascript:void(0);" data-bind="text: name, click: function() { $parent.setTable($data, function(){ huePubSub.publish('metastore.url.change'); }) }"></a>
                 <a class="tableLink" href="javascript:void(0);" data-bind="text: name, click: function() { $parent.setTable($data, function(){ huePubSub.publish('metastore.url.change'); }) }"></a>
               </td>
               </td>
               <td data-bind="text: comment"></td>
               <td data-bind="text: comment"></td>
+              <!-- ko with: $root.optimizerEnabled  -->
+                <td data-bind="text: 100"></td>
+                <td data-bind="text: 15"></td>
+              <!-- /ko -->
               <td class="center">
               <td class="center">
                 <!-- ko if: type == 'Table' -->
                 <!-- ko if: type == 'Table' -->
                   <i class="fa fa-fw fa-table muted" title="${ _('Table') }"></i>
                   <i class="fa fa-fw fa-table muted" title="${ _('Table') }"></i>
@@ -454,6 +469,9 @@ ${ assist.assistPanel() }
                 <!-- ko if: type == 'View' -->
                 <!-- ko if: type == 'View' -->
                   <i class="fa fa-fw fa-eye muted" title="${ _('View') }"></i>
                   <i class="fa fa-fw fa-eye muted" title="${ _('View') }"></i>
                 <!-- /ko -->
                 <!-- /ko -->
+                <!-- ko with: $root.optimizerEnabled  -->
+                  <i class="fa fa-fw fa-cubes muted" title="${ _('View') }"></i>
+                <!-- /ko -->
               </td>
               </td>
             </tr>
             </tr>
           </tbody>
           </tbody>

+ 5 - 1
apps/metastore/src/metastore/views.py

@@ -31,6 +31,8 @@ from desktop.lib.django_util import JsonResponse, render
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.models import Document, Document2
 from desktop.models import Document, Document2
 
 
+from metadata.conf import has_optimizer, get_optimizer_url
+
 from beeswax.design import hql_query
 from beeswax.design import hql_query
 from beeswax.models import SavedQuery, MetaInstall
 from beeswax.models import SavedQuery, MetaInstall
 from beeswax.server import dbms
 from beeswax.server import dbms
@@ -113,7 +115,7 @@ def get_database_metadata(request, database):
     response['data'] = db_metadata
     response['data'] = db_metadata
   except Exception, ex:
   except Exception, ex:
     response['status'] = 1
     response['status'] = 1
-    response['data'] = _("Cannot get metadata for database: %s") % (database,)
+    response['data'] = _("Cannot get metadata for database %s: %s") % (database, ex)
 
 
   return JsonResponse(response)
   return JsonResponse(response)
 
 
@@ -177,6 +179,8 @@ def show_tables(request, database=None):
     'database': None,
     'database': None,
     'partitions': [],
     'partitions': [],
     'has_write_access': has_write_access(request.user),
     'has_write_access': has_write_access(request.user),
+    'is_optimizer_enabled': has_optimizer(),
+    'optimizer_url': get_optimizer_url()
     })
     })
 
 
   return resp
   return resp

+ 10 - 0
desktop/libs/metadata/src/metadata/conf.py

@@ -38,6 +38,9 @@ def get_auth_password():
 def get_optimizer_url():
 def get_optimizer_url():
   return OPTIMIZER.API_URL.get() and OPTIMIZER.API_URL.get().strip('/')
   return OPTIMIZER.API_URL.get() and OPTIMIZER.API_URL.get().strip('/')
 
 
+def has_optimizer():
+  return bool(get_optimizer_url())
+
 
 
 OPTIMIZER = ConfigSection(
 OPTIMIZER = ConfigSection(
   key='optimizer',
   key='optimizer',
@@ -98,6 +101,13 @@ OPTIMIZER = ConfigSection(
       help=_t("In secure mode (HTTPS), if Optimizer SSL certificates have to be verified against certificate authority"),
       help=_t("In secure mode (HTTPS), if Optimizer SSL certificates have to be verified against certificate authority"),
       dynamic_default=default_ssl_validate,
       dynamic_default=default_ssl_validate,
       type=coerce_bool
       type=coerce_bool
+    ),
+
+    MOCKING = Config(
+      key="mocking",
+      help=_t("Use mock data"),
+      default=True,
+      type=coerce_bool
     )
     )
   )
   )
 )
 )

+ 9 - 1
desktop/libs/metadata/src/metadata/optimizer_api.py

@@ -17,6 +17,7 @@
 
 
 import json
 import json
 import logging
 import logging
+import random
 
 
 from django.http import Http404
 from django.http import Http404
 from django.utils.translation import ugettext as _
 from django.utils.translation import ugettext as _
@@ -28,6 +29,8 @@ from desktop.models import Document2
 from notebook.models import Notebook
 from notebook.models import Notebook
 
 
 from metadata.optimizer_client import OptimizerApi
 from metadata.optimizer_client import OptimizerApi
+from metadata.conf import OPTIMIZER
+
 
 
 LOG = logging.getLogger(__name__)
 LOG = logging.getLogger(__name__)
 
 
@@ -53,9 +56,14 @@ def error_handler(view_fn):
 def top_tables(request):
 def top_tables(request):
   response = {'status': -1}
   response = {'status': -1}
 
 
+  len = request.POST.get('len', 500)
+
   api = OptimizerApi()
   api = OptimizerApi()
 
 
-  response['top_tables'] = api.top_tables()
+  response['top_tables'] = api.top_tables() if not OPTIMIZER.MOCKING.get() else [
+      {'name': 'a', 'popularity': random.randint(1, 100) , 'column_count': random.randint(1, 100), 'is_fact': bool(random.getrandbits(1))}
+    for i in xrange(0, len)
+  ]
   response['status'] = 0
   response['status'] = 0
 
 
   return JsonResponse(response)
   return JsonResponse(response)