Search in sources :

Example 21 with NoteNotFoundException

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

Example 22 with NoteNotFoundException

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

Example 23 with NoteNotFoundException

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

Example 24 with NoteNotFoundException

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

Example 25 with NoteNotFoundException

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

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