Forráskód Böngészése

HUE-5895 [metadata] Show useful part of error when DB creation fails because of permissions

Romain Rigaux 8 éve
szülő
commit
f1ee5d6

+ 6 - 10
desktop/libs/indexer/src/indexer/api3.py

@@ -26,6 +26,7 @@ from desktop.lib.django_util import JsonResponse
 from desktop.lib.exceptions_renderable import PopupException
 from desktop.models import Document2
 from notebook.connectors.base import get_api, Notebook
+from notebook.decorators import api_error_handler
 from notebook.models import make_notebook
 
 from indexer.controller import CollectionManagerController
@@ -149,6 +150,7 @@ def index_file(request):
   return JsonResponse(job_handle)
 
 
+@api_error_handler
 def importer_submit(request):
   source = json.loads(request.POST.get('source', '{}'))
   outputFormat = json.loads(request.POST.get('destination', '{}'))['outputFormat']
@@ -189,19 +191,13 @@ def create_database(request, source, destination):
   editor_type = 'hive'
   on_success_url = reverse('metastore:show_tables', kwargs={'database': database})
 
-  try:
-    notebook = make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready', on_success_url=on_success_url)
-    return notebook.execute(request, batch=False)
-  except Exception, e:
-    raise PopupException(_('The table could not be created.'), detail=e.message)
+  notebook = make_notebook(name='Execute and watch', editor_type=editor_type, statement=sql, status='ready', on_success_url=on_success_url)
+  return notebook.execute(request, batch=False)
 
 
 def _create_table(request, source, destination):
-  try:
-    notebook = _create_table_from_a_file(request, source, destination)
-    return notebook.execute(request, batch=False)
-  except Exception, e:
-    raise PopupException(_('The table could not be created.'), detail=e.message)
+  notebook = _create_table_from_a_file(request, source, destination)
+  return notebook.execute(request, batch=False)
 
 
 def _create_table_from_a_file(request, source, destination):

+ 60 - 54
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -1534,65 +1534,71 @@ ${ assist.assistPanel() }
           "source": ko.mapping.toJSON(self.source),
           "destination": ko.mapping.toJSON(self.destination)
         }, function (resp) {
-          self.showCreate(true);
-          self.editorId(resp.history_id);
-          self.jobId(resp.handle.id);
-          $('#importerNotebook').html($('#importerNotebook-progress').html());
-
-          self.editorVM = new EditorViewModel(resp.history_uuid, '', {
-            user: '${ user.username }',
-            userId: ${ user.id },
-            languages: [{name: "Java", type: "java"}, {name: "Hive SQL", type: "hive"}], // TODO reuse
-            snippetViewSettings: {
-              java : {
-                snippetIcon: 'fa-file-archive-o '
-              },
-              hive: {
-                placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
-                aceMode: 'ace/mode/hive',
-                snippetImage: '${ static("beeswax/art/icon_beeswax_48.png") }',
-                sqlDialect: true
-              },
-              impala: {
-                placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
-                aceMode: 'ace/mode/impala',
-                snippetImage: '${ static("impala/art/icon_impala_48.png") }',
-                sqlDialect: true
-              }
-            }
-          });
-          self.editorVM.editorMode(true);
-          self.editorVM.isNotificationManager(true);
-          ko.cleanNode($("#importerNotebook")[0]);
-          ko.applyBindings(self.editorVM, $("#importerNotebook")[0]);
-
-          self.editorVM.openNotebook(resp.history_uuid, null, true, function(){
-            self.editorVM.selectedNotebook().snippets()[0].progress.subscribe(function(val){
-              if (val == 100){
-                self.indexingStarted(false);
-                self.isIndexing(false);
-                self.indexingSuccess(true);
+          if (resp.status != 0) {
+            $(document).trigger("error", resp.message);
+            self.indexingStarted(false);
+            self.isIndexing(false);
+          } else {
+            self.showCreate(true);
+            self.editorId(resp.history_id);
+            self.jobId(resp.handle.id);
+            $('#importerNotebook').html($('#importerNotebook-progress').html());
+
+            self.editorVM = new EditorViewModel(resp.history_uuid, '', {
+              user: '${ user.username }',
+              userId: ${ user.id },
+              languages: [{name: "Java", type: "java"}, {name: "Hive SQL", type: "hive"}], // TODO reuse
+              snippetViewSettings: {
+                java : {
+                  snippetIcon: 'fa-file-archive-o '
+                },
+                hive: {
+                  placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
+                  aceMode: 'ace/mode/hive',
+                  snippetImage: '${ static("beeswax/art/icon_beeswax_48.png") }',
+                  sqlDialect: true
+                },
+                impala: {
+                  placeHolder: '${ _("Example: SELECT * FROM tablename, or press CTRL + space") }',
+                  aceMode: 'ace/mode/impala',
+                  snippetImage: '${ static("impala/art/icon_impala_48.png") }',
+                  sqlDialect: true
+                }
               }
             });
-            self.editorVM.selectedNotebook().snippets()[0].status.subscribe(function(val){
-              if (val == 'failed'){
-                self.isIndexing(false);
-                self.indexingStarted(false);
-                self.indexingError(true);
-              } else if (val == 'available') {
-                var snippet = self.editorVM.selectedNotebook().snippets()[0]; // Could be native to editor at some point
-                if (! snippet.result.handle().has_more_statements) {
-                  if (self.editorVM.selectedNotebook().onSuccessUrl()) {
-                    huePubSub.publish('assist.clear.db.cache', {sourceType: 'hive'});
-                    window.location.href = self.editorVM.selectedNotebook().onSuccessUrl();
+            self.editorVM.editorMode(true);
+            self.editorVM.isNotificationManager(true);
+            ko.cleanNode($("#importerNotebook")[0]);
+            ko.applyBindings(self.editorVM, $("#importerNotebook")[0]);
+
+            self.editorVM.openNotebook(resp.history_uuid, null, true, function(){
+              self.editorVM.selectedNotebook().snippets()[0].progress.subscribe(function(val){
+                if (val == 100){
+                  self.indexingStarted(false);
+                  self.isIndexing(false);
+                  self.indexingSuccess(true);
+                }
+              });
+              self.editorVM.selectedNotebook().snippets()[0].status.subscribe(function(val){
+                if (val == 'failed'){
+                  self.isIndexing(false);
+                  self.indexingStarted(false);
+                  self.indexingError(true);
+                } else if (val == 'available') {
+                  var snippet = self.editorVM.selectedNotebook().snippets()[0]; // Could be native to editor at some point
+                  if (! snippet.result.handle().has_more_statements) {
+                    if (self.editorVM.selectedNotebook().onSuccessUrl()) {
+                      huePubSub.publish('assist.clear.db.cache', {sourceType: 'hive'});
+                      window.location.href = self.editorVM.selectedNotebook().onSuccessUrl();
+                    }
+                  } else { // Perform last DROP statement execute
+                    snippet.execute();
                   }
-                } else { // Perform last DROP statement execute
-                  snippet.execute();
                 }
-              }
+              });
+              self.editorVM.selectedNotebook().snippets()[0].checkStatus();
             });
-            self.editorVM.selectedNotebook().snippets()[0].checkStatus();
-          });
+          }
           viewModel.isLoading(false);
         }).fail(function (xhr, textStatus, errorThrown) {
           $(document).trigger("error", xhr.responseText);