You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by ah...@apache.org on 2017/02/27 11:45:29 UTC

zeppelin git commit: [ZEPPELIN-2114] adding reload endpoint

Repository: zeppelin
Updated Branches:
  refs/heads/master 8e1501a0d -> 897a6398d


[ZEPPELIN-2114] adding reload endpoint

### What is this PR for?
Adding endpoint in NotebookRepoRestApi to trigger reload and broadcast of the note list.
Sending a GET request to /api/notebook-repositories/reload will trigger a reload of the note list, just like the reload button does on the homepage.
Q: If you think this endpoint belongs to another API (NotebookRestApi?), let me know.

### What type of PR is it?
Improvement

### Todos

### What is the Jira issue?
<https://issues.apache.org/jira/browse/ZEPPELIN-2114>

### How should this be tested?
0. add (or remove) a note in the notebook repository
1. curl -X GET http://HOST:PORT/api/notebook-repository/reload
2. verify that you the note list in Zeppelin's home page now contains (or does not contain anymore) the note.

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? NO
* Is there breaking changes for older versions? NO
* Does this needs documentation? NotebookRepoRestApi does not have documentation yet. Could add it in another PR if needed.

Author: Remilito <re...@gmail.com>

Closes #2043 from Remilito/ZEPPELIN-2114 and squashes the following commits:

b1d741a [Remilito] adding log message for reload endpoint
cf66c2b [Remilito] [ZEPPELIN-2114] adding reload endpoint * ability to reload note list from repo by API


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

Branch: refs/heads/master
Commit: 897a6398d1ae3b532738f8c5943291b14fdcdd53
Parents: 8e1501a
Author: Remilito <re...@gmail.com>
Authored: Sun Feb 26 20:25:41 2017 +0100
Committer: ahyoungryu <ah...@apache.org>
Committed: Mon Feb 27 20:44:58 2017 +0900

----------------------------------------------------------------------
 .../org/apache/zeppelin/rest/NotebookRepoRestApi.java  | 13 +++++++++++++
 .../apache/zeppelin/rest/NotebookRepoRestApiTest.java  | 12 ++++++++++--
 2 files changed, 23 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/897a6398/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRepoRestApi.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRepoRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRepoRestApi.java
index 89cb47e..5a66334 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRepoRestApi.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRepoRestApi.java
@@ -76,6 +76,19 @@ public class NotebookRepoRestApi {
   }
 
   /**
+   * Reload notebook repository
+   */
+  @GET
+  @Path("reload")
+  @ZeppelinApi
+  public Response refreshRepo(){
+    AuthenticationInfo subject = new AuthenticationInfo(SecurityUtils.getPrincipal());
+    LOG.info("Reloading notebook repository for user {}", subject.getUser());
+    notebookWsServer.broadcastReloadedNoteList(subject, null);
+    return new JsonResponse<>(Status.OK, "", null).build();
+  }
+
+  /**
    * Update a specific note repo.
    *
    * @param message

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/897a6398/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java
index d221792..307339d 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRepoRestApiTest.java
@@ -18,6 +18,7 @@ package org.apache.zeppelin.rest;
 
 import static org.hamcrest.CoreMatchers.is;
 import static org.hamcrest.CoreMatchers.not;
+import static org.hamcrest.CoreMatchers.anyOf;
 import static org.junit.Assert.assertThat;
 
 import java.io.IOException;
@@ -80,6 +81,13 @@ public class NotebookRepoRestApiTest extends AbstractTestRestApi {
     List<Map<String, Object>> listOfRepositories = getListOfReposotiry();
     assertThat(listOfRepositories.size(), is(not(0)));
   }
+
+  @Test public void reloadRepositories() throws IOException {
+    GetMethod get = httpGet("/notebook-repositories/reload");
+    int status = get.getStatusCode();
+    get.releaseConnection();
+    assertThat(status, is(200)); 
+  }
   
   @Test public void setNewDirectoryForLocalDirectory() throws IOException {
     List<Map<String, Object>> listOfRepositories = getListOfReposotiry();
@@ -95,7 +103,7 @@ public class NotebookRepoRestApiTest extends AbstractTestRestApi {
     }
 
     if (StringUtils.isBlank(localVfs)) {
-      // no loval VFS set...
+      // no local VFS set...
       return;
     }
 
@@ -111,7 +119,7 @@ public class NotebookRepoRestApiTest extends AbstractTestRestApi {
         break;
       }
     }
-    assertThat(updatedPath, is("/tmp/newDir"));
+    assertThat(updatedPath, anyOf(is("/tmp/newDir"),is("/tmp/newDir/")));
     
     // go back to normal
     payload = "{ \"name\": \"" + className + "\", \"settings\" : { \"Notebook Path\" : \"" + localVfs + "\" } }";