use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method renameNote.
public void renameNote(String noteId, String newNotePath, boolean isRelative, ServiceContext context, ServiceCallback<Note> callback) throws IOException {
if (!checkPermission(noteId, Permission.OWNER, Message.OP.NOTE_RENAME, context, callback)) {
return;
}
notebook.processNote(noteId, readNote -> {
if (readNote == null) {
callback.onFailure(new NoteNotFoundException(noteId), context);
}
readNote.setCronSupported(notebook.getConf());
String newNotePathReal = newNotePath;
if (isRelative && !readNote.getParentPath().equals("/")) {
newNotePathReal = readNote.getParentPath() + "/" + newNotePath;
} else {
if (!newNotePath.startsWith("/")) {
newNotePathReal = "/" + newNotePath;
}
}
try {
notebook.moveNote(noteId, newNotePathReal, context.getAutheInfo());
callback.onSuccess(readNote, context);
} catch (NotePathAlreadyExistsException e) {
callback.onFailure(e, context);
}
return null;
});
}
use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method removeParagraph.
public void removeParagraph(String noteId, String paragraphId, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
if (!checkPermission(noteId, Permission.WRITER, Message.OP.PARAGRAPH_REMOVE, context, callback)) {
return;
}
notebook.processNote(noteId, note -> {
if (note == null) {
throw new NoteNotFoundException(noteId);
}
if (note.getParagraph(paragraphId) == null) {
throw new ParagraphNotFoundException(paragraphId);
}
Paragraph p = note.removeParagraph(context.getAutheInfo().getUser(), paragraphId);
notebook.saveNote(note, context.getAutheInfo());
callback.onSuccess(p, context);
return null;
});
}
use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method updateNote.
public void updateNote(String noteId, String name, Map<String, Object> config, ServiceContext context, ServiceCallback<Note> callback) throws IOException {
if (!checkPermission(noteId, Permission.WRITER, Message.OP.NOTE_UPDATE, context, callback)) {
return;
}
// use write lock because config and name are overwritten
notebook.processNote(noteId, note -> {
if (note == null) {
callback.onFailure(new NoteNotFoundException(noteId), context);
return null;
}
if (!(Boolean) note.getConfig().get("isZeppelinNotebookCronEnable")) {
if (config.get("cron") != null) {
config.remove("cron");
}
}
boolean cronUpdated = isCronUpdated(config, note.getConfig());
note.setName(name);
note.setConfig(config);
if (cronUpdated) {
schedulerService.refreshCron(note.getId());
}
notebook.updateNote(note, context.getAutheInfo());
callback.onSuccess(note, context);
return null;
});
}
use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method getNextSessionParagraphId.
/**
* @param noteId
* @param maxParagraph
* @param context
* @param callback
* @return paragraphId
* @throws IOException
*/
public String getNextSessionParagraphId(String noteId, int maxParagraph, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
if (!checkPermission(noteId, Permission.WRITER, Message.OP.PARAGRAPH_CLEAR_OUTPUT, context, callback)) {
throw new IOException("No privilege to access this note");
}
return notebook.processNote(noteId, note -> {
if (note == null) {
callback.onFailure(new NoteNotFoundException(noteId), context);
throw new IOException("No such note");
}
synchronized (this) {
if (note.getParagraphCount() >= maxParagraph) {
boolean removed = false;
for (int i = 1; i < note.getParagraphCount(); ++i) {
if (note.getParagraph(i).getStatus().isCompleted()) {
note.removeParagraph(context.getAutheInfo().getUser(), note.getParagraph(i).getId());
removed = true;
break;
}
}
if (!removed) {
throw new IOException("All the paragraphs are not completed, unable to find available paragraph");
}
}
return note.addNewParagraph(context.getAutheInfo()).getId();
}
});
}
use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method getEditorSetting.
public void getEditorSetting(String noteId, String paragraphText, ServiceContext context, ServiceCallback<Map<String, Object>> callback) throws IOException {
notebook.processNote(noteId, note -> {
if (note == null) {
callback.onFailure(new NoteNotFoundException(noteId), context);
}
try {
Map<String, Object> settings = notebook.getInterpreterSettingManager().getEditorSetting(paragraphText, noteId);
callback.onSuccess(settings, context);
} catch (Exception e) {
callback.onFailure(new IOException("Fail to getEditorSetting", e), context);
}
return null;
});
}
Aggregations