use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class AbstractRestApi method getServiceContext.
protected ServiceContext getServiceContext() {
AuthenticationInfo authInfo = new AuthenticationInfo(authenticationService.getPrincipal());
Set<String> userAndRoles = new HashSet<>();
userAndRoles.add(authenticationService.getPrincipal());
userAndRoles.addAll(authenticationService.getAssociatedRoles());
return new ServiceContext(authInfo, userAndRoles);
}
use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class NotebookRepoRestApi method updateRepoSetting.
/**
* Update a specific note repo.
*
* @param payload
* @return
*/
@PUT
@ZeppelinApi
public Response updateRepoSetting(String payload) {
if (StringUtils.isBlank(payload)) {
return new JsonResponse<>(Status.NOT_FOUND, "", Collections.emptyMap()).build();
}
AuthenticationInfo subject = new AuthenticationInfo(authenticationService.getPrincipal());
NotebookRepoSettingsRequest newSettings;
try {
newSettings = NotebookRepoSettingsRequest.fromJson(payload);
} catch (JsonSyntaxException e) {
LOG.error("Cannot update notebook repo settings", e);
return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload structure")).build();
}
if (NotebookRepoSettingsRequest.isEmpty(newSettings)) {
LOG.error("Invalid property");
return new JsonResponse<>(Status.NOT_ACCEPTABLE, "", ImmutableMap.of("error", "Invalid payload")).build();
}
LOG.info("User {} is going to change repo setting", subject.getUser());
NotebookRepoWithSettings updatedSettings = noteRepos.updateNotebookRepo(newSettings.name, newSettings.settings, subject);
if (!updatedSettings.isEmpty()) {
LOG.info("Broadcasting note list to user {}", subject.getUser());
try {
notebookWsServer.broadcastReloadedNoteList(getServiceContext());
} catch (IOException e) {
LOG.error("Fail to refresh repo.", e);
}
}
return new JsonResponse<>(Status.OK, "", updatedSettings).build();
}
use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class NotebookRepoRestApi method getServiceContext.
private ServiceContext getServiceContext() {
AuthenticationInfo authInfo = new AuthenticationInfo(authenticationService.getPrincipal());
Set<String> userAndRoles = new HashSet<>();
userAndRoles.add(authenticationService.getPrincipal());
userAndRoles.addAll(authenticationService.getAssociatedRoles());
return new ServiceContext(authInfo, userAndRoles);
}
use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class NotebookRestApi method runNoteJobs.
/**
* Run note jobs REST API.
*
* @param noteId ID of Note
* @param blocking blocking until jobs are done
* @param isolated use isolated interpreter for running this note
* @param message any parameters passed to note
* @return JSON with status.OK
* @throws IOException
* @throws IllegalArgumentException
*/
@POST
@Path("job/{noteId}")
@ZeppelinApi
public Response runNoteJobs(@PathParam("noteId") String noteId, @DefaultValue("false") @QueryParam("blocking") boolean blocking, @DefaultValue("false") @QueryParam("isolated") boolean isolated, String message) throws Exception, IllegalArgumentException {
Map<String, Object> params = new HashMap<>();
if (!StringUtils.isEmpty(message)) {
ParametersRequest request = ParametersRequest.fromJson(message);
params.putAll(request.getParams());
}
LOGGER.info("Run note jobs, noteId: {}, blocking: {}, isolated: {}, params: {}", noteId, blocking, isolated, params);
return notebook.processNote(noteId, note -> {
AuthenticationInfo subject = new AuthenticationInfo(authenticationService.getPrincipal());
subject.setRoles(authenticationService.getAssociatedRoles());
checkIfNoteIsNotNull(note, noteId);
checkIfUserCanRun(noteId, "Insufficient privileges you cannot run job for this note");
// TODO(zjffdu), can we run a note via rest api when cron is enabled ?
try {
note.runAll(subject, blocking, isolated, params);
return new JsonResponse<>(Status.OK).build();
} catch (Exception e) {
return new JsonResponse<>(Status.INTERNAL_SERVER_ERROR, "Fail to run note").build();
}
});
}
use of org.apache.zeppelin.user.AuthenticationInfo in project zeppelin by apache.
the class NotebookRestApi method createNote.
/**
* Create new note REST API with note json.
*
* @param message - JSON with new note name
* @return JSON with new note ID
* @throws IOException
*/
@POST
@ZeppelinApi
public Response createNote(String message) throws IOException {
String user = authenticationService.getPrincipal();
LOGGER.info("Creating new note by JSON {}", message);
NewNoteRequest request = NewNoteRequest.fromJson(message);
String defaultInterpreterGroup = request.getDefaultInterpreterGroup();
if (StringUtils.isBlank(defaultInterpreterGroup)) {
defaultInterpreterGroup = zConf.getString(ZeppelinConfiguration.ConfVars.ZEPPELIN_INTERPRETER_GROUP_DEFAULT);
}
String noteId = notebookService.createNote(request.getName(), defaultInterpreterGroup, request.getAddingEmptyParagraph(), getServiceContext(), new RestServiceCallback<>());
return notebook.processNote(noteId, note -> {
AuthenticationInfo subject = new AuthenticationInfo(authenticationService.getPrincipal());
if (request.getParagraphs() != null) {
for (NewParagraphRequest paragraphRequest : request.getParagraphs()) {
Paragraph p = note.addNewParagraph(subject);
initParagraph(p, paragraphRequest, user);
}
}
return new JsonResponse<>(Status.OK, "", note.getId()).build();
});
}
Aggregations