Search in sources :

Example 16 with NoteNotFoundException

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;
    });
}
Also used : ParagraphNotFoundException(org.apache.zeppelin.rest.exception.ParagraphNotFoundException) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 17 with NoteNotFoundException

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;
    });
}
Also used : InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) AngularObject(org.apache.zeppelin.display.AngularObject) IOException(java.io.IOException) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) HashMap(java.util.HashMap) Map(java.util.Map) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) ParagraphNotFoundException(org.apache.zeppelin.rest.exception.ParagraphNotFoundException) ParseException(java.text.ParseException) IOException(java.io.IOException) NotePathAlreadyExistsException(org.apache.zeppelin.notebook.exception.NotePathAlreadyExistsException) ForbiddenException(org.apache.zeppelin.rest.exception.ForbiddenException) BadRequestException(org.apache.zeppelin.rest.exception.BadRequestException) CorruptedNoteException(org.apache.zeppelin.notebook.exception.CorruptedNoteException) Paragraph(org.apache.zeppelin.notebook.Paragraph)

Example 18 with NoteNotFoundException

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;
}
Also used : NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Example 19 with NoteNotFoundException

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);
    }
}
Also used : NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException) CorruptedNoteException(org.apache.zeppelin.notebook.exception.CorruptedNoteException)

Example 20 with NoteNotFoundException

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;
    });
}
Also used : BadRequestException(org.apache.zeppelin.rest.exception.BadRequestException) ParagraphNotFoundException(org.apache.zeppelin.rest.exception.ParagraphNotFoundException) NoteNotFoundException(org.apache.zeppelin.rest.exception.NoteNotFoundException)

Aggregations

NoteNotFoundException (org.apache.zeppelin.rest.exception.NoteNotFoundException)25 ParagraphNotFoundException (org.apache.zeppelin.rest.exception.ParagraphNotFoundException)8 IOException (java.io.IOException)6 Paragraph (org.apache.zeppelin.notebook.Paragraph)6 CorruptedNoteException (org.apache.zeppelin.notebook.exception.CorruptedNoteException)5 Note (org.apache.zeppelin.notebook.Note)4 NotePathAlreadyExistsException (org.apache.zeppelin.notebook.exception.NotePathAlreadyExistsException)4 BadRequestException (org.apache.zeppelin.rest.exception.BadRequestException)4 ParseException (java.text.ParseException)3 ForbiddenException (org.apache.zeppelin.rest.exception.ForbiddenException)3 AngularObject (org.apache.zeppelin.display.AngularObject)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 InterpreterCompletion (org.apache.zeppelin.interpreter.thrift.InterpreterCompletion)1 NotebookRepoWithVersionControl (org.apache.zeppelin.notebook.repo.NotebookRepoWithVersionControl)1