|
@@ -184,12 +184,6 @@ var Snippet = function (notebook, snippet) {
|
|
|
|
|
|
|
|
self.checkStatusTimeout = null;
|
|
self.checkStatusTimeout = null;
|
|
|
|
|
|
|
|
- self.init = function() {
|
|
|
|
|
- if (self.status() == 'running') {
|
|
|
|
|
- self.checkStatus();
|
|
|
|
|
- }
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
self.create_session = function() {
|
|
self.create_session = function() {
|
|
|
$.post("/spark/api/create_session", {
|
|
$.post("/spark/api/create_session", {
|
|
|
notebook: ko.mapping.toJSON(notebook),
|
|
notebook: ko.mapping.toJSON(notebook),
|
|
@@ -206,15 +200,15 @@ var Snippet = function (notebook, snippet) {
|
|
|
$(document).trigger("error", xhr.responseText);
|
|
$(document).trigger("error", xhr.responseText);
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
self.execute = function() {
|
|
self.execute = function() {
|
|
|
$(document).trigger("executeStarted", self);
|
|
$(document).trigger("executeStarted", self);
|
|
|
- $(".jHueNotify").hide();
|
|
|
|
|
- logGA('/execute/' + self.type());
|
|
|
|
|
-
|
|
|
|
|
- self.result.clear();
|
|
|
|
|
- self.status('running');
|
|
|
|
|
|
|
+ $(".jHueNotify").hide();
|
|
|
|
|
+ logGA('/execute/' + self.type());
|
|
|
|
|
|
|
|
|
|
+ self.result.clear();
|
|
|
|
|
+ self.status('running');
|
|
|
|
|
+
|
|
|
$.post("/spark/api/execute", {
|
|
$.post("/spark/api/execute", {
|
|
|
notebook: ko.mapping.toJSON(notebook),
|
|
notebook: ko.mapping.toJSON(notebook),
|
|
|
snippet: ko.mapping.toJSON(self)
|
|
snippet: ko.mapping.toJSON(self)
|
|
@@ -235,33 +229,14 @@ var Snippet = function (notebook, snippet) {
|
|
|
$(document).trigger("error", xhr.responseText);
|
|
$(document).trigger("error", xhr.responseText);
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
-
|
|
|
|
|
- self.checkStatus = function() {
|
|
|
|
|
- $.post("/spark/api/check_status", {
|
|
|
|
|
- notebook: ko.mapping.toJSON(notebook),
|
|
|
|
|
- snippet: ko.mapping.toJSON(self)
|
|
|
|
|
- }, function (data) {
|
|
|
|
|
- if (data.status == 0) {
|
|
|
|
|
- self.status(data.query_status.status);
|
|
|
|
|
-
|
|
|
|
|
- if (self.status() == 'running') {
|
|
|
|
|
- self.checkStatusTimeout = setTimeout(self.checkStatus, 1000);
|
|
|
|
|
- }
|
|
|
|
|
- else if (self.status() == 'available') {
|
|
|
|
|
- self.fetchResult(100);
|
|
|
|
|
- }
|
|
|
|
|
- } else if (data.status == -2) {
|
|
|
|
|
- self.create_session();
|
|
|
|
|
- } else {
|
|
|
|
|
- $(document).trigger("error", data.message);
|
|
|
|
|
- }
|
|
|
|
|
- }).fail(function (xhr, textStatus, errorThrown) {
|
|
|
|
|
- $(document).trigger("error", xhr.responseText);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+
|
|
|
|
|
+ self.fetchResult = function(rows) {
|
|
|
|
|
+ self.fetchResultData(rows);
|
|
|
|
|
+ //self.fetchResultMetadata(rows);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- self.fetchResult = function(rows) {
|
|
|
|
|
- $.post("/spark/api/fetch_result", {
|
|
|
|
|
|
|
+ self.fetchResultData = function(rows) {
|
|
|
|
|
+ $.post("/spark/api/fetch_result_data", {
|
|
|
notebook: ko.mapping.toJSON(notebook),
|
|
notebook: ko.mapping.toJSON(notebook),
|
|
|
snippet: ko.mapping.toJSON(self),
|
|
snippet: ko.mapping.toJSON(self),
|
|
|
rows: rows
|
|
rows: rows
|
|
@@ -276,7 +251,7 @@ var Snippet = function (notebook, snippet) {
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
if (data.result.hasMore && rows > 0) {
|
|
if (data.result.hasMore && rows > 0) {
|
|
|
- setTimeout(function(){ self.fetchResult(rows); }, 500);
|
|
|
|
|
|
|
+ setTimeout(function(){ self.fetchResultData(rows); }, 500);
|
|
|
}
|
|
}
|
|
|
} else if (data.status == -2) {
|
|
} else if (data.status == -2) {
|
|
|
self.create_session();
|
|
self.create_session();
|
|
@@ -289,7 +264,44 @@ var Snippet = function (notebook, snippet) {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
self.fetchResultMetadata = function() {
|
|
self.fetchResultMetadata = function() {
|
|
|
-
|
|
|
|
|
|
|
+ $.post("/spark/api/fetch_result_metadata", {
|
|
|
|
|
+ notebook: ko.mapping.toJSON(notebook),
|
|
|
|
|
+ snippet: ko.mapping.toJSON(self),
|
|
|
|
|
+ }, function (data) {
|
|
|
|
|
+ if (data.status == 0) {
|
|
|
|
|
+ self.result.meta(data.result.meta);
|
|
|
|
|
+ } else if (data.status == -2) {
|
|
|
|
|
+ self.create_session();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $(document).trigger("error", data.message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).fail(function (xhr, textStatus, errorThrown) {
|
|
|
|
|
+ $(document).trigger("error", xhr.responseText);
|
|
|
|
|
+ });
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ self.checkStatus = function() {
|
|
|
|
|
+ $.post("/spark/api/check_status", {
|
|
|
|
|
+ notebook: ko.mapping.toJSON(notebook),
|
|
|
|
|
+ snippet: ko.mapping.toJSON(self)
|
|
|
|
|
+ }, function (data) {
|
|
|
|
|
+ if (data.status == 0) {
|
|
|
|
|
+ self.status(data.query_status.status);
|
|
|
|
|
+
|
|
|
|
|
+ if (self.status() == 'running') {
|
|
|
|
|
+ self.checkStatusTimeout = setTimeout(self.checkStatus, 1000);
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (self.status() == 'available') {
|
|
|
|
|
+ self.fetchResult(100);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (data.status == -2) {
|
|
|
|
|
+ self.create_session();
|
|
|
|
|
+ } else {
|
|
|
|
|
+ $(document).trigger("error", data.message);
|
|
|
|
|
+ }
|
|
|
|
|
+ }).fail(function (xhr, textStatus, errorThrown) {
|
|
|
|
|
+ $(document).trigger("error", xhr.responseText);
|
|
|
|
|
+ });
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
self.cancel = function() {
|
|
self.cancel = function() {
|
|
@@ -326,6 +338,12 @@ var Snippet = function (notebook, snippet) {
|
|
|
$(document).trigger("error", xhr.responseText);
|
|
$(document).trigger("error", xhr.responseText);
|
|
|
});
|
|
});
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
|
|
+ self.init = function() {
|
|
|
|
|
+ if (self.status() == 'running') {
|
|
|
|
|
+ self.checkStatus();
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|