Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions conf/shiro.ini.template
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ admin = *
#
/api/version = anon
/api/cluster/address = anon
# Allow all authenticated users to restart interpreters on a notebook page.
# Comment out the following line if you would like to authorize only admin users to restart interpreters.
# Interpreter restart endpoints:
# - /api/interpreter/setting/restart/** : Restart interpreter for a specific note (requires noteId in request body)
# - /api/interpreter/setting/restart-all/** : Restart interpreter globally (affects all users/sessions)
#
# Allow all authenticated users to restart interpreters on a notebook page and globally.
# Comment out the following line and uncomment the next line if you would like to authorize only admin users to restart interpreters globally.
/api/interpreter/setting/restart-all/** = authc
#/api/interpreter/setting/restart-all/** = authc, roles[admin]
/api/interpreter/setting/restart/** = authc
/api/interpreter/** = authc, roles[admin]
/api/notebook-repositories/** = authc, roles[admin]
Expand Down
44 changes: 40 additions & 4 deletions docs/usage/rest_api/interpreter.md
Original file line number Diff line number Diff line change
Expand Up @@ -478,13 +478,13 @@ The role of registered interpreters, settings and interpreters group are describ


<br/>
### Restart an interpreter
### Restart an interpreter for a specific note

<table class="table-configuration">
<col width="200">
<tr>
<td>Description</td>
<td>This ```PUT``` method restarts the given interpreter id.</td>
<td>This ```PUT``` method restarts the given interpreter for a specific note. The ```noteId``` is required in the request body.</td>
</tr>
<tr>
<td>URL</td>
Expand All @@ -496,10 +496,10 @@ The role of registered interpreters, settings and interpreters group are describ
</tr>
<tr>
<td>Fail code</td>
<td> 500 </td>
<td> 400 (if noteId is missing), 403 (no permission), 404 (interpreter not found), 500 </td>
</tr>
<tr>
<td>Sample JSON input (Optional)</td>
<td>Sample JSON input (Required)</td>
<td>

```json
Expand All @@ -520,6 +520,42 @@ The role of registered interpreters, settings and interpreters group are describ
</tr>
</table>

<br/>
### Restart an interpreter globally

<table class="table-configuration">
<col width="200">
<tr>
<td>Description</td>
<td>This ```PUT``` method restarts the given interpreter globally (affects all users/sessions). This endpoint can be restricted to admin users only via shiro.ini configuration.</td>
</tr>
<tr>
<td>URL</td>
<td>```http://[zeppelin-server]:[zeppelin-port]/api/interpreter/setting/restart-all/[interpreter ID]```</td>
</tr>
<tr>
<td>Success code</td>
<td>200</td>
</tr>
<tr>
<td>Fail code</td>
<td> 403 (no permission), 404 (interpreter not found), 500 </td>
</tr>
<tr>
<td>Sample JSON input</td>
<td>None</td>
</tr>
<tr>
<td>Sample JSON response</td>
<td>

```json
{"status":"OK"}
```
</td>
</tr>
</table>

<br/>
### Add a new repository for dependency resolving

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ public Response removeSetting(@PathParam("settingId") String settingId) throws I
}

/**
* Restart interpreter setting.
* Restart interpreter setting for a specific note.
* Requires noteId in request body.
*/
@PUT
@Path("setting/restart/{settingId}")
Expand All @@ -204,7 +205,8 @@ public Response restartSetting(String message, @PathParam("settingId") String se

String noteId = request == null ? null : request.getNoteId();
if (null == noteId) {
interpreterSettingManager.close(settingId);
return new JsonResponse<>(Status.BAD_REQUEST, "noteId is required. Use /restart-all endpoint for global restart.")
.build();
} else {
Set<String> entities = new HashSet<>();
entities.add(authenticationService.getPrincipal());
Expand All @@ -229,6 +231,24 @@ public Response restartSetting(String message, @PathParam("settingId") String se
return new JsonResponse<>(Status.OK, "", setting).build();
}

/**
* Restart interpreter setting globally (all sessions).
* This endpoint should be protected by shiro.ini for admin only.
*/
@PUT
@Path("setting/restart-all/{settingId}")
@ZeppelinApi
public Response restartSettingAll(@PathParam("settingId") String settingId) {
LOGGER.info("Restart ALL interpreterSetting {}, user={}", settingId, authenticationService.getPrincipal());

InterpreterSetting setting = interpreterSettingManager.get(settingId);
if (setting == null) {
return new JsonResponse<>(Status.NOT_FOUND, "", settingId).build();
}
interpreterSettingManager.close(settingId);
return new JsonResponse<>(Status.OK, "", setting).build();
}

/**
* List all available interpreters by group.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,11 @@ void testInterpreterRestart() throws IOException, InterruptedException {
return note.getBindedInterpreterSettings(new ArrayList<>());
});

// when: restart interpreter
// when: restart interpreter globally
for (InterpreterSetting setting : settings) {
if (setting.getName().equals("md")) {
// call restart interpreter API
CloseableHttpResponse put = httpPut("/interpreter/setting/restart/" + setting.getId(), "");
// call restart interpreter API (global restart)
CloseableHttpResponse put = httpPut("/interpreter/setting/restart-all/" + setting.getId(), "");
assertThat("test interpreter restart:", put, isAllowed());
put.close();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,6 @@ export class InterpreterService extends BaseRest {
}

restartInterpreterSetting(settingId: string) {
return this.http.put(this.restUrl`/interpreter/setting/restart/${settingId}`, null);
return this.http.put(this.restUrl`/interpreter/setting/restart-all/${settingId}`, null);
}
}
2 changes: 1 addition & 1 deletion zeppelin-web/src/app/interpreter/interpreter.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ function InterpreterCtrl($rootScope, $scope, $http, baseUrlSrv, ngToast, $timeou
message: 'Do you want to restart this interpreter?',
callback: function(result) {
if (result) {
$http.put(baseUrlSrv.getRestApiBase() + '/interpreter/setting/restart/' + settingId)
$http.put(baseUrlSrv.getRestApiBase() + '/interpreter/setting/restart-all/' + settingId)
.then(function(res) {
let index = _.findIndex($scope.interpreterSettings, {'id': settingId});
$scope.interpreterSettings[index] = res.data.body;
Expand Down
Loading