You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2015/12/21 20:29:21 UTC
incubator-zeppelin git commit: ZEPPELIN-509 Introduce a new REST API:
get notebook information
Repository: incubator-zeppelin
Updated Branches:
refs/heads/master 9fec2598c -> 16e921b6a
ZEPPELIN-509 Introduce a new REST API: get notebook information
### What is this PR for?
To add a new feature - "get notebook information" via REST API.
### What type of PR is it?
Feature
### Todos
### Is there a relevant Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-509
### How should this be tested?
Just request ```http://<zeppelin host>:<zeppelin port>/api/notebook/<notebookId>```.
If it exists, response would be http status 200 with json body including paragraphs information.
If it doesn't exist, response would be http status 404.
### Screenshots (if appropriate)
### Questions:
* Does the licenses files need update? (No)
* Is there breaking changes for older versions? (No, it's a new feature.)
* Does this needs documentation? (Yes, I've addressed it.)
Author: Jungtaek Lim <ka...@gmail.com>
Closes #542 from HeartSaVioR/ZEPPELIN-509 and squashes the following commits:
91e5f6f [Jungtaek Lim] ZEPPELIN-509 reduce lines of json response of get notebook
f63c4fd [Jungtaek Lim] ZEPPELIN-509 Introduce a new REST API: get notebook information
Project: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/commit/16e921b6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/tree/16e921b6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/diff/16e921b6
Branch: refs/heads/master
Commit: 16e921b6ad3348fbb41c462abc946a068bd76c97
Parents: 9fec259
Author: Jungtaek Lim <ka...@gmail.com>
Authored: Fri Dec 18 05:50:15 2015 +0900
Committer: Lee moon soo <mo...@apache.org>
Committed: Tue Dec 22 04:30:52 2015 +0900
----------------------------------------------------------------------
docs/rest-api/rest-notebook.md | 104 ++++++++++++++++++-
.../apache/zeppelin/rest/NotebookRestApi.java | 11 ++
.../zeppelin/rest/ZeppelinRestApiTest.java | 34 ++++++
3 files changed, 148 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/16e921b6/docs/rest-api/rest-notebook.md
----------------------------------------------------------------------
diff --git a/docs/rest-api/rest-notebook.md b/docs/rest-api/rest-notebook.md
index 0739bcb..7393c5a 100644
--- a/docs/rest-api/rest-notebook.md
+++ b/docs/rest-api/rest-notebook.md
@@ -33,7 +33,7 @@ limitations under the License.
<br />
### Notebook REST API list
- Notebooks REST API supports the following operations: List, Create, Delete & Clone as detailed in the following table
+ Notebooks REST API supports the following operations: List, Create, Get, Delete, Clone, Run as detailed in the following table
<table class="table-configuration">
<col width="200">
@@ -124,6 +124,108 @@ limitations under the License.
<table class="table-configuration">
<col width="200">
<tr>
+ <th>Get notebook</th>
+ <th></th>
+ </tr>
+ <tr>
+ <td>Description</td>
+ <td>This ```GET``` method retrieves an existing notebook's information using the given id.
+ The body field of the returned JSON contain information about paragraphs in the notebook.
+ </td>
+ </tr>
+ <tr>
+ <td>URL</td>
+ <td>```http://[zeppelin-server]:[zeppelin-port]/api/notebook/[notebookId]```</td>
+ </tr>
+ <tr>
+ <td>Success code</td>
+ <td>200</td>
+ </tr>
+ <tr>
+ <td> Fail code</td>
+ <td> 500 </td>
+ </tr>
+ <tr>
+ <td> sample JSON response </td>
+ <td><pre>
+{
+ "status": "OK",
+ "message": "",
+ "body": {
+ "paragraphs": [
+ {
+ "text": "%sql \nselect age, count(1) value\nfrom bank \nwhere age < 30 \ngroup by age \norder by age",
+ "config": {
+ "colWidth": 4,
+ "graph": {
+ "mode": "multiBarChart",
+ "height": 300,
+ "optionOpen": false,
+ "keys": [
+ {
+ "name": "age",
+ "index": 0,
+ "aggr": "sum"
+ }
+ ],
+ "values": [
+ {
+ "name": "value",
+ "index": 1,
+ "aggr": "sum"
+ }
+ ],
+ "groups": [],
+ "scatter": {
+ "xAxis": {
+ "name": "age",
+ "index": 0,
+ "aggr": "sum"
+ },
+ "yAxis": {
+ "name": "value",
+ "index": 1,
+ "aggr": "sum"
+ }
+ }
+ }
+ },
+ "settings": {
+ "params": {},
+ "forms": {}
+ },
+ "jobName": "paragraph_1423500782552_-1439281894",
+ "id": "20150210-015302_1492795503",
+ "result": {
+ "code": "SUCCESS",
+ "type": "TABLE",
+ "msg": "age\tvalue\n19\t4\n20\t3\n21\t7\n22\t9\n23\t20\n24\t24\n25\t44\n26\t77\n27\t94\n28\t103\n29\t97\n"
+ },
+ "dateCreated": "Feb 10, 2015 1:53:02 AM",
+ "dateStarted": "Jul 3, 2015 1:43:17 PM",
+ "dateFinished": "Jul 3, 2015 1:43:23 PM",
+ "status": "FINISHED",
+ "progressUpdateIntervalMs": 500
+ }
+ ],
+ "name": "Zeppelin Tutorial",
+ "id": "2A94M5J1Z",
+ "angularObjects": {},
+ "config": {
+ "looknfeel": "default"
+ },
+ "info": {}
+ }
+}
+ </pre></td>
+ </tr>
+ </table>
+
+<br/>
+
+ <table class="table-configuration">
+ <col width="200">
+ <tr>
<th>Delete notebook</th>
<th></th>
</tr>
http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/16e921b6/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
index 29c5c29..d9e7cf7 100644
--- a/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
+++ b/zeppelin-server/src/main/java/org/apache/zeppelin/rest/NotebookRestApi.java
@@ -124,6 +124,17 @@ public class NotebookRestApi {
return new JsonResponse(Status.OK, "", notesInfo ).build();
}
+ @GET
+ @Path("{notebookId}")
+ public Response getNotebook(@PathParam("notebookId") String notebookId) throws IOException {
+ Note note = notebook.getNote(notebookId);
+ if (note == null) {
+ return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
+ }
+
+ return new JsonResponse(Status.OK, "", note).build();
+ }
+
/**
* Create new note REST API
* @param message - JSON with new note name
http://git-wip-us.apache.org/repos/asf/incubator-zeppelin/blob/16e921b6/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java
----------------------------------------------------------------------
diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java
index cee36b4..caac5a0 100644
--- a/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java
+++ b/zeppelin-server/src/test/java/org/apache/zeppelin/rest/ZeppelinRestApiTest.java
@@ -34,6 +34,7 @@ import org.apache.zeppelin.notebook.Note;
import org.apache.zeppelin.notebook.Paragraph;
import org.apache.zeppelin.rest.message.NewParagraphRequest;
import org.apache.zeppelin.scheduler.Job.Status;
+import org.apache.zeppelin.server.JsonResponse;
import org.apache.zeppelin.server.ZeppelinServer;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -194,6 +195,39 @@ public class ZeppelinRestApiTest extends AbstractTestRestApi {
}
@Test
+ public void testGetNotebookInfo() throws IOException {
+ LOG.info("testGetNotebookInfo");
+ // Create note to get info
+ Note note = ZeppelinServer.notebook.createNote();
+ assertNotNull("can't create new note", note);
+ note.setName("note");
+ Paragraph paragraph = note.addParagraph();
+ Map config = paragraph.getConfig();
+ config.put("enabled", true);
+ paragraph.setConfig(config);
+ String paragraphText = "%md This is my new paragraph in my new note";
+ paragraph.setText(paragraphText);
+ note.persist();
+
+ String sourceNoteID = note.getId();
+ GetMethod get = httpGet("/notebook/" + sourceNoteID);
+ LOG.info("testGetNotebookInfo \n" + get.getResponseBodyAsString());
+ assertThat("test notebook get method:", get, isAllowed());
+
+ Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {
+ }.getType());
+
+ assertNotNull(resp);
+ assertEquals("OK", resp.get("status"));
+
+ Map<String, Object> body = (Map<String, Object>) resp.get("body");
+ List<Map<String, Object>> paragraphs = (List<Map<String, Object>>) body.get("paragraphs");
+
+ assertTrue(paragraphs.size() > 0);
+ assertEquals(paragraphText, paragraphs.get(0).get("text"));
+ }
+
+ @Test
public void testNotebookCreateWithName() throws IOException {
String noteName = "Test note name";
testNotebookCreate(noteName);