Skip to content

Commit 6419070

Browse files
khalidhuseynovLeemoonsoo
authored andcommitted
[ZEPPELIN-1426] User aware storage sync
### What is this PR for? This is to make storage layer sync function aware of the user ### What type of PR is it? Improvement ### Todos * [x] - change function and test ### What is the Jira issue? [ZEPPELIN-1426](https://issues.apache.org/jira/browse/ZEPPELIN-1426) ### How should this be tested? corresponding storage layer tests should pass ### 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 #1424 from khalidhuseynov/storage/sync-with-subject and squashes the following commits: 7cc8455 [Khalid Huseynov] propagate subject to sync()
1 parent 294eef1 commit 6419070

File tree

3 files changed

+17
-15
lines changed

3 files changed

+17
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ public void reloadAllNotes(AuthenticationInfo subject) throws IOException {
476476
if (notebookRepo instanceof NotebookRepoSync) {
477477
NotebookRepoSync mainRepo = (NotebookRepoSync) notebookRepo;
478478
if (mainRepo.getRepoCount() > 1) {
479-
mainRepo.sync();
479+
mainRepo.sync(subject);
480480
}
481481
}
482482

zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public NotebookRepoSync(ZeppelinConfiguration conf) {
9393
}
9494
if (getRepoCount() > 1) {
9595
try {
96-
sync(0, 1);
96+
AuthenticationInfo subject = new AuthenticationInfo("anonymous");
97+
sync(0, 1, subject);
9798
} catch (IOException e) {
9899
LOG.warn("Failed to sync with secondary storage on start {}", e);
99100
}
@@ -175,12 +176,12 @@ public void remove(String noteId, AuthenticationInfo subject) throws IOException
175176
*
176177
* @throws IOException
177178
*/
178-
void sync(int sourceRepoIndex, int destRepoIndex) throws IOException {
179+
void sync(int sourceRepoIndex, int destRepoIndex, AuthenticationInfo subject) throws IOException {
179180
LOG.info("Sync started");
180181
NotebookRepo srcRepo = getRepo(sourceRepoIndex);
181182
NotebookRepo dstRepo = getRepo(destRepoIndex);
182-
List <NoteInfo> srcNotes = srcRepo.list(null);
183-
List <NoteInfo> dstNotes = dstRepo.list(null);
183+
List <NoteInfo> srcNotes = srcRepo.list(subject);
184+
List <NoteInfo> dstNotes = dstRepo.list(subject);
184185

185186
Map<String, List<String>> noteIDs = notesCheckDiff(srcNotes, srcRepo, dstNotes, dstRepo);
186187
List<String> pushNoteIDs = noteIDs.get(pushKey);
@@ -192,7 +193,7 @@ void sync(int sourceRepoIndex, int destRepoIndex) throws IOException {
192193
for (String id : pushNoteIDs) {
193194
LOG.info("ID : " + id);
194195
}
195-
pushNotes(pushNoteIDs, srcRepo, dstRepo);
196+
pushNotes(subject, pushNoteIDs, srcRepo, dstRepo);
196197
} else {
197198
LOG.info("Nothing to push");
198199
}
@@ -202,7 +203,7 @@ void sync(int sourceRepoIndex, int destRepoIndex) throws IOException {
202203
for (String id : pullNoteIDs) {
203204
LOG.info("ID : " + id);
204205
}
205-
pushNotes(pullNoteIDs, dstRepo, srcRepo);
206+
pushNotes(subject, pullNoteIDs, dstRepo, srcRepo);
206207
} else {
207208
LOG.info("Nothing to pull");
208209
}
@@ -212,28 +213,29 @@ void sync(int sourceRepoIndex, int destRepoIndex) throws IOException {
212213
for (String id : delDstNoteIDs) {
213214
LOG.info("ID : " + id);
214215
}
215-
deleteNotes(delDstNoteIDs, dstRepo);
216+
deleteNotes(subject, delDstNoteIDs, dstRepo);
216217
} else {
217218
LOG.info("Nothing to delete from dest");
218219
}
219220

220221
LOG.info("Sync ended");
221222
}
222223

223-
public void sync() throws IOException {
224-
sync(0, 1);
224+
public void sync(AuthenticationInfo subject) throws IOException {
225+
sync(0, 1, subject);
225226
}
226227

227-
private void pushNotes(List<String> ids, NotebookRepo localRepo,
228+
private void pushNotes(AuthenticationInfo subject, List<String> ids, NotebookRepo localRepo,
228229
NotebookRepo remoteRepo) throws IOException {
229230
for (String id : ids) {
230-
remoteRepo.save(localRepo.get(id, null), null);
231+
remoteRepo.save(localRepo.get(id, subject), subject);
231232
}
232233
}
233234

234-
private void deleteNotes(List<String> ids, NotebookRepo repo) throws IOException {
235+
private void deleteNotes(AuthenticationInfo subject, List<String> ids, NotebookRepo repo)
236+
throws IOException {
235237
for (String id : ids) {
236-
repo.remove(id, null);
238+
repo.remove(id, subject);
237239
}
238240
}
239241

zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public void testSyncUpdateMain() throws IOException {
185185
assertEquals(0, notebookRepoSync.get(1,
186186
notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size());
187187
/* apply sync */
188-
notebookRepoSync.sync();
188+
notebookRepoSync.sync(null);
189189
/* check whether added to second storage */
190190
assertEquals(1, notebookRepoSync.get(1,
191191
notebookRepoSync.list(1, null).get(0).getId(), null).getParagraphs().size());

0 commit comments

Comments
 (0)