From de7c937815d5054f9d8a759d170f3e48c8452e2a Mon Sep 17 00:00:00 2001 From: Kavin Date: Tue, 18 Oct 2016 12:22:15 +0530 Subject: [PATCH] Show error message to the user when there is permission issue on creating notebook. --- .../zeppelin/socket/NotebookServer.java | 56 +++++++++++-------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java index 4934265424a..3e137b8bc2d 100644 --- a/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java +++ b/zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java @@ -712,39 +712,49 @@ private boolean isCronUpdated(Map configA, return cronUpdated; } + private void createNote(NotebookSocket conn, HashSet userAndRoles, Notebook notebook, Message message) throws IOException { AuthenticationInfo subject = new AuthenticationInfo(message.principal); - Note note = null; - String defaultInterpreterId = (String) message.get("defaultInterpreterId"); - if (!StringUtils.isEmpty(defaultInterpreterId)) { - List interpreterSettingIds = new LinkedList<>(); - interpreterSettingIds.add(defaultInterpreterId); - for (String interpreterSettingId : notebook.getInterpreterFactory(). - getDefaultInterpreterSettingList()) { - if (!interpreterSettingId.equals(defaultInterpreterId)) { - interpreterSettingIds.add(interpreterSettingId); + try { + Note note = null; + + String defaultInterpreterId = (String) message.get("defaultInterpreterId"); + if (!StringUtils.isEmpty(defaultInterpreterId)) { + List interpreterSettingIds = new LinkedList<>(); + interpreterSettingIds.add(defaultInterpreterId); + for (String interpreterSettingId : notebook.getInterpreterFactory(). + getDefaultInterpreterSettingList()) { + if (!interpreterSettingId.equals(defaultInterpreterId)) { + interpreterSettingIds.add(interpreterSettingId); + } } + note = notebook.createNote(interpreterSettingIds, subject); + } else { + note = notebook.createNote(subject); } - note = notebook.createNote(interpreterSettingIds, subject); - } else { - note = notebook.createNote(subject); - } - note.addParagraph(); // it's an empty note. so add one paragraph - if (message != null) { - String noteName = (String) message.get("name"); - if (StringUtils.isEmpty(noteName)){ - noteName = "Note " + note.getId(); + note.addParagraph(); // it's an empty note. so add one paragraph + if (message != null) { + String noteName = (String) message.get("name"); + if (StringUtils.isEmpty(noteName)) { + noteName = "Note " + note.getId(); + } + note.setName(noteName); } - note.setName(noteName); - } - note.persist(subject); - addConnectionToNote(note.getId(), (NotebookSocket) conn); - conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", note))); + note.persist(subject); + addConnectionToNote(note.getId(), (NotebookSocket) conn); + conn.send(serializeMessage(new Message(OP.NEW_NOTE).put("note", note))); + } catch (FileSystemException e) { + LOG.error("Exception from createNote", e); + conn.send(serializeMessage(new Message(OP.ERROR_INFO).put("info", + "Oops! There is something wrong with the notebook file system. " + + "Please check the logs for more details."))); + return; + } broadcastNoteList(subject, userAndRoles); }