Skip to content
Closed
52 changes: 21 additions & 31 deletions zeppelin-web/src/app/interpreter/interpreter.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,16 @@
*/
'use strict';

angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope, $route, $routeParams, $location, $rootScope,
$http, baseUrlSrv, ngToast) {
angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope, $route,
$routeParams, $location, $rootScope, $http, baseUrlSrv,
ngToast, baseInterpreterService) {
var interpreterSettingsTmp = [];
$scope.interpreterSettings = [];
$scope.availableInterpreters = {};
$scope.showAddNewSetting = false;
$scope.showRepositoryInfo = false;
$scope._ = _;

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').
success(function(data, status, headers, config) {
Expand Down Expand Up @@ -153,14 +144,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;
});
}
}
});
Expand Down Expand Up @@ -202,16 +189,18 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope,
}
request.properties = newProperties;

$http.post(baseUrlSrv.getRestApiBase() + '/interpreter/setting', request).
success(function(data, status, headers, config) {
$scope.resetNewInterpreterSetting();
getInterpreterSettings();
$scope.showAddNewSetting = false;
}).
error(function(data, status, headers, config) {
console.log('Error %o %o', status, data.message);
ngToast.danger(data.message);
$http.post(baseUrlSrv.getRestApiBase()+'/interpreter/setting', newSetting).
success(function(data, status, headers, config) {
$scope.resetNewInterpreterSetting();
baseInterpreterService.getInterpreterSettings().then(function(setting) {
$scope.interpreterSettings = setting;
});
$scope.showAddNewSetting = false;
}).
error(function(data, status, headers, config) {
console.log('Error %o %o', status, data.message);
ngToast.danger(data.message);
});
};

$scope.cancelInterpreterSetting = function() {
Expand Down Expand Up @@ -399,8 +388,9 @@ angular.module('zeppelinWebApp').controller('InterpreterCtrl', function($scope,

var init = function() {
$scope.resetNewInterpreterSetting();
$scope.resetNewRepositorySetting();
getInterpreterSettings();
baseInterpreterService.getInterpreterSettings().then(function(setting) {
$scope.interpreterSettings = setting;
});
getAvailableInterpreters();
getRepositories();
};
Expand Down
45 changes: 43 additions & 2 deletions zeppelin-web/src/app/notebook/notebook.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <strong>' + settingName + '</strong> interpreter? <div class="alert-warning"> Note that all interpreter states and local variables will be reset. </div>',
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)) {
Expand Down
11 changes: 11 additions & 0 deletions zeppelin-web/src/app/notebook/paragraph/paragraph-results.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,15 @@
ng-if="paragraph.status == 'ERROR'"
ng-bind="paragraph.errorMessage">
</div>

<div ng-if="(paragraph.status == 'ERROR') && checkErrorForRestart()">
<div
ng-class="{disable: paragraph.interpreterRestarting}"
ng-if="!paragraph.interpreterRestarted">
<button class="btn btn-default btn-xs" ng-click="restartInterpreterSetting(paragraph.id)"> <span class="fa fa-refresh"></span> Restart Interpreter</button>
</div>
<div ng-if="paragraph.interpreterRestarted">
<em>Interpreter restarted successfully, re-run the paragraph.</em>
</div>
</div>
</div>
18 changes: 17 additions & 1 deletion zeppelin-web/src/app/notebook/paragraph/paragraph.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
angular.module('zeppelinWebApp')
.controller('ParagraphCtrl', function($scope,$rootScope, $route, $window, $element, $routeParams, $location,
$timeout, $compile, websocketMsgSrv) {

var ANGULAR_FUNCTION_OBJECT_NAME_PREFIX = '_Z_ANGULAR_FUNC_';
$scope.paragraph = null;
$scope.originalText = '';
Expand Down Expand Up @@ -347,6 +348,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;
Expand Down Expand Up @@ -2097,7 +2100,20 @@ angular.module('zeppelinWebApp')
$window.open(redirectToUrl);
};

$scope.showScrollDownIcon = function(){
$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 ||
errorText.indexOf('connection refused') > 0) {
return true;
}
}
return false;
};

$scope.showScrollDownIcon = function() {
var doc = angular.element('#p' + $scope.paragraph.id + '_text');
if(doc[0]){
return doc[0].scrollHeight > doc.innerHeight();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
});
});

};

});
1 change: 1 addition & 0 deletions zeppelin-web/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<script src="components/websocketEvents/websocketEvents.factory.js"></script>
<script src="components/notebookListDataFactory/notebookList.datafactory.js"></script>
<script src="components/baseUrl/baseUrl.service.js"></script>
<script src="components/baseInterpreterService/baseInterpreter.service.js"></script>
<script src="components/browser-detect/browserDetect.service.js"></script>
<script src="components/saveAs/saveAs.service.js"></script>
<script src="components/searchService/search.service.js"></script>
Expand Down