Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
187 changes: 187 additions & 0 deletions docs/rest-api/rest-notebook.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,190 @@ limitations under the License.
</tr>
</table>

<br/>


<table class="table-configuration">
<col width="200">
<tr>
<th>Create paragraph</th>
<th></th>
</tr>
<tr>
<td>Description</td>
<td>This ```POST``` method create a new paragraph using JSON payload.
The body field of the returned JSON contain the new paragraph id.
</td>
</tr>
<tr>
<td>URL</td>
<td>```http://[zeppelin-server]:[zeppelin-port]/api/notebook/[notebookId]/paragraph```</td>
</tr>
<tr>
<td>Success code</td>
<td>201</td>
</tr>
<tr>
<td> Fail code</td>
<td> 500 </td>
</tr>
<tr>
<td> sample JSON input (add to the last) </td>
<td><pre>
{
"title": "Paragraph insert revised",
"text": "%spark\nprintln(\"Paragraph insert revised\")"
}</pre></td>
</tr>
<tr>
<td> sample JSON input (add to specific index) </td>
<td><pre>
{
"title": "Paragraph insert revised",
"text": "%spark\nprintln(\"Paragraph insert revised\")",
"index": 0
}
</pre></td>
</tr>
<tr>
<td> sample JSON response </td>
<td><pre>{"status": "CREATED","message": "","body": "20151218-100330_1754029574"}</pre></td>
</tr>
</table>

<br/>

<table class="table-configuration">
<col width="200">
<tr>
<th>Get paragraph</th>
<th></th>
</tr>
<tr>
<td>Description</td>
<td>This ```GET``` method retrieves an existing paragraph's information using the given id.
The body field of the returned JSON contain information about paragraph.
</td>
</tr>
<tr>
<td>URL</td>
<td>```http://[zeppelin-server]:[zeppelin-port]/api/notebook/[notebookId]/paragraph/[paragraphId]```</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": {
"title": "Paragraph2",
"text": "%spark\n\nprintln(\"it's paragraph2\")",
"dateUpdated": "Dec 18, 2015 7:33:54 AM",
"config": {
"colWidth": 12,
"graph": {
"mode": "table",
"height": 300,
"optionOpen": false,
"keys": [],
"values": [],
"groups": [],
"scatter": {}
},
"enabled": true,
"title": true,
"editorMode": "ace/mode/scala"
},
"settings": {
"params": {},
"forms": {}
},
"jobName": "paragraph_1450391574392_-1890856722",
"id": "20151218-073254_1105602047",
"result": {
"code": "SUCCESS",
"type": "TEXT",
"msg": "it's paragraph2\n"
},
"dateCreated": "Dec 18, 2015 7:32:54 AM",
"dateStarted": "Dec 18, 2015 7:33:55 AM",
"dateFinished": "Dec 18, 2015 7:33:55 AM",
"status": "FINISHED",
"progressUpdateIntervalMs": 500
}
}
</pre></td>
</tr>
</table>

<br/>

<table class="table-configuration">
<col width="200">
<tr>
<th>Move paragraph</th>
<th></th>
</tr>
<tr>
<td>Description</td>
<td>This ```POST``` method moves a paragraph to the specific index (order) from the notebook.
</td>
</tr>
<tr>
<td>URL</td>
<td>```http://[zeppelin-server]:[zeppelin-port]/api/notebook/[notebookId]/paragraph/[paragraphId]/move/[newIndex]```</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":""}</pre></td>
</tr>
</table>


<br/>

<table class="table-configuration">
<col width="200">
<tr>
<th>Delete paragraph</th>
<th></th>
</tr>
<tr>
<td>Description</td>
<td>This ```DELETE``` method deletes a paragraph by the given notebook and paragraph id.
</td>
</tr>
<tr>
<td>URL</td>
<td>```http://[zeppelin-server]:[zeppelin-port]/api/notebook/[notebookId]/paragraph/[paragraphId]```</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":""}</pre></td>
</tr>
</table>

Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,129 @@ public Response cloneNote(@PathParam("notebookId") String notebookId, String mes
notebookServer.broadcastNoteList();
return new JsonResponse<>(Status.CREATED, "", newNote.getId()).build();
}


/**
* Insert paragraph REST API
* @param message - JSON containing paragraph's information
* @return JSON with status.OK
* @throws IOException
*/
@POST
@Path("{notebookId}/paragraph")
public Response insertParagraph(@PathParam("notebookId") String notebookId, String message)
throws IOException {
LOG.info("insert paragraph {} {}", notebookId, message);

Note note = notebook.getNote(notebookId);
if (note == null) {
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
}

NewParagraphRequest request = gson.fromJson(message, NewParagraphRequest.class);

Paragraph p;
Double indexDouble = request.getIndex();
if (indexDouble == null) {
p = note.addParagraph();
} else {
p = note.insertParagraph(indexDouble.intValue());
}
p.setTitle(request.getTitle());
p.setText(request.getText());

note.persist();
notebookServer.broadcastNote(note);
return new JsonResponse(Status.CREATED, "", p.getId()).build();
}

/**
* Get paragraph REST API
* @param
* @return JSON with information of the paragraph
* @throws IOException
*/
@GET
@Path("{notebookId}/paragraph/{paragraphId}")
public Response getParagraph(@PathParam("notebookId") String notebookId,
@PathParam("paragraphId") String paragraphId) throws IOException {
LOG.info("get paragraph {} {}", notebookId, paragraphId);

Note note = notebook.getNote(notebookId);
if (note == null) {
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
}

Paragraph p = note.getParagraph(paragraphId);
if (p == null) {
return new JsonResponse(Status.NOT_FOUND, "paragraph not found.").build();
}

return new JsonResponse(Status.OK, "", p).build();
}

/**
* Move paragraph REST API
* @param newIndex - new index to move
* @return JSON with status.OK
* @throws IOException
*/
@POST
@Path("{notebookId}/paragraph/{paragraphId}/move/{newIndex}")
public Response moveParagraph(@PathParam("notebookId") String notebookId,
@PathParam("paragraphId") String paragraphId,
@PathParam("newIndex") String newIndex) throws IOException {
LOG.info("move paragraph {} {} {}", notebookId, paragraphId, newIndex);

Note note = notebook.getNote(notebookId);
if (note == null) {
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
}

Paragraph p = note.getParagraph(paragraphId);
if (p == null) {
return new JsonResponse(Status.NOT_FOUND, "paragraph not found.").build();
}

try {
note.moveParagraph(paragraphId, Integer.parseInt(newIndex), true);

note.persist();
notebookServer.broadcastNote(note);
return new JsonResponse(Status.OK, "").build();
} catch (IndexOutOfBoundsException e) {
return new JsonResponse(Status.BAD_REQUEST, "paragraph's new index is out of bound").build();
}
}

/**
* Delete paragraph REST API
* @param
* @return JSON with status.OK
* @throws IOException
*/
@DELETE
@Path("{notebookId}/paragraph/{paragraphId}")
public Response deleteParagraph(@PathParam("notebookId") String notebookId,
@PathParam("paragraphId") String paragraphId) throws IOException {
LOG.info("delete paragraph {} {}", notebookId, paragraphId);

Note note = notebook.getNote(notebookId);
if (note == null) {
return new JsonResponse(Status.NOT_FOUND, "note not found.").build();
}

Paragraph p = note.getParagraph(paragraphId);
if (p == null) {
return new JsonResponse(Status.NOT_FOUND, "paragraph not found.").build();
}

note.removeParagraph(paragraphId);
note.persist();
notebookServer.broadcastNote(note);

return new JsonResponse(Status.OK, "").build();
}

/**
* Run notebook jobs REST API
* @param
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
/**
* NewParagraphRequest rest api request message
*
* It is used for NewNotebookRequest with initial paragraphs
*
* index field will be ignored when it's used to provide initial paragraphs
*/
public class NewParagraphRequest {
String title;
String text;
Double index;

public NewParagraphRequest() {

Expand All @@ -38,4 +38,8 @@ public String getTitle() {
public String getText() {
return text;
}

public Double getIndex() {
return index;
}
}
Loading