Browse Source

HUE-9000 [editor] Use the operationId for check status

Johan Ahlen 6 years ago
parent
commit
b83729c207

+ 18 - 24
desktop/core/src/desktop/js/api/apiHelper.js

@@ -2169,32 +2169,26 @@ class ApiHelper {
   checkExecutionStatus(options) {
     const deferred = $.Deferred();
 
-    const result = new CancellablePromise(deferred);
-
-    options.executable
-      .toContext()
-      .then(notebookApiContext => {
-        const request = $.post({
-          url: '/notebook/api/check_status',
-          data: notebookApiContext
-        })
-          .done(response => {
-            if (response && response.query_status) {
-              deferred.resolve(response.query_status.status);
-            } else if (response && response.status === -3) {
-              deferred.resolve(EXECUTION_STATUS.expired);
-            } else {
-              deferred.resolve(EXECUTION_STATUS.failed);
-            }
-          })
-          .fail(err => {
-            deferred.reject(this.assistErrorCallback(options)(err));
-          });
-        result.request = request;
+    const request = $.post({
+      url: '/notebook/api/check_status',
+      data: {
+        operationId: options.executable.operationId
+      }
+    })
+      .done(response => {
+        if (response && response.query_status) {
+          deferred.resolve(response.query_status.status);
+        } else if (response && response.status === -3) {
+          deferred.resolve(EXECUTION_STATUS.expired);
+        } else {
+          deferred.resolve(EXECUTION_STATUS.failed);
+        }
       })
-      .catch(deferred.reject);
+      .fail(err => {
+        deferred.reject(this.assistErrorCallback(options)(err));
+      });
 
-    return result;
+    return new CancellablePromise(deferred, request);
   }
 
   /**

+ 7 - 6
desktop/core/src/desktop/js/apps/notebook2/execution/executable.js

@@ -330,15 +330,16 @@ export default class Executable {
     delete state.aceAnchor;
 
     return {
-      type: 'executable',
+      executeEnded: this.executeEnded,
+      executeStarted: this.executeStarted,
       handle: this.handle,
-      status: this.status,
-      progress: this.progress,
+      history: this.history,
       logs: this.logs.toJs(),
-      executeStarted: this.executeStarted,
-      executeEnded: this.executeEnded,
+      lost: this.lost,
       observerState: state,
-      lost: this.lost
+      progress: this.progress,
+      status: this.status,
+      type: 'executable'
     };
   }
 

+ 8 - 6
desktop/core/src/desktop/js/apps/notebook2/execution/sqlExecutable.js

@@ -58,15 +58,17 @@ export default class SqlExecutable extends Executable {
       database: executableRaw.database,
       parsedStatement: executableRaw.parsedStatement
     });
+    executable.executeEnded = executableRaw.executeEnded;
+    executable.executeStarted = executableRaw.executeStarted;
+    executable.handle = executableRaw.handle;
+    executable.history = executableRaw.history;
+    executable.logs.errors = executableRaw.logs.errors;
+    executable.logs.jobs = executableRaw.logs.jobs;
+    executable.lost = executableRaw.lost;
     executable.observerState = executableRaw.observerState || {};
+    executable.operationId = executableRaw.history && executableRaw.history.uuid;
     executable.progress = executableRaw.progress;
     executable.status = executableRaw.status;
-    executable.handle = executableRaw.handle;
-    executable.lost = executableRaw.lost;
-    executable.logs.jobs = executableRaw.logs.jobs;
-    executable.logs.errors = executableRaw.logs.errors;
-    executable.executeStarted = executableRaw.executeStarted;
-    executable.executeEnded = executableRaw.executeEnded;
     return executable;
   }
 

+ 29 - 29
desktop/core/src/desktop/js/apps/notebook2/notebook.js

@@ -27,23 +27,23 @@ import sessionManager from 'apps/notebook2/execution/sessionManager';
 import Snippet, { STATUS as SNIPPET_STATUS } from 'apps/notebook2/snippet';
 
 export default class Notebook {
-  constructor(vm, notebook) {
+  constructor(vm, notebookRaw) {
     this.parentVm = vm;
-    this.id = ko.observable(notebook.id);
-    this.uuid = ko.observable(notebook.uuid || hueUtils.UUID());
-    this.name = ko.observable(notebook.name || '');
-    this.description = ko.observable(notebook.description || '');
-    this.type = ko.observable(notebook.type || 'notebook');
+    this.id = ko.observable(notebookRaw.id);
+    this.uuid = ko.observable(notebookRaw.uuid || hueUtils.UUID());
+    this.name = ko.observable(notebookRaw.name || '');
+    this.description = ko.observable(notebookRaw.description || '');
+    this.type = ko.observable(notebookRaw.type || 'notebook');
     this.initialType = this.type().replace('query-', '');
-    this.coordinatorUuid = ko.observable(notebook.coordinatorUuid);
-    this.isHistory = ko.observable(!!notebook.is_history);
-    this.isManaged = ko.observable(!!notebook.isManaged);
-    this.parentSavedQueryUuid = ko.observable(notebook.parentSavedQueryUuid); // History parent
-    this.isSaved = ko.observable(!!notebook.isSaved);
-    this.canWrite = ko.observable(notebook.can_write !== false);
-    this.onSuccessUrl = ko.observable(notebook.onSuccessUrl);
-    this.pubSubUrl = ko.observable(notebook.pubSubUrl);
-    this.isPresentationModeDefault = ko.observable(!!notebook.isPresentationModeDefault);
+    this.coordinatorUuid = ko.observable(notebookRaw.coordinatorUuid);
+    this.isHistory = ko.observable(!!notebookRaw.is_history);
+    this.isManaged = ko.observable(!!notebookRaw.isManaged);
+    this.parentSavedQueryUuid = ko.observable(notebookRaw.parentSavedQueryUuid); // History parent
+    this.isSaved = ko.observable(!!notebookRaw.isSaved);
+    this.canWrite = ko.observable(notebookRaw.can_write !== false);
+    this.onSuccessUrl = ko.observable(notebookRaw.onSuccessUrl);
+    this.pubSubUrl = ko.observable(notebookRaw.pubSubUrl);
+    this.isPresentationModeDefault = ko.observable(!!notebookRaw.isPresentationModeDefault);
     this.isPresentationMode = ko.observable(false);
     this.isPresentationModeInitialized = ko.observable(false);
     this.isPresentationMode.subscribe(newValue => {
@@ -57,12 +57,12 @@ export default class Notebook {
       }
     });
     this.presentationSnippets = ko.observable({});
-    this.isHidingCode = ko.observable(!!notebook.isHidingCode);
+    this.isHidingCode = ko.observable(!!notebookRaw.isHidingCode);
 
     this.snippets = ko.observableArray();
     this.selectedSnippet = ko.observable(vm.editorType()); // Aka selectedSnippetType
-    this.directoryUuid = ko.observable(notebook.directoryUuid);
-    this.dependents = komapping.fromJS(notebook.dependents || []);
+    this.directoryUuid = ko.observable(notebookRaw.directoryUuid);
+    this.dependents = komapping.fromJS(notebookRaw.dependents || []);
     this.dependentsCoordinator = ko.pureComputed(() =>
       this.dependents().filter(doc => doc.type() === 'oozie-coordinator2' && doc.is_managed())
     );
@@ -120,9 +120,9 @@ export default class Notebook {
       () => this.snippets().length > 0 && this.snippets().every(snippet => snippet.isBatchable())
     );
 
-    this.isExecutingAll = ko.observable(!!notebook.isExecutingAll);
+    this.isExecutingAll = ko.observable(!!notebookRaw.isExecutingAll);
 
-    this.executingAllIndex = ko.observable(notebook.executingAllIndex || 0);
+    this.executingAllIndex = ko.observable(notebookRaw.executingAllIndex || 0);
 
     this.retryModalConfirm = null;
     this.retryModalCancel = null;
@@ -134,7 +134,7 @@ export default class Notebook {
     this.unloaded = ko.observable(false);
     this.updateHistoryFailed = false;
 
-    this.viewSchedulerId = ko.observable(notebook.viewSchedulerId || '');
+    this.viewSchedulerId = ko.observable(notebookRaw.viewSchedulerId || '');
     this.viewSchedulerId.subscribe(() => {
       this.save();
     });
@@ -142,16 +142,16 @@ export default class Notebook {
     this.loadingScheduler = ko.observable(false);
 
     // Init
-    if (notebook.snippets) {
-      notebook.snippets.forEach(snippet => {
-        this.addSnippet(snippet);
+    if (notebookRaw.snippets) {
+      notebookRaw.snippets.forEach(snippetRaw => {
+        this.addSnippet(snippetRaw);
       });
       if (
-        typeof notebook.presentationSnippets != 'undefined' &&
-        notebook.presentationSnippets != null
+        typeof notebookRaw.presentationSnippets != 'undefined' &&
+        notebookRaw.presentationSnippets != null
       ) {
         // Load
-        $.each(notebook.presentationSnippets, (key, snippet) => {
+        $.each(notebookRaw.presentationSnippets, (key, snippet) => {
           snippet.status = 'ready'; // Protect from storm of check_statuses
           const _snippet = new Snippet(vm, this, snippet);
           _snippet.init();
@@ -218,8 +218,8 @@ export default class Notebook {
     huePubSub.publish('assist.is.db.panel.ready');
   }
 
-  addSnippet(snippet) {
-    const newSnippet = new Snippet(this.parentVm, this, snippet);
+  addSnippet(snippetRaw) {
+    const newSnippet = new Snippet(this.parentVm, this, snippetRaw);
     this.snippets.push(newSnippet);
     newSnippet.init();
     return newSnippet;

+ 29 - 29
desktop/core/src/desktop/js/apps/notebook2/snippet.js

@@ -174,12 +174,12 @@ const getDefaultSnippetProperties = snippetType => {
 const ERROR_REGEX = /line ([0-9]+)(:([0-9]+))?/i;
 
 export default class Snippet {
-  constructor(vm, notebook, snippet) {
+  constructor(vm, notebook, snippetRaw) {
     this.parentVm = vm;
     this.parentNotebook = notebook;
 
-    this.id = ko.observable(snippet.id || hueUtils.UUID());
-    this.name = ko.observable(snippet.name || '');
+    this.id = ko.observable(snippetRaw.id || hueUtils.UUID());
+    this.name = ko.observable(snippetRaw.name || '');
     this.type = ko.observable();
     this.type.subscribe(newValue => {
       // TODO: Add session disposal for ENABLE_NOTEBOOK_2
@@ -188,7 +188,7 @@ export default class Snippet {
         this.status(STATUS.ready);
       });
     });
-    this.type(snippet.type || TYPE.hive);
+    this.type(snippetRaw.type || TYPE.hive);
     this.isBatchable = ko.pureComputed(
       () =>
         this.type() === this.hive ||
@@ -206,7 +206,7 @@ export default class Snippet {
 
     // Ace stuff
     this.aceCursorPosition = ko.observable(
-      this.parentNotebook.isHistory() ? snippet.aceCursorPosition : null
+      this.parentNotebook.isHistory() ? snippetRaw.aceCursorPosition : null
     );
 
     this.aceEditor = null;
@@ -249,10 +249,10 @@ export default class Snippet {
 
     // namespace and compute might be initialized as empty object {}
     this.namespace = ko.observable(
-      snippet.namespace && snippet.namespace.id ? snippet.namespace : undefined
+      snippetRaw.namespace && snippetRaw.namespace.id ? snippetRaw.namespace : undefined
     );
     this.compute = ko.observable(
-      snippet.compute && snippet.compute.id ? snippet.compute : undefined
+      snippetRaw.compute && snippetRaw.compute.id ? snippetRaw.compute : undefined
     );
 
     this.availableDatabases = ko.observableArray();
@@ -269,11 +269,11 @@ export default class Snippet {
       }
     });
 
-    this.database(snippet.database);
+    this.database(snippetRaw.database);
 
     // History is currently in Notebook, same with saved queries by snippets, might be better in assist
-    this.currentQueryTab = ko.observable(snippet.currentQueryTab || 'queryHistory');
-    this.pinnedContextTabs = ko.observableArray(snippet.pinnedContextTabs || []);
+    this.currentQueryTab = ko.observable(snippetRaw.currentQueryTab || 'queryHistory');
+    this.pinnedContextTabs = ko.observableArray(snippetRaw.pinnedContextTabs || []);
 
     this.errorLoadingQueries = ko.observable(false);
     this.loadingQueries = ko.observable(false);
@@ -341,12 +341,12 @@ export default class Snippet {
       });
     }
 
-    this.statementType = ko.observable(snippet.statementType || 'text');
+    this.statementType = ko.observable(snippetRaw.statementType || 'text');
     this.statementTypes = ko.observableArray(['text', 'file']); // Maybe computed later for Spark
     if (!this.parentVm.editorMode()) {
       this.statementTypes.push('document');
     }
-    this.statementPath = ko.observable(snippet.statementPath || '');
+    this.statementPath = ko.observable(snippetRaw.statementPath || '');
     this.externalStatementLoaded = ko.observable(false);
 
     this.statementPath.subscribe(() => {
@@ -355,7 +355,7 @@ export default class Snippet {
 
     this.associatedDocumentLoading = ko.observable(true);
     this.associatedDocument = ko.observable();
-    this.associatedDocumentUuid = ko.observable(snippet.associatedDocumentUuid);
+    this.associatedDocumentUuid = ko.observable(snippetRaw.associatedDocumentUuid);
     this.associatedDocumentUuid.subscribe(val => {
       if (val !== '') {
         this.getExternalStatement();
@@ -364,7 +364,7 @@ export default class Snippet {
         this.ace().setValue('', 1);
       }
     });
-    this.statement_raw = ko.observable(snippet.statement_raw || '');
+    this.statement_raw = ko.observable(snippetRaw.statement_raw || '');
     this.selectedStatement = ko.observable('');
     this.positionStatement = ko.observable(null);
     this.lastExecutedStatement = ko.observable(null);
@@ -428,12 +428,12 @@ export default class Snippet {
       this.parentVm.huePubSubId
     );
 
-    this.aceSize = ko.observable(snippet.aceSize || 100);
-    this.status = ko.observable(snippet.status || STATUS.loading);
+    this.aceSize = ko.observable(snippetRaw.aceSize || 100);
+    this.status = ko.observable(snippetRaw.status || STATUS.loading);
     this.statusForButtons = ko.observable(STATUS_FOR_BUTTONS.executed);
 
     this.properties = ko.observable(
-      komapping.fromJS(snippet.properties || getDefaultSnippetProperties(this.type()))
+      komapping.fromJS(snippetRaw.properties || getDefaultSnippetProperties(this.type()))
     );
     this.hasProperties = ko.pureComputed(
       () => Object.keys(komapping.toJS(this.properties())).length > 0
@@ -462,8 +462,8 @@ export default class Snippet {
         }
       }, 100);
     });
-    if (snippet.variables) {
-      snippet.variables.forEach(variable => {
+    if (snippetRaw.variables) {
+      snippetRaw.variables.forEach(variable => {
         variable.meta = (typeof variable.defaultValue === 'object' && variable.defaultValue) || {
           type: 'text',
           placeholder: ''
@@ -477,7 +477,7 @@ export default class Snippet {
         delete variable.defaultValue;
       });
     }
-    this.variables = komapping.fromJS(snippet.variables || []);
+    this.variables = komapping.fromJS(snippetRaw.variables || []);
     this.variables.subscribe(() => {
       $(document).trigger('updateResultHeaders', this);
     });
@@ -761,8 +761,8 @@ export default class Snippet {
     if (this.parentVm.editorMode() && $.totalStorage('hue.editor.showLogs')) {
       defaultShowLogs = $.totalStorage('hue.editor.showLogs');
     }
-    this.showLogs = ko.observable(snippet.showLogs || defaultShowLogs);
-    this.jobs = ko.observableArray(snippet.jobs || []);
+    this.showLogs = ko.observable(snippetRaw.showLogs || defaultShowLogs);
+    this.jobs = ko.observableArray(snippetRaw.jobs || []);
 
     this.executeNextTimeout = -1;
     this.refreshTimeouts = {};
@@ -780,9 +780,9 @@ export default class Snippet {
 
     this.errorsKlass = ko.pureComputed(() => this.resultsKlass() + ' alert alert-error');
 
-    this.is_redacted = ko.observable(!!snippet.is_redacted);
+    this.is_redacted = ko.observable(!!snippetRaw.is_redacted);
 
-    this.settingsVisible = ko.observable(!!snippet.settingsVisible);
+    this.settingsVisible = ko.observable(!!snippetRaw.settingsVisible);
     this.saveResultsModalVisible = ko.observable(false);
 
     this.complexity = ko.observable();
@@ -953,7 +953,7 @@ export default class Snippet {
       }
     }
 
-    this.wasBatchExecuted = ko.observable(!!snippet.wasBatchExecuted);
+    this.wasBatchExecuted = ko.observable(!!snippetRaw.wasBatchExecuted);
     this.isReady = ko.pureComputed(
       () =>
         (this.statementType() === 'text' &&
@@ -973,8 +973,8 @@ export default class Snippet {
           this.associatedDocumentUuid() &&
           this.associatedDocumentUuid().length > 0)
     );
-    this.lastExecuted = ko.observable(snippet.lastExecuted || 0);
-    this.lastAceSelectionRowOffset = ko.observable(snippet.lastAceSelectionRowOffset || 0);
+    this.lastExecuted = ko.observable(snippetRaw.lastExecuted || 0);
+    this.lastAceSelectionRowOffset = ko.observable(snippetRaw.lastAceSelectionRowOffset || 0);
 
     this.executingBlockingOperation = null; // A ExecuteStatement()
     this.showLongOperationWarning = ko.observable(false);
@@ -1011,9 +1011,9 @@ export default class Snippet {
       isSqlEngine: this.isSqlDialect
     });
 
-    if (snippet.executor) {
+    if (snippetRaw.executor) {
       try {
-        this.executor.executables = snippet.executor.executables.map(executableRaw => {
+        this.executor.executables = snippetRaw.executor.executables.map(executableRaw => {
           switch (executableRaw.type) {
             case 'sqlExecutable': {
               return SqlExecutable.fromJs(this.executor, executableRaw);