You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2016/09/15 23:14:46 UTC

zeppelin git commit: [ZEPPELIN-1426] User aware storage sync

Repository: zeppelin
Updated Branches:
  refs/heads/master 294eef132 -> 64190707f


[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 <kh...@gmail.com>

Closes #1424 from khalidhuseynov/storage/sync-with-subject and squashes the following commits:

7cc8455 [Khalid Huseynov] propagate subject to sync()


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/64190707
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/64190707
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/64190707

Branch: refs/heads/master
Commit: 64190707f7ba1458e77fcf83a1b1e8004efa48ad
Parents: 294eef1
Author: Khalid Huseynov <kh...@gmail.com>
Authored: Mon Sep 12 14:41:01 2016 +0900
Committer: Lee moon soo <mo...@apache.org>
Committed: Thu Sep 15 16:14:42 2016 -0700

----------------------------------------------------------------------
 .../org/apache/zeppelin/notebook/Notebook.java  |  2 +-
 .../notebook/repo/NotebookRepoSync.java         | 28 +++++++++++---------
 .../notebook/repo/NotebookRepoSyncTest.java     |  2 +-
 3 files changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/64190707/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 cb39197..4449223 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
@@ -476,7 +476,7 @@ public class Notebook implements NoteEventListener {
     if (notebookRepo instanceof NotebookRepoSync) {
       NotebookRepoSync mainRepo = (NotebookRepoSync) notebookRepo;
       if (mainRepo.getRepoCount() > 1) {
-        mainRepo.sync();
+        mainRepo.sync(subject);
       }
     }
 

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/64190707/zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/repo/NotebookRepoSync.java
----------------------------------------------------------------------
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 7208726..f67b71f 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 class NotebookRepoSync implements NotebookRepo {
     }
     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 class NotebookRepoSync implements NotebookRepo {
    *
    * @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 <NoteInfo> srcNotes = srcRepo.list(null);
-    List <NoteInfo> dstNotes = dstRepo.list(null);
+    List <NoteInfo> srcNotes = srcRepo.list(subject);
+    List <NoteInfo> dstNotes = dstRepo.list(subject);
 
     Map<String, List<String>> noteIDs = notesCheckDiff(srcNotes, srcRepo, dstNotes, dstRepo);
     List<String> pushNoteIDs = noteIDs.get(pushKey);
@@ -192,7 +193,7 @@ public class NotebookRepoSync implements NotebookRepo {
       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 @@ public class NotebookRepoSync implements NotebookRepo {
       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 @@ public class NotebookRepoSync implements NotebookRepo {
       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 @@ public class NotebookRepoSync implements NotebookRepo {
     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<String> ids, NotebookRepo localRepo,
+  private void pushNotes(AuthenticationInfo subject, List<String> 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<String> ids, NotebookRepo repo) throws IOException {
+  private void deleteNotes(AuthenticationInfo subject, List<String> ids, NotebookRepo repo)
+      throws IOException {
     for (String id : ids) {
-      repo.remove(id, null);
+      repo.remove(id, subject);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/64190707/zeppelin-zengine/src/test/java/org/apache/zeppelin/notebook/repo/NotebookRepoSyncTest.java
----------------------------------------------------------------------
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 bd13120..c768df8 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 class NotebookRepoSyncTest implements JobListenerFactory {
     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());