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 2020/11/04 01:46:29 UTC
[zeppelin] branch branch-0.9 updated: [ZEPPELIN-5114]. Add api to
ZeppelinClient for import note
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 236b989 [ZEPPELIN-5114]. Add api to ZeppelinClient for import note
236b989 is described below
commit 236b989133545b0ebc1c53c7ab890c9fa38dddff
Author: Jeff Zhang <zj...@apache.org>
AuthorDate: Thu Oct 29 00:08:25 2020 +0800
[ZEPPELIN-5114]. Add api to ZeppelinClient for import note
### What is this PR for?
This PR just add api to ZeppelinClient for importing note. This api would return noteId if importing is successful, otherwise it would throw exception.
### What type of PR is it?
[Feature]
### Todos
* [ ] - Task
### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-5114
### How should this be tested?
* Unit test is added
https://travis-ci.org/github/zjffdu/zeppelin/builds/739823431
### 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 #3957 from zjffdu/ZEPPELIN-5114 and squashes the following commits:
2ef051f0a [Jeff Zhang] [ZEPPELIN-5114]. Add api to ZeppelinClient for import note
(cherry picked from commit dbd93781031bd3ef37191e4fc81398edf15c7851)
Signed-off-by: Jeff Zhang <zj...@apache.org>
---
.../org/apache/zeppelin/client/ZeppelinClient.java | 22 +++++++
.../integration/ZeppelinClientIntegrationTest.java | 34 ++++++++++
.../src/test/resources/Test_Note.zpln | 74 ++++++++++++++++++++++
.../apache/zeppelin/rest/AbstractTestRestApi.java | 2 +-
4 files changed, 131 insertions(+), 1 deletion(-)
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 bd26103..790575b 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
@@ -424,6 +424,28 @@ public class ZeppelinClient {
return queryNoteResult(noteId);
}
+
+ /**
+ * Import note with given note json content to the specified notePath.
+ *
+ * @param notePath
+ * @param noteContent
+ * @return
+ * @throws Exception
+ */
+ public String importNote(String notePath, String noteContent) throws Exception {
+ JSONObject bodyObject = new JSONObject(noteContent);
+ HttpResponse<JsonNode> response = Unirest
+ .post("/notebook/import")
+ .queryString("notePath", notePath)
+ .body(bodyObject)
+ .asJson();
+ checkResponse(response);
+ JsonNode jsonNode = response.getBody();
+ checkJsonNodeStatus(jsonNode);
+ return jsonNode.getObject().getString("body");
+ }
+
/**
* Block there until note execution is completed.
*
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 53164ed..0e8a3c5 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
@@ -17,6 +17,7 @@
package org.apache.zeppelin.integration;
+import org.apache.commons.io.IOUtils;
import org.apache.zeppelin.client.ClientConfig;
import org.apache.zeppelin.client.NoteResult;
import org.apache.zeppelin.client.ParagraphResult;
@@ -37,6 +38,7 @@ import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -73,6 +75,38 @@ public class ZeppelinClientIntegrationTest extends AbstractTestRestApi {
}
@Test
+ public void testImportNote() throws Exception {
+ String noteContent = IOUtils.toString(ZeppelinClientIntegrationTest.class.getResource("/Test_Note.zpln"));
+ String noteId = zeppelinClient.importNote("/imported_notes/note_1", noteContent);
+ assertNotNull("Import note failed because returned noteId is null", noteId);
+
+ NoteResult noteResult = zeppelinClient.queryNoteResult(noteId);
+ assertFalse(noteResult.isRunning());
+ assertEquals(2, noteResult.getParagraphResultList().size());
+ assertEquals(1, noteResult.getParagraphResultList().get(0).getResults().size());
+ assertEquals("TEXT", noteResult.getParagraphResultList().get(0).getResults().get(0).getType());
+ assertEquals("Hello World\n", noteResult.getParagraphResultList().get(0).getResults().get(0).getData());
+
+ // import to the same notePath again
+ try {
+ zeppelinClient.importNote("/imported_notes/note_1", noteContent);
+ fail("Should fail to import note to the same notePath");
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue(e.getMessage(), e.getMessage().contains("Note '/imported_notes/note_1' existed"));
+ }
+
+ // import invalid noteContent
+ try {
+ zeppelinClient.importNote("/imported_notes/note_1", "Invalid_content");
+ fail("Should fail to import note with invalid note content");
+ } catch (Exception e) {
+ e.printStackTrace();
+ assertTrue(e.getMessage(), e.getMessage().contains("Invalid JSON"));
+ }
+ }
+
+ @Test
public void testNoteOperation() throws Exception {
String noteId = zeppelinClient.createNote("/project_1/note1");
assertNotNull(notebook.getNote(noteId));
diff --git a/zeppelin-interpreter-integration/src/test/resources/Test_Note.zpln b/zeppelin-interpreter-integration/src/test/resources/Test_Note.zpln
new file mode 100644
index 0000000..3c3b9b8
--- /dev/null
+++ b/zeppelin-interpreter-integration/src/test/resources/Test_Note.zpln
@@ -0,0 +1,74 @@
+{
+ "paragraphs": [
+ {
+ "text": "%sh\n\necho \"Hello World\"",
+ "user": "anonymous",
+ "dateUpdated": "2020-10-28 23:01:23.128",
+ "progress": 0,
+ "config": {
+ "editorSetting": {
+ "language": "sh",
+ "editOnDblClick": false,
+ "completionKey": "TAB",
+ "completionSupport": false
+ },
+ "colWidth": 12.0,
+ "editorMode": "ace/mode/sh",
+ "fontSize": 9.0,
+ "results": {},
+ "enabled": true
+ },
+ "settings": {
+ "params": {},
+ "forms": {}
+ },
+ "results": {
+ "code": "SUCCESS",
+ "msg": [
+ {
+ "type": "TEXT",
+ "data": "Hello World\n"
+ }
+ ]
+ },
+ "apps": [],
+ "runtimeInfos": {},
+ "progressUpdateIntervalMs": 500,
+ "jobName": "paragraph_1603897273036_1773568653",
+ "id": "paragraph_1603897273036_1773568653",
+ "dateCreated": "2020-10-28 23:01:13.044",
+ "dateStarted": "2020-10-28 23:01:23.153",
+ "dateFinished": "2020-10-28 23:01:24.905",
+ "status": "FINISHED"
+ },
+ {
+ "text": "%sh\n",
+ "user": "anonymous",
+ "dateUpdated": "2020-10-28 23:01:23.148",
+ "progress": 0,
+ "config": {},
+ "settings": {
+ "params": {},
+ "forms": {}
+ },
+ "apps": [],
+ "runtimeInfos": {},
+ "progressUpdateIntervalMs": 500,
+ "jobName": "paragraph_1603897283147_268154041",
+ "id": "paragraph_1603897283147_268154041",
+ "dateCreated": "2020-10-28 23:01:23.147",
+ "status": "READY"
+ }
+ ],
+ "name": "Untitled Note 11",
+ "id": "2FQC5WHZG",
+ "defaultInterpreterGroup": "spark",
+ "version": "0.9.0-SNAPSHOT",
+ "noteParams": {},
+ "noteForms": {},
+ "angularObjects": {},
+ "config": {
+ "isZeppelinNotebookCronEnable": false
+ },
+ "info": {}
+}
\ No newline at end of file
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java
index 7fd279c..912183d 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/AbstractTestRestApi.java
@@ -180,7 +180,7 @@ public abstract class AbstractTestRestApi {
try {
TestUtils.clearInstances();
ZeppelinServer.main(new String[]{""});
- } catch (Exception e) {
+ } catch (Throwable e) {
LOG.error("Exception in WebDriverManager while getWebDriver ", e);
throw new RuntimeException(e);
}