You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@zeppelin.apache.org by GitBox <gi...@apache.org> on 2022/01/26 14:15:21 UTC

[GitHub] [zeppelin] huage1994 opened a new pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

huage1994 opened a new pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292


   ### What is this PR for?
   Provide REST API and SDK to get noteId by notePath.
   
   
   ### What type of PR is it?
   [Feature]
   
   ### Todos
   * [ ] - Task
   
   ### What is the Jira issue?
   * Open an issue on Jira https://issues.apache.org/jira/browse/ZEPPELIN-5642
   
   ### How should this be tested?
   CI passed
   
   ### Screenshots (if appropriate)
   
   ### Questions:
   * Does the licenses files need update? No
   * Is there breaking changes for older versions? No
   * Does this needs documentation? No
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] huage1994 commented on a change in pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
huage1994 commented on a change in pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292#discussion_r793443837



##########
File path: zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
##########
@@ -120,6 +120,38 @@ public void testGetReloadNote() throws IOException {
       }
     }
   }
+  
+  @Test
+  public void testGetNoteByPath() throws IOException {

Review comment:
       > It's better to add a test for querying a not-existed note
   
   Thanks @zjffdu  for reviews.  have added test case for querying not-existed note
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] asfgit closed pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] huage1994 commented on a change in pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
huage1994 commented on a change in pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292#discussion_r793685047



##########
File path: zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
##########
@@ -120,6 +120,55 @@ public void testGetReloadNote() throws IOException {
       }
     }
   }
+  
+  @Test
+  public void testGetNoteByPath() throws IOException {
+    LOG.info("Running testGetNoteByPath");
+    String note1Id = null;
+    try {
+        String notePath = "dir1/note1";
+        note1Id = TestUtils.getInstance(Notebook.class).createNote(notePath, anonymous);
+        TestUtils.getInstance(Notebook.class).processNote(note1Id,
+                note1 -> {
+                    note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
+                    TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous);
+                    return null;
+                });
+
+        CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" );
+
+        assertThat(post, isAllowed());
+        Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8),
+                new TypeToken<Map<String, Object>>() {}.getType());
+        Map<String, Object> noteObject = (Map<String, Object>) resp.get("body");
+        assertEquals(notePath, ((String)noteObject.get("path")).substring(1));
+        post.close();
+    } catch (IOException e) {
+        e.printStackTrace();
+    } finally {
+        // cleanup
+        if (null != note1Id) {
+            TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
+        }
+    }
+  }
+
+  @Test
+  public void testGetNoteByPathWithPathNotExist() {
+    LOG.info("Running testGetNoteByPathWithPathNotExist");
+    try {
+        String notePath = "A note that doesn't exist";
+        CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" );
+        assertThat(post, isNotFound());
+        Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8),
+                new TypeToken<Map<String, Object>>() {}.getType());
+        String status = (String) resp.get("status");
+        assertEquals(status, "NOT_FOUND");
+        post.close();
+    } catch (IOException e) {
+        e.printStackTrace();

Review comment:
       > use Logger to log error instead of `e.printStackTrace()`
   
   I got it wrong.  I find it should throw the IOException here like the other test case.  And catch statement has been remove here.
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] zjffdu commented on a change in pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
zjffdu commented on a change in pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292#discussion_r792775676



##########
File path: zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
##########
@@ -120,6 +120,38 @@ public void testGetReloadNote() throws IOException {
       }
     }
   }
+  
+  @Test
+  public void testGetNoteByPath() throws IOException {

Review comment:
       It's better to add a test for querying a not-existed note




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] huage1994 commented on a change in pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
huage1994 commented on a change in pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292#discussion_r793685047



##########
File path: zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
##########
@@ -120,6 +120,55 @@ public void testGetReloadNote() throws IOException {
       }
     }
   }
+  
+  @Test
+  public void testGetNoteByPath() throws IOException {
+    LOG.info("Running testGetNoteByPath");
+    String note1Id = null;
+    try {
+        String notePath = "dir1/note1";
+        note1Id = TestUtils.getInstance(Notebook.class).createNote(notePath, anonymous);
+        TestUtils.getInstance(Notebook.class).processNote(note1Id,
+                note1 -> {
+                    note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
+                    TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous);
+                    return null;
+                });
+
+        CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" );
+
+        assertThat(post, isAllowed());
+        Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8),
+                new TypeToken<Map<String, Object>>() {}.getType());
+        Map<String, Object> noteObject = (Map<String, Object>) resp.get("body");
+        assertEquals(notePath, ((String)noteObject.get("path")).substring(1));
+        post.close();
+    } catch (IOException e) {
+        e.printStackTrace();
+    } finally {
+        // cleanup
+        if (null != note1Id) {
+            TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
+        }
+    }
+  }
+
+  @Test
+  public void testGetNoteByPathWithPathNotExist() {
+    LOG.info("Running testGetNoteByPathWithPathNotExist");
+    try {
+        String notePath = "A note that doesn't exist";
+        CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" );
+        assertThat(post, isNotFound());
+        Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8),
+                new TypeToken<Map<String, Object>>() {}.getType());
+        String status = (String) resp.get("status");
+        assertEquals(status, "NOT_FOUND");
+        post.close();
+    } catch (IOException e) {
+        e.printStackTrace();

Review comment:
       > use Logger to log error instead of `e.printStackTrace()`
   
   I got it wrong.  I find it should throw the IOException here like the other test case. 
   
   And catch statement has been remove here.
   
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] zjffdu commented on pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
zjffdu commented on pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292#issuecomment-1032138163


   LGTM


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] zjffdu commented on a change in pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
zjffdu commented on a change in pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292#discussion_r792769624



##########
File path: zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java
##########
@@ -417,6 +417,11 @@ private boolean isNotePathAvailable(String notePath) {
     return true;
   }
 
+  public synchronized String getNoteIdByPath(String notePath) throws IOException {

Review comment:
       why add `synchronized`?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] zjffdu commented on a change in pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
zjffdu commented on a change in pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292#discussion_r793446311



##########
File path: zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
##########
@@ -120,6 +120,55 @@ public void testGetReloadNote() throws IOException {
       }
     }
   }
+  
+  @Test
+  public void testGetNoteByPath() throws IOException {
+    LOG.info("Running testGetNoteByPath");
+    String note1Id = null;
+    try {
+        String notePath = "dir1/note1";
+        note1Id = TestUtils.getInstance(Notebook.class).createNote(notePath, anonymous);
+        TestUtils.getInstance(Notebook.class).processNote(note1Id,
+                note1 -> {
+                    note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
+                    TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous);
+                    return null;
+                });
+
+        CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" );
+
+        assertThat(post, isAllowed());
+        Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8),
+                new TypeToken<Map<String, Object>>() {}.getType());
+        Map<String, Object> noteObject = (Map<String, Object>) resp.get("body");
+        assertEquals(notePath, ((String)noteObject.get("path")).substring(1));
+        post.close();
+    } catch (IOException e) {
+        e.printStackTrace();
+    } finally {
+        // cleanup
+        if (null != note1Id) {
+            TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
+        }
+    }
+  }
+
+  @Test
+  public void testGetNoteByPathWithPathNotExist() {
+    LOG.info("Running testGetNoteByPathWithPathNotExist");
+    try {
+        String notePath = "A note that doesn't exist";
+        CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" );
+        assertThat(post, isNotFound());
+        Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8),
+                new TypeToken<Map<String, Object>>() {}.getType());
+        String status = (String) resp.get("status");
+        assertEquals(status, "NOT_FOUND");
+        post.close();
+    } catch (IOException e) {
+        e.printStackTrace();

Review comment:
       use Logger to log error instead of `e.pringStackTrace()`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] zjffdu commented on a change in pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
zjffdu commented on a change in pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292#discussion_r793446311



##########
File path: zeppelin-server/src/test/java/org/apache/zeppelin/rest/NotebookRestApiTest.java
##########
@@ -120,6 +120,55 @@ public void testGetReloadNote() throws IOException {
       }
     }
   }
+  
+  @Test
+  public void testGetNoteByPath() throws IOException {
+    LOG.info("Running testGetNoteByPath");
+    String note1Id = null;
+    try {
+        String notePath = "dir1/note1";
+        note1Id = TestUtils.getInstance(Notebook.class).createNote(notePath, anonymous);
+        TestUtils.getInstance(Notebook.class).processNote(note1Id,
+                note1 -> {
+                    note1.addNewParagraph(AuthenticationInfo.ANONYMOUS);
+                    TestUtils.getInstance(Notebook.class).saveNote(note1, anonymous);
+                    return null;
+                });
+
+        CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" );
+
+        assertThat(post, isAllowed());
+        Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8),
+                new TypeToken<Map<String, Object>>() {}.getType());
+        Map<String, Object> noteObject = (Map<String, Object>) resp.get("body");
+        assertEquals(notePath, ((String)noteObject.get("path")).substring(1));
+        post.close();
+    } catch (IOException e) {
+        e.printStackTrace();
+    } finally {
+        // cleanup
+        if (null != note1Id) {
+            TestUtils.getInstance(Notebook.class).removeNote(note1Id, anonymous);
+        }
+    }
+  }
+
+  @Test
+  public void testGetNoteByPathWithPathNotExist() {
+    LOG.info("Running testGetNoteByPathWithPathNotExist");
+    try {
+        String notePath = "A note that doesn't exist";
+        CloseableHttpResponse post = httpPost("/notebook/getByPath" , "{\"notePath\":\""+ notePath + "\"}" );
+        assertThat(post, isNotFound());
+        Map<String, Object> resp = gson.fromJson(EntityUtils.toString(post.getEntity(), StandardCharsets.UTF_8),
+                new TypeToken<Map<String, Object>>() {}.getType());
+        String status = (String) resp.get("status");
+        assertEquals(status, "NOT_FOUND");
+        post.close();
+    } catch (IOException e) {
+        e.printStackTrace();

Review comment:
       use Logger to log error instead of `e.printStackTrace()`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [zeppelin] huage1994 commented on a change in pull request #4292: [ZEPPELIN-5642] Provide REST API and SDK to get noteId by notePath

Posted by GitBox <gi...@apache.org>.
huage1994 commented on a change in pull request #4292:
URL: https://github.com/apache/zeppelin/pull/4292#discussion_r793444352



##########
File path: zeppelin-zengine/src/main/java/org/apache/zeppelin/notebook/NoteManager.java
##########
@@ -417,6 +417,11 @@ private boolean isNotePathAvailable(String notePath) {
     return true;
   }
 
+  public synchronized String getNoteIdByPath(String notePath) throws IOException {

Review comment:
       > why add `synchronized`?
   
   Thanks @zjffdu  for reviews.  it's been removed.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscribe@zeppelin.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org