use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method cancelParagraph.
public void cancelParagraph(String noteId, String paragraphId, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
if (!checkPermission(noteId, Permission.RUNNER, Message.OP.CANCEL_PARAGRAPH, context, callback)) {
return;
}
notebook.processNote(noteId, note -> {
if (note == null) {
throw new NoteNotFoundException(noteId);
}
Paragraph p = note.getParagraph(paragraphId);
if (p == null) {
throw new ParagraphNotFoundException(paragraphId);
}
p.abort();
callback.onSuccess(p, context);
return null;
});
}
use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method runAllParagraphs.
/**
* Run list of paragraphs. This method runs provided paragraphs one by one, synchronously.
* When a paragraph fails, subsequent paragraphs are not going to run and this method returns false.
* When list of paragraphs provided from argument is null, list of paragraphs stored in the Note will be used.
*
* @param noteId
* @param paragraphs list of paragraphs to run (passed from frontend). Run note directly when it is null.
* @param context
* @param callback
* @return true when all paragraphs successfully run. false when any paragraph fails.
* @throws IOException
*/
public boolean runAllParagraphs(String noteId, List<Map<String, Object>> paragraphs, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
if (!checkPermission(noteId, Permission.RUNNER, Message.OP.RUN_ALL_PARAGRAPHS, context, callback)) {
return false;
}
return notebook.processNote(noteId, note -> {
if (note == null) {
callback.onFailure(new NoteNotFoundException(noteId), context);
return false;
}
if (paragraphs != null) {
// run note via the data passed from frontend
try {
note.setRunning(true);
for (Map<String, Object> raw : paragraphs) {
String paragraphId = (String) raw.get("id");
if (paragraphId == null) {
LOGGER.warn("No id found in paragraph json: {}", raw);
continue;
}
try {
String text = (String) raw.get("paragraph");
String title = (String) raw.get("title");
Map<String, Object> params = (Map<String, Object>) raw.get("params");
Map<String, Object> config = (Map<String, Object>) raw.get("config");
if (!runParagraph(note, paragraphId, title, text, params, config, null, false, true, context, callback)) {
// stop execution when one paragraph fails.
return false;
}
// also stop execution when user code in a paragraph fails
Paragraph p = note.getParagraph(paragraphId);
InterpreterResult result = p.getReturn();
if (result != null && result.code() == ERROR) {
return false;
}
if (p.getStatus() == ABORT || p.isAborted()) {
return false;
}
} catch (Exception e) {
throw new IOException("Fail to run paragraph json: " + raw, e);
}
}
} finally {
note.setRunning(false);
}
} else {
try {
// run note directly when parameter `paragraphs` is null.
note.runAll(context.getAutheInfo(), true, false, new HashMap<>());
return true;
} catch (Exception e) {
LOGGER.warn("Fail to run note: {}", note.getName(), e);
return false;
}
}
return true;
});
}
use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method listRevisionHistory.
public List<NotebookRepoWithVersionControl.Revision> listRevisionHistory(String noteId, ServiceContext context, ServiceCallback<List<NotebookRepoWithVersionControl.Revision>> callback) throws IOException {
List<NotebookRepoWithVersionControl.Revision> revisions = notebook.processNote(noteId, note -> {
if (note == null) {
callback.onFailure(new NoteNotFoundException(noteId), context);
return null;
}
// }
return notebook.listRevisionHistory(noteId, note.getPath(), context.getAutheInfo());
});
callback.onSuccess(revisions, context);
return revisions;
}
use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method removeNote.
public void removeNote(String noteId, ServiceContext context, ServiceCallback<String> callback) throws IOException {
if (!checkPermission(noteId, Permission.OWNER, Message.OP.DEL_NOTE, context, callback)) {
return;
}
if (notebook.containsNoteById(noteId)) {
try {
notebook.removeNote(noteId, context.getAutheInfo());
callback.onSuccess("Delete note successfully", context);
} catch (CorruptedNoteException e) {
notebook.removeCorruptedNote(noteId, context.getAutheInfo());
callback.onSuccess("Delete note successfully", context);
}
} else {
callback.onFailure(new NoteNotFoundException(noteId), context);
}
}
use of org.apache.zeppelin.rest.exception.NoteNotFoundException in project zeppelin by apache.
the class NotebookService method moveParagraph.
public void moveParagraph(String noteId, String paragraphId, int newIndex, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
if (!checkPermission(noteId, Permission.WRITER, Message.OP.MOVE_PARAGRAPH, context, callback)) {
return;
}
notebook.processNote(noteId, note -> {
if (note == null) {
throw new NoteNotFoundException(noteId);
}
if (note.getParagraph(paragraphId) == null) {
throw new ParagraphNotFoundException(paragraphId);
}
if (newIndex >= note.getParagraphCount()) {
callback.onFailure(new BadRequestException("newIndex " + newIndex + " is out of bounds"), context);
return null;
}
note.moveParagraph(paragraphId, newIndex);
notebook.saveNote(note, context.getAutheInfo());
callback.onSuccess(note.getParagraph(newIndex), context);
return null;
});
}
Aggregations