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/02/08 11:53:18 UTC

[zeppelin] branch branch-0.9 updated: [ZEPPELIN-5159]. Add api to clone note in ZeppelinClient

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 92112be  [ZEPPELIN-5159]. Add api to clone note in ZeppelinClient
92112be is described below

commit 92112beea1b146a64a72511090f9f4419328052d
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Fri Dec 11 11:20:38 2020 +0800

    [ZEPPELIN-5159]. Add api to clone note in ZeppelinClient
    
    ### What is this PR for?
    
    Add one simple api for clone note.  Besides that, also fix a bug in cloneNote, we should use deep copy instead of shallow copy.
    
    ### What type of PR is it?
    [Improvement ]
    
    ### Todos
    * [ ] - Task
    
    ### What is the Jira issue?
    * https://issues.apache.org/jira/browse/ZEPPELIN-5159
    
    ### How should this be tested?
    * CI 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: Jeff Zhang <zj...@apache.org>
    
    Closes #4036 from zjffdu/ZEPPELIN-5159 and squashes the following commits:
    
    2b53b639a [Jeff Zhang] [ZEPPELIN-5159]. Add api to clone note in ZeppelinClient
    
    (cherry picked from commit b3f1c9ef79f654174c2448d5846fd64155574259)
    Signed-off-by: Jeff Zhang <zj...@apache.org>
---
 .../org/apache/zeppelin/client/ZeppelinClient.java | 23 ++++++++++++++++++++++
 .../integration/ZeppelinClientIntegrationTest.java | 17 ++++++++++++++++
 .../org/apache/zeppelin/notebook/Notebook.java     |  8 ++++++++
 3 files changed, 48 insertions(+)

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 0605e09..75d00f3 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
@@ -331,6 +331,29 @@ public class ZeppelinClient {
   }
 
   /**
+   * Clone a note to a specified notePath.
+   *
+   * @param noteId
+   * @param destPath
+   * @return
+   * @throws Exception
+   */
+  public String cloneNote(String noteId, String destPath) throws Exception {
+    JSONObject bodyObject = new JSONObject();
+    bodyObject.put("name", destPath);
+    HttpResponse<JsonNode> response = Unirest
+            .post("/notebook/{noteId}")
+            .routeParam("noteId", noteId)
+            .body(bodyObject.toString())
+            .asJson();
+    checkResponse(response);
+    JsonNode jsonNode = response.getBody();
+    checkJsonNodeStatus(jsonNode);
+
+    return jsonNode.getObject().getString("body");
+  }
+
+  /**
    * Query {@link NoteResult} with provided noteId.
    *
    * @param noteId
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 96ff276..bf5801c 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
@@ -27,6 +27,7 @@ import org.apache.zeppelin.client.ZeppelinClient;
 
 import org.apache.zeppelin.conf.ZeppelinConfiguration;
 import org.apache.zeppelin.common.SessionInfo;
+import org.apache.zeppelin.notebook.Note;
 import org.apache.zeppelin.notebook.Notebook;
 import org.apache.zeppelin.rest.AbstractTestRestApi;
 import org.apache.zeppelin.utils.TestUtils;
@@ -146,6 +147,22 @@ public class ZeppelinClientIntegrationTest extends AbstractTestRestApi {
   }
 
   @Test
+  public void testCloneNote() throws Exception {
+    String noteId = zeppelinClient.createNote("/clone_note_test/note1");
+    Note note1 = notebook.getNote(noteId);
+    assertNotNull(note1);
+
+    zeppelinClient.addParagraph(noteId, "title_1", "text_1");
+    assertEquals(1, note1.getParagraphCount());
+
+    String clonedNoteId = zeppelinClient.cloneNote(noteId, "/clone_note_test/cloned_note1");
+    Note clonedNote = notebook.getNote(clonedNoteId);
+    assertEquals(1, clonedNote.getParagraphCount());
+    assertEquals("title_1", clonedNote.getParagraph(0).getTitle());
+    assertEquals("text_1", clonedNote.getParagraph(0).getText());
+  }
+
+  @Test
   public void testExecuteParagraph() throws Exception {
     // run paragraph succeed
     String noteId = zeppelinClient.createNote("/test/note_1");
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 16170c1..70f9dad 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
@@ -325,6 +325,14 @@ public class Notebook {
     for (Paragraph p : paragraphs) {
       newNote.addCloneParagraph(p, subject);
     }
+
+    newNote.setConfig(new HashMap<>(sourceNote.getConfig()));
+    newNote.setInfo(new HashMap<>(sourceNote.getInfo()));
+    newNote.setDefaultInterpreterGroup(sourceNote.getDefaultInterpreterGroup());
+    newNote.setNoteForms(new HashMap<>(sourceNote.getNoteForms()));
+    newNote.setNoteParams(new HashMap<>(sourceNote.getNoteParams()));
+    newNote.setRunning(false);
+
     saveNote(newNote, subject);
     authorizationService.cloneNoteMeta(newNote.getId(), sourceNoteId, subject);
     return newNote;