Repository: zeppelin Updated Branches: refs/heads/master 2ea1ce541 -> 8dde8fb9a
[ZEPPELIN-1612] Fix NPE when initializing Notebook ### What is this PR for? Sometimes Zeppelin wasn't able to start because of empty subject when initializing Notebook class, more details in issue. ### What type of PR is it? Bug Fix ### Todos * [x] - add anonymous subject * [x] - add test ### What is the Jira issue? [ZEPPELIN-1612](https://issues.apache.org/jira/browse/ZEPPELIN-1612) ### How should this be tested? * added test passing and no relevant CI failures * also can be starting Zeppelin in anonymous mode when you have notes with angular objects ### Screenshots (if appropriate) ### Questions: * Does the licenses files need update? no * Is there breaking changes for older versions? no * Does this needs documentation? no Author: Khalid Huseynov <[email protected]> Closes #1590 from khalidhuseynov/fix/loadAllNotes-npe and squashes the following commits: 0d21f78 [Khalid Huseynov] strict test passing condition 8da069b [Khalid Huseynov] add test 3dc0a8b [Khalid Huseynov] substitute null with anonymous subject Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/8dde8fb9 Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/8dde8fb9 Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/8dde8fb9 Branch: refs/heads/master Commit: 8dde8fb9af86eda91b7eb744e2c30630f8b4bf5d Parents: 2ea1ce5 Author: Khalid Huseynov <[email protected]> Authored: Thu Nov 3 23:45:03 2016 +0900 Committer: Alexander Bezzubov <[email protected]> Committed: Fri Nov 4 10:28:47 2016 +0900 ---------------------------------------------------------------------- .../org/apache/zeppelin/notebook/Notebook.java | 9 ++++--- .../apache/zeppelin/notebook/NotebookTest.java | 26 +++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/8dde8fb9/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java index 1b4b779..6f0f793 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java @@ -120,7 +120,8 @@ public class Notebook implements NoteEventListener { quartzSched.start(); CronJob.notebook = this; - loadAllNotes(); + AuthenticationInfo anonymous = AuthenticationInfo.ANONYMOUS; + loadAllNotes(anonymous); if (this.noteSearchService != null) { long start = System.nanoTime(); logger.info("Notebook indexing started..."); @@ -462,11 +463,11 @@ public class Notebook implements NoteEventListener { return note; } - private void loadAllNotes() throws IOException { - List<NoteInfo> noteInfos = notebookRepo.list(null); + void loadAllNotes(AuthenticationInfo subject) throws IOException { + List<NoteInfo> noteInfos = notebookRepo.list(subject); for (NoteInfo info : noteInfos) { - loadNoteFromRepo(info.getId(), null); + loadNoteFromRepo(info.getId(), subject); } } http://git-wip-us.apache.org/repos/asf/zeppelin/blob/8dde8fb9/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java ---------------------------------------------------------------------- diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java index abeda2e..3807bd0 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java @@ -65,7 +65,7 @@ public class NotebookTest implements JobListenerFactory{ private DependencyResolver depResolver; private NotebookAuthorization notebookAuthorization; private Credentials credentials; - private AuthenticationInfo anonymous = new AuthenticationInfo("anonymous"); + private AuthenticationInfo anonymous = AuthenticationInfo.ANONYMOUS; @Before public void setUp() throws Exception { @@ -197,6 +197,30 @@ public class NotebookTest implements JobListenerFactory{ } @Test + public void testLoadAllNotes() { + Note note; + try { + assertEquals(0, notebook.getAllNotes().size()); + note = notebook.createNote(anonymous); + Paragraph p1 = note.addParagraph(); + Map config = p1.getConfig(); + config.put("enabled", true); + p1.setConfig(config); + p1.setText("hello world"); + note.persist(anonymous); + } catch (IOException fe) { + logger.warn("Failed to create note and paragraph. Possible problem with persisting note, safe to ignore", fe); + } + + try { + notebook.loadAllNotes(anonymous); + assertEquals(1, notebook.getAllNotes().size()); + } catch (IOException e) { + fail("Subject is non-emtpy anonymous, shouldn't fail"); + } + } + + @Test public void testPersist() throws IOException, SchedulerException, RepositoryException { Note note = notebook.createNote(anonymous);
