From 5dc860f216ccd8e40b1445378c5d481d29fd1963 Mon Sep 17 00:00:00 2001 From: Prabhjyot Singh Date: Mon, 14 Dec 2015 15:58:07 +0530 Subject: [PATCH 1/3] Option to restart interpreter from paragraph. --- .../app/interpreter/interpreter.controller.js | 31 +++++-------- .../paragraph/paragraph.controller.js | 33 +++++++++++++- .../src/app/notebook/paragraph/paragraph.html | 9 ++++ .../baseInterpreter.service.js | 45 +++++++++++++++++++ zeppelin-web/src/index.html | 1 + 5 files changed, 98 insertions(+), 21 deletions(-) create mode 100644 zeppelin-web/src/components/baseInterpreterService/baseInterpreter.service.js diff --git a/zeppelin-web/src/app/interpreter/interpreter.controller.js b/zeppelin-web/src/app/interpreter/interpreter.controller.js index e4c772a2c76..315ad139f36 100644 --- a/zeppelin-web/src/app/interpreter/interpreter.controller.js +++ b/zeppelin-web/src/app/interpreter/interpreter.controller.js @@ -15,21 +15,12 @@ 'use strict'; angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope, $route, $routeParams, $location, $rootScope, - $http, baseUrlSrv) { + $http, baseUrlSrv, baseInterpreterService) { var interpreterSettingsTmp = []; $scope.interpreterSettings = []; $scope.availableInterpreters = {}; $scope.showAddNewSetting = false; - var getInterpreterSettings = function() { - $http.get(baseUrlSrv.getRestApiBase()+'/interpreter/setting'). - success(function(data, status, headers, config) { - $scope.interpreterSettings = data.body; - }). - error(function(data, status, headers, config) { - console.log('Error %o %o', status, data.message); - }); - }; var getAvailableInterpreters = function() { $http.get(baseUrlSrv.getRestApiBase()+'/interpreter'). @@ -129,14 +120,10 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope, message: 'Do you want to restart this interpreter?', callback: function(result) { if (result) { - $http.put(baseUrlSrv.getRestApiBase() + '/interpreter/setting/restart/' + settingId). - success(function(data, status, headers, config) { - var index = _.findIndex($scope.interpreterSettings, { 'id': settingId }); - $scope.interpreterSettings[index] = data.body; - }). - error(function(data, status, headers, config) { - console.log('Error %o %o', status, data.message); - }); + baseInterpreterService.restartInterpreterSetting(settingId).then(function(interpreterSettings) { + var index = _.findIndex($scope.interpreterSettings, {'id': settingId}); + $scope.interpreterSettings[index] = interpreterSettings; + }); } } }); @@ -168,7 +155,9 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope, $http.post(baseUrlSrv.getRestApiBase()+'/interpreter/setting', newSetting). success(function(data, status, headers, config) { $scope.resetNewInterpreterSetting(); - getInterpreterSettings(); + baseInterpreterService.getInterpreterSettings().then(function(setting) { + $scope.interpreterSettings = setting; + }); $scope.showAddNewSetting = false; }). error(function(data, status, headers, config) { @@ -223,7 +212,9 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope, var init = function() { $scope.resetNewInterpreterSetting(); - getInterpreterSettings(); + baseInterpreterService.getInterpreterSettings().then(function(setting) { + $scope.interpreterSettings = setting; + }); getAvailableInterpreters(); }; diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js index dd66a593206..8619621f536 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js @@ -16,7 +16,7 @@ angular.module('zeppelinWebApp') .controller('ParagraphCtrl', function($scope,$rootScope, $route, $window, $element, $routeParams, $location, - $timeout, $compile, websocketMsgSrv) { + $timeout, $compile, websocketMsgSrv, $http, baseUrlSrv, baseInterpreterService) { $scope.paragraph = null; $scope.originalText = ''; @@ -206,6 +206,8 @@ angular.module('zeppelinWebApp') $scope.paragraph.status = data.paragraph.status; $scope.paragraph.result = data.paragraph.result; $scope.paragraph.settings = data.paragraph.settings; + $scope.paragraph.interpreterRestarting = undefined; + $scope.paragraph.interpreterRestarted = undefined; if (!$scope.asIframe) { $scope.paragraph.config = data.paragraph.config; @@ -1847,4 +1849,33 @@ angular.module('zeppelinWebApp') var redirectToUrl = location.protocol + '//' + location.host + location.pathname + '#/notebook/' + noteId + '/paragraph/' + $scope.paragraph.id+'?asIframe'; $window.open(redirectToUrl); }; + + $scope.restartInterpreterSetting = function() { + var result = confirm('Do you want to restart this interpreter?'); + if (!result) { + return; + } + + $scope.paragraph.interpreterRestarting = true; + + var settingId = Object.keys($scope.note.angularObjects)[0]; + if ($scope.paragraph.text.split('\n')[0][0] !== '%') { + baseInterpreterService.restartInterpreterSetting(settingId).then(function() { + $scope.paragraph.interpreterRestarted = true; + }); + } else { + var language = $scope.paragraph.text.split('\n')[0].split(' ')[0].split('.')[0].split('%')[1]; + baseInterpreterService.getInterpreterSettings().then(function(settings) { + for (var settingIndex in settings) { + if (settings[settingIndex].name === language) { + settingId = settings[settingIndex].id; + break; + } + } + baseInterpreterService.restartInterpreterSetting(settingId).then(function(interpreterSettings) { + $scope.paragraph.interpreterRestarted = true; + }); + }); + } + }; }); diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.html b/zeppelin-web/src/app/notebook/paragraph/paragraph.html index cded6d8ea31..e926139a1b0 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.html +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.html @@ -399,6 +399,15 @@ ng-if="paragraph.status == 'ERROR'" ng-bind="paragraph.errorMessage"> +
+ +
+
+ Interpreter restarted successfully, re-run the paragraph. +
diff --git a/zeppelin-web/src/components/baseInterpreterService/baseInterpreter.service.js b/zeppelin-web/src/components/baseInterpreterService/baseInterpreter.service.js new file mode 100644 index 00000000000..f6d8bc87049 --- /dev/null +++ b/zeppelin-web/src/components/baseInterpreterService/baseInterpreter.service.js @@ -0,0 +1,45 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +'use strict'; + +angular.module('zeppelinWebApp').service('baseInterpreterService', function($http, baseUrlSrv, $q) { + + this.getInterpreterSettings = function() { + return $q(function(resolve, reject) { + $http.get(baseUrlSrv.getRestApiBase() + '/interpreter/setting'). + success(function(data, status, headers, config) { + resolve(data.body); + }). + error(function(data, status, headers, config) { + console.log('Error %o %o', status, data.message); + reject(); + }); + }); + }; + + this.restartInterpreterSetting = function(settingId) { + return $q(function(resolve, reject) { + $http.put(baseUrlSrv.getRestApiBase() + '/interpreter/setting/restart/' + settingId). + success(function(data, status, headers, config) { + resolve(data.body); + }). + error(function(data, status, headers, config) { + console.log('Error %o %o', status, data.message); + reject(); + }); + }); + + }; + +}); diff --git a/zeppelin-web/src/index.html b/zeppelin-web/src/index.html index 4bddd9849d4..09fdf28e7f1 100644 --- a/zeppelin-web/src/index.html +++ b/zeppelin-web/src/index.html @@ -145,6 +145,7 @@ + From 97b33f113556cf245b4985297c277fe4f9724ba6 Mon Sep 17 00:00:00 2001 From: Prabhjyot Singh Date: Mon, 14 Dec 2015 15:58:32 +0530 Subject: [PATCH 2/3] restart only if there is "timed out" or "thrift" related exception --- .../notebook/paragraph/paragraph.controller.js | 11 +++++++++++ .../src/app/notebook/paragraph/paragraph.html | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js index 8619621f536..4ee24481edc 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js @@ -1850,6 +1850,17 @@ angular.module('zeppelinWebApp') $window.open(redirectToUrl); }; + $scope.checkErrorForRestart = function(){ + var errorText = $scope.paragraph.result.msg; + if (errorText) { + errorText = errorText.toLowerCase(); + if (errorText.indexOf('timed out') > 0 || (errorText.indexOf('thrift') > 0) && errorText.indexOf('except') > 0) { + return true; + } + } + return false; + }; + $scope.restartInterpreterSetting = function() { var result = confirm('Do you want to restart this interpreter?'); if (!result) { diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.html b/zeppelin-web/src/app/notebook/paragraph/paragraph.html index e926139a1b0..ad1e4b65181 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.html +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.html @@ -399,14 +399,16 @@ ng-if="paragraph.status == 'ERROR'" ng-bind="paragraph.errorMessage"> -
- -
-
- Interpreter restarted successfully, re-run the paragraph. +
+
+ +
+
+ Interpreter restarted successfully, re-run the paragraph. +
From 0dfe6d9ca92b08680c8a6dcd0324de8a5e3d73da Mon Sep 17 00:00:00 2001 From: Prabhjyot Singh Date: Mon, 29 Feb 2016 16:16:17 +0530 Subject: [PATCH 3/3] move restartInterpreterSetting to notebook.controller.js --- .../src/app/notebook/notebook.controller.js | 45 ++++++++++++++++++- .../notebook/paragraph/paragraph-results.html | 2 +- .../paragraph/paragraph.controller.js | 35 +-------------- 3 files changed, 45 insertions(+), 37 deletions(-) diff --git a/zeppelin-web/src/app/notebook/notebook.controller.js b/zeppelin-web/src/app/notebook/notebook.controller.js index 194cd7788ca..49b6518e962 100644 --- a/zeppelin-web/src/app/notebook/notebook.controller.js +++ b/zeppelin-web/src/app/notebook/notebook.controller.js @@ -16,8 +16,8 @@ 'use strict'; angular.module('zeppelinWebApp').controller('NotebookCtrl', - function($scope, $route, $routeParams, $location, $rootScope, $http, - websocketMsgSrv, baseUrlSrv, $timeout, SaveAsService) { + function($scope, $route, $routeParams, $location, $rootScope, $http, websocketMsgSrv, baseUrlSrv, + $timeout, SaveAsService, baseInterpreterService) { $scope.note = null; $scope.showEditor = false; $scope.editorToggled = false; @@ -694,6 +694,47 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', } }; + $scope.restartInterpreterSetting = function(id) { + var paragraph; + for (var paragraphIndex in $scope.note.paragraphs) { + if ($scope.note.paragraphs[paragraphIndex].id == id) { + paragraph = $scope.note.paragraphs[paragraphIndex]; + } + } + var settingId = ""; + var settingName = ""; + var language; + if (paragraph.text.split('\n')[0][0] === '%') { + language = paragraph.text.split('\n')[0].split(' ')[0].split('.')[0].split('%')[1]; + } + if (language) { + for (var settingIndex in $scope.interpreterBindings) { + if ($scope.interpreterBindings[settingIndex].name === language) { + settingId = $scope.interpreterBindings[settingIndex].id; + settingName = $scope.interpreterBindings[settingIndex].group; + break; + } + } + } else { + settingId = $scope.interpreterBindings[0].id; + settingName = $scope.interpreterBindings[0].group; + } + + BootstrapDialog.confirm({ + title: '', + message: 'Restart ' + settingName + ' interpreter?
Note that all interpreter states and local variables will be reset.
', + callback: function(result) { + if (result) { + $scope.paragraph.interpreterRestarting = true; + + baseInterpreterService.restartInterpreterSetting(settingId).then(function() { + $scope.paragraph.interpreterRestarted = true; + }); + } + } + }); + }; + var isSettingDirty = function() { if (angular.equals($scope.interpreterBindings, $scope.interpreterBindingsOrig)) { diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph-results.html b/zeppelin-web/src/app/notebook/paragraph/paragraph-results.html index eeb79617b04..17e3b025a55 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph-results.html +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph-results.html @@ -63,7 +63,7 @@
- +
Interpreter restarted successfully, re-run the paragraph. diff --git a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js index 7fd7f5780b6..f1fd04811a4 100644 --- a/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js +++ b/zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js @@ -16,8 +16,7 @@ angular.module('zeppelinWebApp') .controller('ParagraphCtrl', function($scope,$rootScope, $route, $window, $element, $routeParams, $location, - $timeout, $compile, websocketMsgSrv, $http, baseUrlSrv, - baseInterpreterService) { + $timeout, $compile, websocketMsgSrv) { var ANGULAR_FUNCTION_OBJECT_NAME_PREFIX = '_Z_ANGULAR_FUNC_'; $scope.paragraph = null; @@ -2114,38 +2113,6 @@ angular.module('zeppelinWebApp') return false; }; - $scope.restartInterpreterSetting = function() { - BootstrapDialog.confirm({ - title: '', - message: 'Do you want to restart this interpreter?', - callback: function(result) { - if (result) { - $scope.paragraph.interpreterRestarting = true; - - var settingId = Object.keys($scope.note.angularObjects)[0]; - if ($scope.paragraph.text.split('\n')[0][0] !== '%') { - baseInterpreterService.restartInterpreterSetting(settingId).then(function() { - $scope.paragraph.interpreterRestarted = true; - }); - } else { - var language = $scope.paragraph.text.split('\n')[0].split(' ')[0].split('.')[0].split('%')[1]; - baseInterpreterService.getInterpreterSettings().then(function(settings) { - for (var settingIndex in settings) { - if (settings[settingIndex].name === language) { - settingId = settings[settingIndex].id; - break; - } - } - baseInterpreterService.restartInterpreterSetting(settingId).then(function(interpreterSettings) { - $scope.paragraph.interpreterRestarted = true; - }); - }); - } - } - } - }); - }; - $scope.showScrollDownIcon = function() { var doc = angular.element('#p' + $scope.paragraph.id + '_text'); if(doc[0]){