Interpreter restarts on a note.

This commit is contained in:
astroshim 2016-08-08 16:26:32 +09:00
parent 045b2d24d8
commit 5ad4503951
4 changed files with 97 additions and 16 deletions

View file

@ -33,6 +33,7 @@ import javax.ws.rs.core.Response.Status;
import com.google.gson.Gson;
import org.apache.commons.lang.exception.ExceptionUtils;
import org.apache.zeppelin.rest.message.RestartInterpreterRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonatype.aether.RepositoryException;
@ -150,9 +151,22 @@ public class InterpreterRestApi {
@PUT
@Path("setting/restart/{settingId}")
@ZeppelinApi
public Response restartSetting(@PathParam("settingId") String settingId) {
logger.info("Restart interpreterSetting {}", settingId);
public Response restartSetting(String message, @PathParam("settingId") String settingId) {
logger.info("Restart interpreterSetting {}, msg={}", settingId, message);
try {
RestartInterpreterRequest request =
gson.fromJson(message, RestartInterpreterRequest.class);
InterpreterSetting setting = interpreterFactory.get(settingId);
if (setting != null && request.getType().trim().equals("self")) {
if ((setting.getOption().isPerNoteProcess() |
setting.getOption().isPerNoteSession()) == false) {
return new JsonResponse<>(Status.FORBIDDEN,
"Can't restart shared interpreter process.").build();
}
}
interpreterFactory.restart(settingId);
} catch (InterpreterException e) {
logger.error("Exception in InterpreterRestApi while restartSetting ", e);

View file

@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.zeppelin.rest.message;
/**
* RestartInterpreter rest api request message
*/
public class RestartInterpreterRequest {
String type;
public RestartInterpreterRequest() {
}
public String getType() {
return type;
}
}

View file

@ -643,6 +643,33 @@ angular.module('zeppelinWebApp').controller('NotebookCtrl', function($scope, $ro
$scope.permissions.writers = angular.element('#selectWriters').val();
}
$scope.restartInterpreter = function(interpeter) {
BootstrapDialog.confirm({
closable: true,
title: 'Restart ' + interpeter.name + ' interpreter',
message: 'Do you want to restart ' + interpeter.name + ' interpreter?',
callback: function(result) {
if (result) {
var payload = {
'type': 'self'
};
$http.put(baseUrlSrv.getRestApiBase() + '/interpreter/setting/restart/' + interpeter.id, payload)
.success(function(data, status, headers, config) {
var index = _.findIndex($scope.interpreterSettings, {'id': interpeter.id});
$scope.interpreterSettings[index] = data.body;
}).error(function(data, status, headers, config) {
console.log('Error %o %o', status, data.message);
BootstrapDialog.show({
title: 'Error restart interpreter.',
message: data.message
});
});
}
}
});
}
$scope.savePermissions = function() {
convertPermissionsToArray();
$http.put(baseUrlSrv.getRestApiBase() + '/notebook/' + $scope.note.id + '/permissions',

View file

@ -32,20 +32,27 @@ limitations under the License.
<div class="interpreterSettings"
as-sortable="interpreterSelectionListeners" data-ng-model="interpreterBindings">
<div data-ng-repeat="item in interpreterBindings" as-sortable-item>
<div as-sortable-item-handle
ng-click="item.selected = !item.selected"
class="btn"
ng-class="{'btn-info': item.selected, 'btn-default': !item.selected}">
<font style="font-size:16px">{{item.name}}</font>
<small>
<span style="display:inline-block" ng-repeat="intp in item.interpreters">
<span ng-show="!$first">, </span>
%<span ng-show="!$parent.$first || $first">{{item.name}}</span
><span ng-show="(!$parent.$first || $first) && !$first">.</span
><span ng-show="!$first">{{intp.name}}</span>
<span ng-show="$parent.$first && $first">(default)</span>
</span>
</small>
<div>
<div as-sortable-item-handle
class="btn btn-warning"
ng-click="restartInterpreter(item)">
<font style="font-size:16px">Restart</font>
</div>
<div as-sortable-item-handle
ng-click="item.selected = !item.selected"
class="btn"
ng-class="{'btn-info': item.selected, 'btn-default': !item.selected}">
<font style="font-size:16px">{{item.name}}</font>
<small>
<span style="display:inline-block" ng-repeat="intp in item.interpreters">
<span ng-show="!$first">, </span>
%<span ng-show="!$parent.$first || $first">{{item.name}}</span
><span ng-show="(!$parent.$first || $first) && !$first">.</span
><span ng-show="!$first">{{intp.name}}</span>
<span ng-show="$parent.$first && $first">(default)</span>
</span>
</small>
</div>
</div>
</div>
</div>