Jelajahi Sumber

HUE-9100 [editor] Reuse session when opening notebook

Jean-Francois Desjeans Gauthier 6 tahun lalu
induk
melakukan
644b5bc7b1

+ 2 - 2
apps/filebrowser/src/filebrowser/templates/listdir_components.mako

@@ -1760,7 +1760,7 @@ from filebrowser.conf import ENABLE_EXTRACT_UPLOADED_ARCHIVE
         }, function (data) {
           if (data.status == 0) {
             $.jHueNotify.info("${ _('Task ') }" + data.history_uuid + "${_(' submitted.') }");
-            huePubSub.publish('notebook.task.submitted', data.history_uuid);
+            huePubSub.publish('notebook.task.submitted', data);
           } else {
             $(document).trigger("error", data.message);
           }
@@ -1796,7 +1796,7 @@ from filebrowser.conf import ENABLE_EXTRACT_UPLOADED_ARCHIVE
         }, function (data) {
           if (data.status == 0) {
             $.jHueNotify.info("${ _('Task ') }" + data.history_uuid + "${_(' submitted.') }");
-            huePubSub.publish('notebook.task.submitted', data.history_uuid);
+            huePubSub.publish('notebook.task.submitted', data);
           } else {
             $(document).trigger("error", data.message);
           }

+ 2 - 2
apps/metastore/src/metastore/templates/metastore.mako

@@ -991,7 +991,7 @@ ${ components.menubar(is_embeddable) }
       dataType: 'json',
       success: function(resp) {
         if (resp.history_uuid) {
-          huePubSub.publish('notebook.task.submitted', resp.history_uuid);
+          huePubSub.publish('notebook.task.submitted', resp);
           huePubSub.publish('metastore.clear.selection');
         } else if (resp && resp.message) {
           $(document).trigger("error", resp.message);
@@ -1029,7 +1029,7 @@ ${ components.menubar(is_embeddable) }
       cluster: compute
     },function(resp) {
       if (resp.history_uuid) {
-        huePubSub.publish('open.editor.query', resp.history_uuid);
+        huePubSub.publish('open.editor.query', resp);
       } else if (resp.message) {
         $(document).trigger("error", resp.message);
       }

+ 1 - 1
apps/metastore/src/metastore/templates/popups/load_data.mako

@@ -146,7 +146,7 @@ from django.utils.translation import ugettext as _
               $('#import-data-modal').html(response['data']);
             }
           } else {
-            huePubSub.publish('notebook.task.submitted', response.history_uuid);
+            huePubSub.publish('notebook.task.submitted', response);
             $("#import-data-modal").modal("hide");
           }
         }

+ 5 - 1
desktop/core/src/desktop/js/apps/notebook/editorViewModel.js

@@ -542,7 +542,7 @@ class EditorViewModel {
       };
     };
 
-    self.openNotebook = function(uuid, queryTab, skipUrlChange, callback) {
+    self.openNotebook = function(uuid, queryTab, skipUrlChange, callback, session) {
       const deferredOpen = new $.Deferred();
       $.get(
         '/desktop/api2/doc/',
@@ -555,6 +555,10 @@ class EditorViewModel {
           if (data.status == 0) {
             data.data.dependents = data.dependents;
             data.data.can_write = data.user_perms.can_write;
+            if (session) {
+              // backend doesn't store session, but can reuse an opened one.
+              data.data.sessions = [session];
+            }
             const notebook = data.data;
             self.loadNotebook(notebook, queryTab);
             if (typeof skipUrlChange === 'undefined' && !self.isNotificationManager()) {

+ 1 - 1
desktop/core/src/desktop/js/apps/table_browser/metastoreTable.js

@@ -352,7 +352,7 @@ class MetastoreTable {
         cluster: JSON.stringify(this.database.catalogEntry.compute)
       }).done(resp => {
         if (resp.history_uuid) {
-          huePubSub.publish('notebook.task.submitted', resp.history_uuid);
+          huePubSub.publish('notebook.task.submitted', resp);
         } else {
           $(document).trigger('error', resp.message);
         }

+ 1 - 1
desktop/core/src/desktop/js/hue.js

@@ -151,7 +151,7 @@ $(document).ready(() => {
       },
       resp => {
         if (resp.history_uuid) {
-          huePubSub.publish('open.editor.query', resp.history_uuid);
+          huePubSub.publish('open.editor.query', resp);
         } else if (resp.message) {
           $(document).trigger('error', resp.message);
         }

+ 1 - 1
desktop/core/src/desktop/js/ko/components/ko.executionAnalysis.js

@@ -259,7 +259,7 @@ class ExecutionAnalysis {
         compute: self.details().compute
       })
       .done(resp => {
-        huePubSub.publish('notebook.task.submitted', resp.task.history_uuid);
+        huePubSub.publish('notebook.task.submitted', resp);
         fix.fixed = true;
         self.analysis.valueHasMutated();
       });

+ 72 - 57
desktop/core/src/desktop/js/ko/components/ko.historyPanel.js

@@ -231,69 +231,84 @@ class HistoryPanel {
       }
     });
 
-    huePubSub.subscribe('notebook.task.submitted', history_id => {
-      self.editorViewModel.openNotebook(history_id, null, true, () => {
-        const notebook = self.editorViewModel.selectedNotebook();
-        notebook.snippets()[0].progress.subscribe(val => {
-          if (val === 100) {
-            //self.indexingStarted(false);
-            //self.isIndexing(false);
-            //self.indexingSuccess(true);
-          }
-        });
+    huePubSub.subscribe('notebook.task.submitted', resp => {
+      const data = { uuid: resp.history_uuid };
+      if (resp.handle && resp.handle.session_id) {
+        data['session'] = {
+          type: resp.handle.session_type,
+          id: resp.handle.session_id,
+          session_id: resp.handle.session_guid,
+          properties: []
+        };
+      }
+      self.editorViewModel.openNotebook(
+        data.uuid,
+        null,
+        true,
+        () => {
+          const notebook = self.editorViewModel.selectedNotebook();
+          notebook.snippets()[0].progress.subscribe(val => {
+            if (val === 100) {
+              //self.indexingStarted(false);
+              //self.isIndexing(false);
+              //self.indexingSuccess(true);
+            }
+          });
 
-        notebook.snippets()[0].status.subscribe(val => {
-          if (val === 'failed') {
-            //self.isIndexing(false);
-            //self.indexingStarted(false);
-            //self.indexingError(true);
-          } else if (val === 'available') {
-            const snippet = notebook.snippets()[0];
-            if (!snippet.result.handle().has_more_statements) {
-              // TODO: Show finish notification and clicking on it does onSuccessUrl
-              // or if still on initial spinner we redirect automatically to onSuccessUrl
-              if (notebook.onSuccessUrl() && notebook.onSuccessUrl() !== 'assist.db.refresh') {
-                // TODO: Similar if in in FB directory, also refresh FB dir
-                huePubSub.publish('open.link', notebook.onSuccessUrl());
-              }
+          notebook.snippets()[0].status.subscribe(val => {
+            if (val === 'failed') {
+              //self.isIndexing(false);
+              //self.indexingStarted(false);
+              //self.indexingError(true);
+            } else if (val === 'available') {
+              const snippet = notebook.snippets()[0];
+              if (!snippet.result.handle().has_more_statements) {
+                // TODO: Show finish notification and clicking on it does onSuccessUrl
+                // or if still on initial spinner we redirect automatically to onSuccessUrl
+                if (notebook.onSuccessUrl() && notebook.onSuccessUrl() !== 'assist.db.refresh') {
+                  // TODO: Similar if in in FB directory, also refresh FB dir
+                  huePubSub.publish('open.link', notebook.onSuccessUrl());
+                }
 
-              if (notebook.onSuccessUrl() === 'assist.db.refresh') {
-                dataCatalog
-                  .getEntry({
-                    sourceType: snippet.type(),
-                    namespace: snippet.namespace(),
-                    compute: snippet.compute(),
-                    path: []
-                  })
-                  .done(entry => {
-                    entry.clearCache({ invalidate: 'cache', cascade: true, silenceErrors: true });
-                  });
-              } else if (notebook.onSuccessUrl()) {
-                huePubSub.publish(notebook.pubSubUrl());
+                if (notebook.onSuccessUrl() === 'assist.db.refresh') {
+                  dataCatalog
+                    .getEntry({
+                      sourceType: snippet.type(),
+                      namespace: snippet.namespace(),
+                      compute: snippet.compute(),
+                      path: []
+                    })
+                    .done(entry => {
+                      entry.clearCache({ invalidate: 'cache', cascade: true, silenceErrors: true });
+                    });
+                } else if (notebook.onSuccessUrl()) {
+                  huePubSub.publish(notebook.pubSubUrl());
+                }
+                notebook.close(); // TODO: Don't close when onSuccessUrl is editor?
+              } else {
+                // Perform last DROP statement execute
+                snippet.execute();
               }
-              notebook.close(); // TODO: Don't close when onSuccessUrl is editor?
-            } else {
-              // Perform last DROP statement execute
-              snippet.execute();
             }
-          }
-        });
-        notebook.snippets()[0].checkStatus();
+          });
+          notebook.snippets()[0].checkStatus();
 
-        // Add to history
-        notebook.history.unshift(
-          notebook.makeHistoryRecord(
-            notebook.onSuccessUrl(),
-            notebook.description(),
-            new Date().getTime(),
-            notebook.snippets()[0].status(),
-            notebook.name(),
-            notebook.uuid()
-          )
-        );
+          // Add to history
+          notebook.history.unshift(
+            notebook.makeHistoryRecord(
+              notebook.onSuccessUrl(),
+              notebook.description(),
+              new Date().getTime(),
+              notebook.snippets()[0].status(),
+              notebook.name(),
+              notebook.uuid()
+            )
+          );
 
-        self.historyPanelVisible(true);
-      });
+          self.historyPanelVisible(true);
+        },
+        data.session
+      );
     });
   }
 

+ 11 - 2
desktop/core/src/desktop/js/onePageViewModel.js

@@ -79,10 +79,19 @@ class OnePageViewModel {
       huePubSub.publish('set.current.app.name', self.currentApp());
     });
 
-    huePubSub.subscribe('open.editor.query', uuid => {
+    huePubSub.subscribe('open.editor.query', resp => {
       self.loadApp('editor');
+      const data = { uuid: resp.history_uuid };
+      if (resp.handle && resp.handle.session_id) {
+        data['session'] = {
+          type: resp.handle.session_type,
+          id: resp.handle.session_id,
+          session_id: resp.handle.session_guid,
+          properties: []
+        };
+      }
       self.getActiveAppViewModel(viewModel => {
-        viewModel.openNotebook(uuid);
+        viewModel.openNotebook(data.uuid, null, null, null, data.session);
       });
     });
 

+ 1 - 1
desktop/core/src/desktop/templates/common_notebook_ko_components.mako

@@ -453,7 +453,7 @@ from notebook.conf import ENABLE_SQL_INDEXER
                 huePubSub.publish('open.link', resp.watch_url);
               } else if (resp.history_uuid) {
                 $(self.saveResultsModalId).modal('hide');
-                huePubSub.publish('notebook.task.submitted', resp.history_uuid);
+                huePubSub.publish('notebook.task.submitted', resp);
               } else if (resp && resp.message) {
                 $(document).trigger("error", resp.message);
               }

+ 2 - 2
desktop/libs/indexer/src/indexer/templates/importer.mako

@@ -2068,7 +2068,7 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
           "source": ko.mapping.toJSON(self)
         }, function (resp) {
           if (resp.status === 0 && resp.data) {
-            huePubSub.publish('notebook.task.submitted', resp.history_uuid);
+            huePubSub.publish('notebook.task.submitted', resp);
           } else if (resp.status === 1) {
             $(document).trigger("error", "${ _('Connection Failed: ') }" + resp.message);
             self.rdbmsDbIsValid(false);
@@ -2895,7 +2895,7 @@ ${ commonheader(_("Importer"), "indexer", user, request, "60px") | n,unicode }
           if (resp.status === 0) {
             if (resp.history_uuid) {
               $.jHueNotify.info("${ _('Task submitted') }");
-              huePubSub.publish('notebook.task.submitted', resp.history_uuid);
+              huePubSub.publish('notebook.task.submitted', resp);
             } else if (resp.on_success_url) {
               if (resp.pub_sub_url) {
                 huePubSub.publish(resp.pub_sub_url);

+ 2 - 1
desktop/libs/notebook/src/notebook/connectors/hiveserver2.py

@@ -315,7 +315,8 @@ class HS2Api(Api):
       'modified_row_count': handle.modified_row_count,
       'log_context': handle.log_context,
       'session_guid': handle.session_guid,
-      'session_id': handle.session_id
+      'session_id': handle.session_id,
+      'session_type': snippet['type']
     }
     response.update(statement)