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 ae448e3947f..335e524a16d 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 @@ -469,7 +469,7 @@ public void reloadAllNotes(AuthenticationInfo subject) throws IOException { if (notebookRepo instanceof NotebookRepoSync) { NotebookRepoSync mainRepo = (NotebookRepoSync) notebookRepo; if (mainRepo.getRepoCount() > 1) { - mainRepo.sync(); + mainRepo.sync(subject); } } diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java index 72087262aca..f67b71f5d6c 100644 --- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java +++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java @@ -93,7 +93,8 @@ public NotebookRepoSync(ZeppelinConfiguration conf) { } if (getRepoCount() > 1) { try { - sync(0, 1); + AuthenticationInfo subject = new AuthenticationInfo("anonymous"); + sync(0, 1, subject); } catch (IOException e) { LOG.warn("Failed to sync with secondary storage on start {}", e); } @@ -175,12 +176,12 @@ public void remove(String noteId, AuthenticationInfo subject) throws IOException * * @throws IOException */ - void sync(int sourceRepoIndex, int destRepoIndex) throws IOException { + void sync(int sourceRepoIndex, int destRepoIndex, AuthenticationInfo subject) throws IOException { LOG.info("Sync started"); NotebookRepo srcRepo = getRepo(sourceRepoIndex); NotebookRepo dstRepo = getRepo(destRepoIndex); - List srcNotes = srcRepo.list(null); - List dstNotes = dstRepo.list(null); + List srcNotes = srcRepo.list(subject); + List dstNotes = dstRepo.list(subject); Map> noteIDs = notesCheckDiff(srcNotes, srcRepo, dstNotes, dstRepo); List pushNoteIDs = noteIDs.get(pushKey); @@ -192,7 +193,7 @@ void sync(int sourceRepoIndex, int destRepoIndex) throws IOException { for (String id : pushNoteIDs) { LOG.info("ID : " + id); } - pushNotes(pushNoteIDs, srcRepo, dstRepo); + pushNotes(subject, pushNoteIDs, srcRepo, dstRepo); } else { LOG.info("Nothing to push"); } @@ -202,7 +203,7 @@ void sync(int sourceRepoIndex, int destRepoIndex) throws IOException { for (String id : pullNoteIDs) { LOG.info("ID : " + id); } - pushNotes(pullNoteIDs, dstRepo, srcRepo); + pushNotes(subject, pullNoteIDs, dstRepo, srcRepo); } else { LOG.info("Nothing to pull"); } @@ -212,7 +213,7 @@ void sync(int sourceRepoIndex, int destRepoIndex) throws IOException { for (String id : delDstNoteIDs) { LOG.info("ID : " + id); } - deleteNotes(delDstNoteIDs, dstRepo); + deleteNotes(subject, delDstNoteIDs, dstRepo); } else { LOG.info("Nothing to delete from dest"); } @@ -220,20 +221,21 @@ void sync(int sourceRepoIndex, int destRepoIndex) throws IOException { LOG.info("Sync ended"); } - public void sync() throws IOException { - sync(0, 1); + public void sync(AuthenticationInfo subject) throws IOException { + sync(0, 1, subject); } - private void pushNotes(List ids, NotebookRepo localRepo, + private void pushNotes(AuthenticationInfo subject, List ids, NotebookRepo localRepo, NotebookRepo remoteRepo) throws IOException { for (String id : ids) { - remoteRepo.save(localRepo.get(id, null), null); + remoteRepo.save(localRepo.get(id, subject), subject); } } - private void deleteNotes(List ids, NotebookRepo repo) throws IOException { + private void deleteNotes(AuthenticationInfo subject, List ids, NotebookRepo repo) + throws IOException { for (String id : ids) { - repo.remove(id, null); + repo.remove(id, subject); } } diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java index bd13120a4a3..c768df80435 100644 --- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java +++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java @@ -185,7 +185,7 @@ public void testSyncUpdateMain() throws IOException { assertEquals(0, notebookRepoSync.get(1, notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size()); /* apply sync */ - notebookRepoSync.sync(); + notebookRepoSync.sync(null); /* check whether added to second storage */ assertEquals(1, notebookRepoSync.get(1, notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size());