Skip to content

Commit b7f19c9

Browse files
separate getAllNotes() and getAllNotes(subject)
1 parent 17e2d4c commit b7f19c9

File tree

3 files changed

+35
-29
lines changed

3 files changed

+35
-29
lines changed

zeppelin-server/src/main/java/org/apache/zeppelin/socket/NotebookServer.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,7 @@ private String getOpenNoteId(NotebookSocket socket) {
332332
private void broadcastToNoteBindedInterpreter(String interpreterGroupId,
333333
Message m) {
334334
Notebook notebook = notebook();
335-
//TODO(khalid): anonymous or specific user notes?
336-
AuthenticationInfo subject = new AuthenticationInfo("anonymous");
337-
List<Note> notes = notebook.getAllNotes(subject);
335+
List<Note> notes = notebook.getAllNotes();
338336
for (Note note : notes) {
339337
List<String> ids = notebook.getInterpreterFactory().getInterpreters(note.getId());
340338
for (String id : ids) {
@@ -859,9 +857,7 @@ private void angularObjectUpdated(NotebookSocket conn, HashSet<String> userAndRo
859857

860858
if (global) { // broadcast change to all web session that uses related
861859
// interpreter.
862-
//TODO(khalid): anonymous or specific user notes?
863-
AuthenticationInfo subject = new AuthenticationInfo("anonymous");
864-
for (Note n : notebook.getAllNotes(subject)) {
860+
for (Note n : notebook.getAllNotes()) {
865861
List<InterpreterSetting> settings = notebook.getInterpreterFactory()
866862
.getInterpreterSettings(note.getId());
867863
for (InterpreterSetting setting : settings) {
@@ -1539,9 +1535,7 @@ public void onUpdate(String interpreterGroupId, AngularObject object) {
15391535
return;
15401536
}
15411537

1542-
//TODO(khalid): anonymous or specific user notes?
1543-
AuthenticationInfo subject = new AuthenticationInfo("anonymous");
1544-
List<Note> notes = notebook.getAllNotes(subject );
1538+
List<Note> notes = notebook.getAllNotes();
15451539
for (Note note : notes) {
15461540
if (object.getNoteId() != null && !note.getId().equals(object.getNoteId())) {
15471541
continue;
@@ -1566,9 +1560,7 @@ public void onUpdate(String interpreterGroupId, AngularObject object) {
15661560
@Override
15671561
public void onRemove(String interpreterGroupId, String name, String noteId, String paragraphId) {
15681562
Notebook notebook = notebook();
1569-
//TODO(khalid): anonymous or specific user notes?
1570-
AuthenticationInfo subject = new AuthenticationInfo("anonymous");
1571-
List<Note> notes = notebook.getAllNotes(subject);
1563+
List<Note> notes = notebook.getAllNotes();
15721564
for (Note note : notes) {
15731565
if (noteId != null && !note.getId().equals(noteId)) {
15741566
continue;

zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/Notebook.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,27 @@ Date getLastUpdate() {
578578
}
579579
}
580580

581+
public List<Note> getAllNotes() {
582+
synchronized (notes) {
583+
List<Note> noteList = new ArrayList<>(notes.values());
584+
Collections.sort(noteList, new Comparator<Note>() {
585+
@Override
586+
public int compare(Note note1, Note note2) {
587+
String name1 = note1.getId();
588+
if (note1.getName() != null) {
589+
name1 = note1.getName();
590+
}
591+
String name2 = note2.getId();
592+
if (note2.getName() != null) {
593+
name2 = note2.getName();
594+
}
595+
return name1.compareTo(name2);
596+
}
597+
});
598+
return noteList;
599+
}
600+
}
601+
581602
public List<Note> getAllNotes(AuthenticationInfo subject) {
582603
synchronized (notes) {
583604
List<Note> noteList = getAuthorizedNotes(subject);
@@ -760,7 +781,7 @@ public List<Map<String, Object>> getJobListByUnixTime(boolean needsReload,
760781
}
761782
}
762783

763-
List<Note> notes = getAllNotes(subject);
784+
List<Note> notes = getAllNotes();
764785
List<Map<String, Object>> notesInfo = new LinkedList<>();
765786
for (Note note : notes) {
766787
boolean isNotebookRunning = false;

zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/NotebookTest.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,12 @@ public void testReloadAndSetInterpreter() throws IOException {
135135
File destDir = new File(notebookDir.getAbsolutePath() + "/2A94M5J1Z");
136136
FileUtils.copyDirectory(srcDir, destDir);
137137

138-
//TODO(khalid): anonymous or specific user notes?
139-
AuthenticationInfo subject = new AuthenticationInfo("anonymous");
140-
141138
// when load
142139
notebook.reloadAllNotes(null);
143-
assertEquals(1, notebook.getAllNotes(subject).size());
140+
assertEquals(1, notebook.getAllNotes().size());
144141

145142
// then interpreter factory should be injected into all the paragraphs
146-
Note note = notebook.getAllNotes(subject).get(0);
143+
Note note = notebook.getAllNotes().get(0);
147144
assertNull(note.getParagraphs().get(0).getRepl(null));
148145
}
149146

@@ -166,17 +163,14 @@ public void testReloadAllNotes() throws IOException {
166163
logger.error(e.toString(), e);
167164
}
168165

169-
//TODO(khalid): anonymous or specific user notes?
170-
AuthenticationInfo subject = new AuthenticationInfo("anonymous");
171-
172166
// doesn't have copied notebook in memory before reloading
173-
List<Note> notes = notebook.getAllNotes(subject);
167+
List<Note> notes = notebook.getAllNotes();
174168
assertEquals(notes.size(), 0);
175169

176170
// load copied notebook on memory when reloadAllNotes() is called
177171
Note copiedNote = notebookRepo.get("2A94M5J1Z", null);
178172
notebook.reloadAllNotes(null);
179-
notes = notebook.getAllNotes(subject);
173+
notes = notebook.getAllNotes();
180174
assertEquals(notes.size(), 2);
181175
assertEquals(notes.get(1).getId(), copiedNote.getId());
182176
assertEquals(notes.get(1).getName(), copiedNote.getName());
@@ -189,12 +183,12 @@ public void testReloadAllNotes() throws IOException {
189183
}
190184

191185
// keep notebook in memory before reloading
192-
notes = notebook.getAllNotes(subject);
186+
notes = notebook.getAllNotes();
193187
assertEquals(notes.size(), 2);
194188

195189
// delete notebook from notebook list when reloadAllNotes() is called
196190
notebook.reloadAllNotes(null);
197-
notes = notebook.getAllNotes(subject);
191+
notes = notebook.getAllNotes();
198192
assertEquals(notes.size(), 0);
199193
}
200194

@@ -211,7 +205,7 @@ public void testReloadAuthorizedNotes() throws IOException {
211205
logger.info("Loaded {} notes", notes1.size());
212206

213207
Note note = notebook.createNote(user1);
214-
setNotePermissions(note.id(), user1.getUser(), true, true, true);
208+
setNotePermissions(note.getId(), user1.getUser(), true, true, true);
215209
notebook.reloadAllNotes(user1);
216210
notes1 = notebook.getAllNotes(user1);
217211
notebook.reloadAllNotes(user2);
@@ -250,9 +244,8 @@ public void testPersist() throws IOException, SchedulerException, RepositoryExce
250244
Notebook notebook2 = new Notebook(
251245
conf, notebookRepo, schedulerFactory,
252246
new InterpreterFactory(conf, null, null, null, depResolver), this, null, null, null);
253-
//TODO(khalid): anonymous or specific user notes?
254-
AuthenticationInfo subject = new AuthenticationInfo("anonymous");
255-
assertEquals(1, notebook2.getAllNotes(subject).size());
247+
248+
assertEquals(1, notebook2.getAllNotes().size());
256249
}
257250

258251
@Test

0 commit comments

Comments
 (0)