Ver Fonte

HUE-8758 [editor] Inform the user from correctly installed or not samples

Romain há 5 anos atrás
pai
commit
1710570568

+ 9 - 8
apps/about/src/about/templates/admin_wizard.mako

@@ -324,21 +324,22 @@ ${ layout.menubar(section='quick_start') }
       $.post("${ url('notebook:install_examples') }", {
           connector: connector.type
         }, function(data) {
-        if (data.status == 0) {
-          $(document).trigger('info','${ _("Examples refreshed") }');
-          if ($(button).data("is-connector")) {
+          if (data.message) {
+            $(document).trigger('info', data.message);
+          }
+          if (data.errorMessage) {
+            $(document).trigger('error', data.errorMessage);
+          }
+          if (data.status == 0 && $(button).data("is-connector")) {
             huePubSub.publish('cluster.config.refresh.config');
           }
-        } else {
-          $(document).trigger('error', data.message);
-        }
       }).always(function(data) {
         self.isInstallingSample(false);
       });
     }
   }
 
-  function installConnectorDataExample() {
+  function installConnectorExample() {
     var button = $(this);
     $(button).button('loading');
     $.post(button.data("sample-url"), function(data) {
@@ -389,7 +390,7 @@ ${ layout.menubar(section='quick_start') }
       huePubSub.publish('cluster.config.refresh.config', configUpdated);
     % endif
 
-    $(".installBtn").click(installConnectorDataExample);
+    $(".installBtn").click(installConnectorExample);
 
     $(".installAllBtn").click(function() {
       var button = $(this);

+ 20 - 10
apps/beeswax/src/beeswax/management/commands/beeswax_install_examples.py

@@ -68,18 +68,19 @@ class Command(BaseCommand):
     )
     exception = None
 
+
+    self.successes = []
+    self.errors = []
     try:
       sample_user = install_sample_user(user)  # Documents will belong to the sample user but we run the SQL as the current user
-      self._install_queries(sample_user, dialect, interpreter=interpreter)
-      self._install_tables(user, dialect, db_name, tables, interpreter=interpreter, request=request)
+      self.install_queries(sample_user, dialect, interpreter=interpreter)
+      self.install_tables(user, dialect, db_name, tables, interpreter=interpreter, request=request)
     except Exception as ex:
       exception = ex
 
     if exception is not None:
       pretty_msg = None
 
-      if "AlreadyExistsException" in str(exception):
-        pretty_msg = _("SQL table examples already installed.")
       if "Permission denied" in str(exception):
         pretty_msg = _("Permission denied. Please check with your system administrator.")
 
@@ -88,7 +89,10 @@ class Command(BaseCommand):
       else:
         raise exception
 
-  def _install_tables(self, django_user, dialect, db_name, tables, interpreter=None, request=None):
+    return self.successes, self.errors
+
+
+  def install_tables(self, django_user, dialect, db_name, tables, interpreter=None, request=None):
     data_dir = LOCAL_EXAMPLES_DATA_DIR.get()
     table_file = open(os.path.join(data_dir, tables))
     table_list = json.load(table_file)
@@ -100,16 +104,18 @@ class Command(BaseCommand):
       raise InstallException(_('No %s tables are available as samples') % dialect)
 
     for table_dict in table_list:
+      full_name = '%s.%s' % (db_name, table_dict['table_name'])
       try:
         table = SampleTable(table_dict, dialect, db_name, interpreter=interpreter, request=request)
         table.install(django_user)
+        self.successes.append(_('Table %s installed.') % full_name)
       except Exception as ex:
         msg = str(ex)
         LOG.error(msg)
-        raise InstallException(_('Could not install table %s: %s') % (table_dict['table_name'], msg))
+        self.errors.append(_('Could not install table %s: %s') % (full_name, msg))
 
 
-  def _install_queries(self, django_user, dialect, interpreter=None):
+  def install_queries(self, django_user, dialect, interpreter=None):
     design_file = open(os.path.join(LOCAL_EXAMPLES_DATA_DIR.get(), 'queries.json'))
     design_list = json.load(design_file)
     design_file.close()
@@ -127,8 +133,11 @@ class Command(BaseCommand):
       design = SampleQuery(design_dict)
       try:
         design.install(django_user, interpreter=interpreter)
+        self.successes.append(_('Query %s %s installed.') % (design_dict['name'], dialect))
       except Exception as ex:
-        raise InstallException(_('Could not install %s query: %s') % (dialect, ex))
+        msg = str(ex)
+        LOG.error(msg)
+        self.errors.append(_('Could not install %s query: %s') % (dialect, msg))
 
 
 class SampleTable(object):
@@ -196,8 +205,9 @@ class SampleTable(object):
 
       job.execute_and_wait(self.request)
     except Exception as ex:
-      if 'already exists' in str(ex):
-        LOG.warn('Table %s.%s already exists' % (self.db_name, self.name))
+      exception_string = str(ex)
+      if 'already exists' in exception_string or 'AlreadyExistsException' in exception_string:
+        raise PopupException('already exists')
       else:
         raise ex
 

+ 10 - 6
desktop/libs/notebook/src/notebook/views.py

@@ -392,7 +392,7 @@ def download(request):
 @require_POST
 @admin_required
 def install_examples(request):
-  response = {'status': -1, 'message': ''}
+  response = {'status': -1, 'message': '', 'errorMessage': ''}
 
   try:
     connector = Connector.objects.get(id=request.POST.get('connector'))
@@ -401,15 +401,19 @@ def install_examples(request):
       db_name = request.POST.get('db_name', 'default')
       interpreter = get_interpreter(connector_type=connector.to_dict()['type'], user=request.user)
 
-      beeswax_install_examples.Command().handle(
+      successes, errors = beeswax_install_examples.Command().handle(
           dialect=dialect, db_name=db_name, user=request.user, interpreter=interpreter, request=request
       )
+      response['message'] = ' '.join(successes)
+      response['errorMessage'] = ' '.join(errors)
+      response['status'] = len(errors)
     else:
-      Command().handle(user=request.user)  # Notebook examples
-    response['status'] = 0
+      Command().handle(user=request.user)
+      response['status'] = 0
+      response['message'] = _('Examples refreshed')
   except Exception as e:
-    msg = 'Error during Editor samples installation.'
+    msg = 'Error during Editor samples installation'
     LOG.exception(msg)
-    response['message'] = msg + ': ' + str(e)
+    response['errorMessage'] = msg + ': ' + str(e)
 
   return JsonResponse(response)