|
|
@@ -23,7 +23,6 @@ import hueAnalytics from 'utils/hueAnalytics';
|
|
|
import huePubSub from 'utils/huePubSub';
|
|
|
import hueUtils from 'utils/hueUtils';
|
|
|
|
|
|
-import Session from 'apps/notebook2/session';
|
|
|
import { Snippet, STATUS as SNIPPET_STATUS } from 'apps/notebook2/snippet';
|
|
|
|
|
|
const NOTEBOOK_MAPPING = {
|
|
|
@@ -97,10 +96,6 @@ class Notebook {
|
|
|
|
|
|
self.snippets = ko.observableArray();
|
|
|
self.selectedSnippet = ko.observable(vm.editorType()); // Aka selectedSnippetType
|
|
|
- self.creatingSessionLocks = ko.observableArray();
|
|
|
- self.sessions = komapping.fromJS(notebook.sessions || [], {
|
|
|
- create: value => new Session(vm, value.data)
|
|
|
- });
|
|
|
self.directoryUuid = ko.observable(notebook.directoryUuid);
|
|
|
self.dependents = komapping.fromJS(notebook.dependents || []);
|
|
|
self.dependentsCoordinator = ko.pureComputed(() =>
|
|
|
@@ -255,47 +250,14 @@ class Notebook {
|
|
|
huePubSub.publish('assist.is.db.panel.ready');
|
|
|
}
|
|
|
|
|
|
- addSession(session) {
|
|
|
- const self = this;
|
|
|
- const toRemove = self.sessions().filter(s => s.type() === session.type());
|
|
|
-
|
|
|
- toRemove.forEach(s => {
|
|
|
- self.sessions.remove(s);
|
|
|
- });
|
|
|
-
|
|
|
- self.sessions.push(session);
|
|
|
- }
|
|
|
-
|
|
|
- addSnippet(snippet, skipSession) {
|
|
|
+ addSnippet(snippet) {
|
|
|
const self = this;
|
|
|
const newSnippet = new Snippet(self.parentVm, self, snippet);
|
|
|
self.snippets.push(newSnippet);
|
|
|
-
|
|
|
- if (self.getSession(newSnippet.type()) == null && typeof skipSession == 'undefined') {
|
|
|
- window.setTimeout(() => {
|
|
|
- newSnippet.status(SNIPPET_STATUS.loading);
|
|
|
- self.createSession(new Session(self.parentVm, { type: newSnippet.type() }));
|
|
|
- }, 200);
|
|
|
- }
|
|
|
-
|
|
|
newSnippet.init();
|
|
|
return newSnippet;
|
|
|
}
|
|
|
|
|
|
- authSession() {
|
|
|
- const self = this;
|
|
|
- self.createSession(
|
|
|
- new Session(self.parentVm, {
|
|
|
- type: self.parentVm.authSessionType(),
|
|
|
- properties: [
|
|
|
- { name: 'user', value: self.parentVm.authSessionUsername() },
|
|
|
- { name: 'password', value: self.parentVm.authSessionPassword() }
|
|
|
- ]
|
|
|
- }),
|
|
|
- self.parentVm.authSessionCallback() // On new session we don't automatically execute the snippet after the aut. On session expiration we do or we refresh assist DB when login-in.
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
cancelExecutingAll() {
|
|
|
const self = this;
|
|
|
const index = self.executingAllIndex();
|
|
|
@@ -348,99 +310,6 @@ class Notebook {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- closeAndRemoveSession(session) {
|
|
|
- const self = this;
|
|
|
- self.closeSession(session, false, () => {
|
|
|
- self.sessions.remove(session);
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- closeSession(session, silent, callback) {
|
|
|
- $.post(
|
|
|
- '/notebook/api/close_session',
|
|
|
- {
|
|
|
- session: komapping.toJSON(session)
|
|
|
- },
|
|
|
- data => {
|
|
|
- if (!silent && data && data.status !== 0 && data.status !== -2 && data.message) {
|
|
|
- $(document).trigger('error', data.message);
|
|
|
- }
|
|
|
-
|
|
|
- if (callback) {
|
|
|
- callback();
|
|
|
- }
|
|
|
- }
|
|
|
- ).fail(xhr => {
|
|
|
- if (!silent && xhr.status !== 502) {
|
|
|
- $(document).trigger('error', xhr.responseText);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- createSession(session, callback, failCallback) {
|
|
|
- const self = this;
|
|
|
- if (self.creatingSessionLocks().indexOf(session.type()) !== -1) {
|
|
|
- // Create one type of session max
|
|
|
- return;
|
|
|
- } else {
|
|
|
- self.creatingSessionLocks.push(session.type());
|
|
|
- }
|
|
|
-
|
|
|
- let compute = null;
|
|
|
- self.getSnippets(session.type()).forEach((snippet, index) => {
|
|
|
- snippet.status(SNIPPET_STATUS.loading);
|
|
|
- if (index === 0) {
|
|
|
- compute = snippet.compute();
|
|
|
- }
|
|
|
- });
|
|
|
-
|
|
|
- const fail = function(message) {
|
|
|
- self.getSnippets(session.type()).forEach(snippet => {
|
|
|
- snippet.status('failed');
|
|
|
- });
|
|
|
- $(document).trigger('error', message);
|
|
|
- if (failCallback) {
|
|
|
- failCallback();
|
|
|
- }
|
|
|
- };
|
|
|
-
|
|
|
- apiHelper
|
|
|
- .createSession({
|
|
|
- notebookJson: komapping.toJSON(self.getContext(), NOTEBOOK_MAPPING),
|
|
|
- sessionJson: komapping.toJSON(session), // e.g. {'type': 'pyspark', 'properties': [{'name': driverCores', 'value', '2'}]}
|
|
|
- clusterJson: komapping.toJSON(compute ? compute : '')
|
|
|
- })
|
|
|
- .then(data => {
|
|
|
- if (data.status === 0) {
|
|
|
- komapping.fromJS(data.session, {}, session);
|
|
|
- if (self.getSession(session.type()) == null) {
|
|
|
- self.addSession(session);
|
|
|
- } else {
|
|
|
- const _session = self.getSession(session.type());
|
|
|
- komapping.fromJS(data.session, {}, _session);
|
|
|
- }
|
|
|
- self.getSnippets(session.type()).forEach(snippet => {
|
|
|
- snippet.status('ready');
|
|
|
- });
|
|
|
- if (callback) {
|
|
|
- setTimeout(callback, 500);
|
|
|
- }
|
|
|
- } else if (data.status === 401) {
|
|
|
- $(document).trigger('showAuthModal', { type: session.type(), message: data.message });
|
|
|
- } else {
|
|
|
- fail(data.message);
|
|
|
- }
|
|
|
- })
|
|
|
- .fail(xhr => {
|
|
|
- if (xhr.status !== 502) {
|
|
|
- fail(xhr.responseText);
|
|
|
- }
|
|
|
- })
|
|
|
- .always(() => {
|
|
|
- self.creatingSessionLocks.remove(session.type());
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
executeAll() {
|
|
|
const self = this;
|
|
|
if (self.isExecutingAll() || self.snippets().length === 0) {
|
|
|
@@ -501,25 +370,11 @@ class Notebook {
|
|
|
uuid: self.uuid,
|
|
|
parentSavedQueryUuid: self.parentSavedQueryUuid,
|
|
|
isSaved: self.isSaved,
|
|
|
- sessions: self.sessions,
|
|
|
type: self.type,
|
|
|
name: self.name
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- getSession(session_type) {
|
|
|
- const self = this;
|
|
|
- let found = undefined;
|
|
|
- self.sessions().every(session => {
|
|
|
- if (session.type() === session_type) {
|
|
|
- found = session;
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- });
|
|
|
- return found;
|
|
|
- }
|
|
|
-
|
|
|
getSnippets(type) {
|
|
|
const self = this;
|
|
|
return self.snippets().filter(snippet => snippet.type() === type);
|
|
|
@@ -660,37 +515,6 @@ class Notebook {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- restartSession(session, callback) {
|
|
|
- const self = this;
|
|
|
- if (session.restarting()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- session.restarting(true);
|
|
|
- const snippets = self.getSnippets(session.type());
|
|
|
-
|
|
|
- snippets.forEach(snippet => {
|
|
|
- snippet.status(SNIPPET_STATUS.loading);
|
|
|
- });
|
|
|
-
|
|
|
- self.closeSession(session, true, () => {
|
|
|
- self.createSession(
|
|
|
- session,
|
|
|
- () => {
|
|
|
- snippets.forEach(snippet => {
|
|
|
- snippet.status(SNIPPET_STATUS.ready);
|
|
|
- });
|
|
|
- session.restarting(false);
|
|
|
- if (callback) {
|
|
|
- callback();
|
|
|
- }
|
|
|
- },
|
|
|
- () => {
|
|
|
- session.restarting(false);
|
|
|
- }
|
|
|
- );
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
save(callback) {
|
|
|
const self = this;
|
|
|
hueAnalytics.log('notebook', 'save');
|
|
|
@@ -786,15 +610,6 @@ class Notebook {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- saveDefaultUserProperties(session) {
|
|
|
- const self = this;
|
|
|
- apiHelper.saveConfiguration({
|
|
|
- app: session.type(),
|
|
|
- properties: session.properties,
|
|
|
- userId: self.parentVm.userId
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
saveScheduler() {
|
|
|
const self = this;
|
|
|
if (
|