You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2021/03/04 15:22:07 UTC
[zeppelin] branch branch-0.9 updated: [ZEPPELIN-5262] Add feature
'rename note' for Zeppelin Client
This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch branch-0.9
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/branch-0.9 by this push:
new ebcc361 [ZEPPELIN-5262] Add feature 'rename note' for Zeppelin Client
ebcc361 is described below
commit ebcc3613a8cdc250b6853617d019abf1d2ccd19e
Author: Bowen0729 <bo...@qq.com>
AuthorDate: Sun Feb 28 21:47:46 2021 +0800
[ZEPPELIN-5262] Add feature 'rename note' for Zeppelin Client
### What is this PR for?
Add a feature "rename note" for Zeppelin Client,
### What type of PR is it?
Improvement
### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-5262
### How should this be tested?
CI
### Questions:
* Does the licenses files need update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Author: Bowen0729 <bo...@qq.com>
Closes #4061 from Bowen0729/master and squashes the following commits:
7380f0910 [Bowen0729] [ZEPPELIN-5262] Add feature 'rename note' for Zeppelin Client
(cherry picked from commit 35dd87ec9b0607307e09ff4b4f203341d868493b)
Signed-off-by: Jeff Zhang <zj...@apache.org>
---
.../client/examples/ZeppelinClientExample.java | 6 ++++++
.../org/apache/zeppelin/client/NoteResult.java | 8 +++++++-
.../org/apache/zeppelin/client/ZeppelinClient.java | 22 +++++++++++++++++++++-
.../integration/ZeppelinClientIntegrationTest.java | 17 +++++++++++++++++
4 files changed, 51 insertions(+), 2 deletions(-)
diff --git a/zeppelin-client-examples/src/main/java/org/apache/zeppelin/client/examples/ZeppelinClientExample.java b/zeppelin-client-examples/src/main/java/org/apache/zeppelin/client/examples/ZeppelinClientExample.java
index 6dbae58..7254568 100644
--- a/zeppelin-client-examples/src/main/java/org/apache/zeppelin/client/examples/ZeppelinClientExample.java
+++ b/zeppelin-client-examples/src/main/java/org/apache/zeppelin/client/examples/ZeppelinClientExample.java
@@ -41,6 +41,12 @@ public class ZeppelinClientExample {
noteId = zClient.createNote(notePath);
System.out.println("Created note: " + noteId);
+ String newNotePath = notePath + "_rename";
+ zClient.renameNote(noteId, newNotePath);
+
+ NoteResult renamedNoteResult = zClient.queryNoteResult(noteId);
+ System.out.println("Rename note: " + noteId + " name to " + renamedNoteResult.getNotePath());
+
String paragraphId = zClient.addParagraph(noteId, "the first paragraph", "%python print('hello world')");
ParagraphResult paragraphResult = zClient.executeParagraph(noteId, paragraphId);
System.out.println("Added new paragraph and execute it.");
diff --git a/zeppelin-client/src/main/java/org/apache/zeppelin/client/NoteResult.java b/zeppelin-client/src/main/java/org/apache/zeppelin/client/NoteResult.java
index b0cde11..8b469a0 100644
--- a/zeppelin-client/src/main/java/org/apache/zeppelin/client/NoteResult.java
+++ b/zeppelin-client/src/main/java/org/apache/zeppelin/client/NoteResult.java
@@ -25,11 +25,13 @@ import java.util.List;
*/
public class NoteResult {
private String noteId;
+ private String notePath;
private boolean isRunning;
private List<ParagraphResult> paragraphResultList;
- public NoteResult(String noteId, boolean isRunning, List<ParagraphResult> paragraphResultList) {
+ public NoteResult(String noteId, String notePath, boolean isRunning, List<ParagraphResult> paragraphResultList) {
this.noteId = noteId;
+ this.notePath = notePath;
this.isRunning = isRunning;
this.paragraphResultList = paragraphResultList;
}
@@ -38,6 +40,10 @@ public class NoteResult {
return noteId;
}
+ public String getNotePath() {
+ return notePath;
+ }
+
public boolean isRunning() {
return isRunning;
}
diff --git a/zeppelin-client/src/main/java/org/apache/zeppelin/client/ZeppelinClient.java b/zeppelin-client/src/main/java/org/apache/zeppelin/client/ZeppelinClient.java
index 75d00f3..32553f1 100644
--- a/zeppelin-client/src/main/java/org/apache/zeppelin/client/ZeppelinClient.java
+++ b/zeppelin-client/src/main/java/org/apache/zeppelin/client/ZeppelinClient.java
@@ -353,6 +353,21 @@ public class ZeppelinClient {
return jsonNode.getObject().getString("body");
}
+ public void renameNote(String noteId, String newNotePath) throws Exception {
+ JSONObject bodyObject = new JSONObject();
+ bodyObject.put("name", newNotePath);
+
+ HttpResponse<JsonNode> response = Unirest
+ .put("/notebook/{noteId}/rename")
+ .routeParam("noteId", noteId)
+ .body(bodyObject.toString())
+ .asJson();
+
+ checkResponse(response);
+ JsonNode jsonNode = response.getBody();
+ checkJsonNodeStatus(jsonNode);
+ }
+
/**
* Query {@link NoteResult} with provided noteId.
*
@@ -378,6 +393,11 @@ public class ZeppelinClient {
}
}
+ String notePath = null;
+ if (noteJsonObject.has("path")) {
+ notePath = noteJsonObject.getString("path");
+ }
+
List<ParagraphResult> paragraphResultList = new ArrayList<>();
if (noteJsonObject.has("paragraphs")) {
JSONArray paragraphJsonArray = noteJsonObject.getJSONArray("paragraphs");
@@ -386,7 +406,7 @@ public class ZeppelinClient {
}
}
- return new NoteResult(noteId, isRunning, paragraphResultList);
+ return new NoteResult(noteId, notePath, isRunning, paragraphResultList);
}
/**
diff --git a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinClientIntegrationTest.java b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinClientIntegrationTest.java
index bf5801c..1ac1106 100644
--- a/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinClientIntegrationTest.java
+++ b/zeppelin-interpreter-integration/src/test/java/org/apache/zeppelin/integration/ZeppelinClientIntegrationTest.java
@@ -163,6 +163,23 @@ public class ZeppelinClientIntegrationTest extends AbstractTestRestApi {
}
@Test
+ public void testRenameNote() throws Exception {
+ String noteId = zeppelinClient.createNote("/rename_note_test/note1");
+ Note note1 = notebook.getNote(noteId);
+ assertNotNull(note1);
+
+ zeppelinClient.addParagraph(noteId, "title_1", "text_1");
+ assertEquals(1, note1.getParagraphCount());
+
+ zeppelinClient.renameNote(noteId, "/rename_note_test/note1_renamed");
+ Note renamedNote = notebook.getNote(noteId);
+ assertEquals("/rename_note_test/note1_renamed", renamedNote.getPath());
+ assertEquals(1, renamedNote.getParagraphCount());
+ assertEquals("title_1", renamedNote.getParagraph(0).getTitle());
+ assertEquals("text_1", renamedNote.getParagraph(0).getText());
+ }
+
+ @Test
public void testExecuteParagraph() throws Exception {
// run paragraph succeed
String noteId = zeppelinClient.createNote("/test/note_1");