use of org.apache.zeppelin.rest.exception.ParagraphNotFoundException in project zeppelin by apache.
the class NotebookService method updateParagraph.
public void updateParagraph(String noteId, String paragraphId, String title, String text, Map<String, Object> params, Map<String, Object> config, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
if (!checkPermission(noteId, Permission.WRITER, Message.OP.COMMIT_PARAGRAPH, context, callback)) {
return;
}
notebook.processNote(noteId, note -> {
if (note == null) {
callback.onFailure(new NoteNotFoundException(noteId), context);
return null;
}
Paragraph p = note.getParagraph(paragraphId);
if (p == null) {
callback.onFailure(new ParagraphNotFoundException(paragraphId), context);
return null;
}
p.settings.setParams(params);
p.mergeConfig(config);
p.setTitle(title);
p.setText(text);
if (note.isPersonalizedMode()) {
p = p.getUserParagraph(context.getAutheInfo().getUser());
p.settings.setParams(params);
p.mergeConfig(config);
p.setTitle(title);
p.setText(text);
}
notebook.saveNote(note, context.getAutheInfo());
callback.onSuccess(p, context);
return null;
});
}
use of org.apache.zeppelin.rest.exception.ParagraphNotFoundException in project zeppelin by apache.
the class NotebookService method clearParagraphOutput.
public void clearParagraphOutput(String noteId, String paragraphId, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
if (!checkPermission(noteId, Permission.WRITER, Message.OP.PARAGRAPH_CLEAR_OUTPUT, context, callback)) {
return;
}
notebook.processNote(noteId, note -> {
if (note == null) {
callback.onFailure(new NoteNotFoundException(noteId), context);
return null;
}
Paragraph p = note.getParagraph(paragraphId);
if (p == null) {
callback.onFailure(new ParagraphNotFoundException(paragraphId), context);
return null;
}
Paragraph returnedParagraph;
if (note.isPersonalizedMode()) {
returnedParagraph = note.clearPersonalizedParagraphOutput(paragraphId, context.getAutheInfo().getUser());
} else {
note.clearParagraphOutput(paragraphId);
returnedParagraph = note.getParagraph(paragraphId);
}
callback.onSuccess(returnedParagraph, context);
return null;
});
}
use of org.apache.zeppelin.rest.exception.ParagraphNotFoundException 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.ParagraphNotFoundException 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;
});
}
use of org.apache.zeppelin.rest.exception.ParagraphNotFoundException in project zeppelin by apache.
the class NotebookService method runParagraph.
/**
* Executes given paragraph with passed paragraph info like noteId, paragraphId, title, text and etc.
*
* @param noteId
* @param paragraphId
* @param title
* @param text
* @param params
* @param config
* @param failIfDisabled
* @param blocking
* @param context
* @param callback
* @return return true only when paragraph execution finished, it could end with succeed or error due to user code.
* return false when paragraph execution fails due to zeppelin internal issue.
* @throws IOException
*/
public boolean runParagraph(Note note, String paragraphId, String title, String text, Map<String, Object> params, Map<String, Object> config, String sessionId, boolean failIfDisabled, boolean blocking, ServiceContext context, ServiceCallback<Paragraph> callback) throws IOException {
if (note == null) {
return false;
}
LOGGER.info("Start to run paragraph: {} of note: {}", paragraphId, note.getId());
if (!checkPermission(note.getId(), Permission.RUNNER, Message.OP.RUN_PARAGRAPH, context, callback)) {
return false;
}
Paragraph p = note.getParagraph(paragraphId);
if (p == null) {
callback.onFailure(new ParagraphNotFoundException(paragraphId), context);
return false;
}
if (failIfDisabled && !p.isEnabled()) {
callback.onFailure(new IOException("paragraph is disabled."), context);
return false;
}
p.setText(text);
p.setTitle(title);
p.setAuthenticationInfo(context.getAutheInfo());
if (params != null && !params.isEmpty()) {
p.settings.setParams(params);
}
if (config != null && !config.isEmpty()) {
p.mergeConfig(config);
}
if (note.isPersonalizedMode()) {
p = p.getUserParagraph(context.getAutheInfo().getUser());
p.setText(text);
p.setTitle(title);
p.setAuthenticationInfo(context.getAutheInfo());
if (params != null && !params.isEmpty()) {
p.settings.setParams(params);
}
if (config != null && !config.isEmpty()) {
p.mergeConfig(config);
}
}
try {
notebook.saveNote(note, context.getAutheInfo());
note.run(p.getId(), sessionId, blocking, context.getAutheInfo().getUser());
callback.onSuccess(p, context);
return true;
} catch (Exception ex) {
LOGGER.error("Exception from run", ex);
p.setReturn(new InterpreterResult(InterpreterResult.Code.ERROR, ex.getMessage()), ex);
p.setStatus(Job.Status.ERROR);
// in paragraph result section instead of pop up the error window.
return false;
}
}
Aggregations