Apache Zeppelin 笔记本 REST API
概述
Apache Zeppelin 提供了多个 REST API 用于交互和远程激活 Zeppelin 功能。
所有 REST API 都从以下端点开始可用 http://[zeppelin-server]:[zeppelin-port]/api。
请注意,Apache Zeppelin 的 REST API 接收或返回 JSON 对象,建议您安装一些 JSON 查看器,例如 JSONView。
如果您在使用 Apache Zeppelin 时发现需要额外的 REST API,请 提交问题或发送电子邮件给我们。
Notebooks REST API 支持以下操作:列出、创建、获取、删除、克隆、运行、导出、导入,如下表所示。
笔记操作
笔记列表
| 描述 | 此GET方法列出服务器上可用的笔记。
笔记本JSON包含所有笔记的name和id。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"status": "OK",
"message": "",
"body": [
{
"path":"Homepage",
"id":"2AV4WUEMK"
},
{
"path":"Zeppelin Tutorial",
"id":"2A94M5J1Z"
}
]
}
创建新笔记
| 描述 | 此POST方法使用给定的名称或默认名称(如果未提供)创建一个新的笔记。
返回的JSON的body字段包含新笔记的ID。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON输入(无段落) |
{"name": "name of new note"}
{
"name": "name of new note",
"paragraphs": [
{
"title": "paragraph title1",
"text": "paragraph text1"
},
{
"title": "paragraph title2",
"text": "paragraph text2",
"config": {
"title": true,
"colWidth": 6.0,
"results": [
{
"graph": {
"mode": "scatterChart",
"optionOpen": true
}
}
]
}
}
]
}
{
"status": "OK",
"message": "",
"body": "2AZPHY918"
}
获取所有段落的状态
| 描述 | 此GET方法通过给定的笔记ID获取所有段落的状态。
返回的JSON的body字段包含由段落ID、段落状态、段落完成日期、段落开始日期组成的数组。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"status": "OK",
"body": [
{
"id":"20151121-212654\_766735423",
"status":"FINISHED",
"finished":"Tue Nov 24 14:21:40 KST 2015",
"started":"Tue Nov 24 14:21:39 KST 2015"
},
{
"progress":"1",
"id":"20151121-212657\_730976687",
"status":"RUNNING",
"finished":"Tue Nov 24 14:21:35 KST 2015",
"started":"Tue Nov 24 14:21:40 KST 2015"
}
]
}
获取现有笔记信息
| 描述 | 此GET方法使用给定的id检索现有笔记的信息。
返回的JSON的body字段包含有关笔记中段落的信息。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"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",
"results": {
"code": "SUCCESS",
"msg": [
{
"type": "TABLE",
"data": "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": {}
}
}
删除笔记
| 描述 | 这个DELETE方法通过给定的笔记ID删除一个笔记。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{"status": "OK","message": ""}
克隆笔记
| 描述 | 此POST方法通过给定的id克隆一个笔记,并使用给定的名称或默认名称(如果未提供)创建一个新笔记。如果您想复制的是某个特定版本的笔记,则需要指定revisionId。
返回的JSON的body字段包含新笔记的id。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON输入 |
{
"name": "name of new note",
"revisionId": "revisionId of note to be copied (optional)"
}
{
"status": "OK",
"message": "",
"body": "2AZPHY918"
}
重命名笔记
| 描述 | 此PUT方法通过给定的ID使用给定的名称重命名笔记。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/rename |
| 成功代码 | 200 |
| 错误请求代码 | 400 |
| 失败代码 | 500 |
| 示例JSON输入 |
{"name": "new name of a note"}
{"status":"OK"}
导出笔记
| 描述 | 此GET方法通过给定的id导出一个笔记并生成一个JSON
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/export/[noteId] |
| 成功代码 | 201 |
| 失败代码 | 500 | 示例JSON响应 |
{
"paragraphs": [
{
"text": "%md This is my new paragraph in my new note",
"dateUpdated": "Jan 8, 2016 4:49:38 PM",
"config": {
"enabled": true
},
"settings": {
"params": {},
"forms": {}
},
"jobName": "paragraph\_1452300578795\_1196072540",
"id": "20160108-164938\_1685162144",
"dateCreated": "Jan 8, 2016 4:49:38 PM",
"status": "READY",
"progressUpdateIntervalMs": 500
}
],
"name": "source note for export",
"id": "2B82H3RR1",
"angularObjects": {},
"config": {},
"info": {}
}
导入笔记
| 描述 | 此POST方法从笔记JSON输入导入笔记
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/import |
| 成功代码 | 201 |
| 失败代码 | 500 |
| 示例JSON输入 |
{
"paragraphs": [
{
"text": "%md This is my new paragraph in my new note",
"dateUpdated": "Jan 8, 2016 4:49:38 PM",
"config": {
"enabled": true
},
"settings": {
"params": {},
"forms": {}
},
"jobName": "paragraph\_1452300578795\_1196072540",
"id": "20160108-164938\_1685162144",
"dateCreated": "Jan 8, 2016 4:49:38 PM",
"status": "READY",
"progressUpdateIntervalMs": 500
}
],
"name": "source note for export",
"id": "2B82H3RR1",
"angularObjects": {},
"config": {},
"info": {}
}
{
"status": "OK",
"message": "",
"body": "2AZPHY918"
}
运行所有段落
| 描述 |
这个POST方法运行给定笔记ID中的所有段落。如果找不到笔记ID,则返回404。 如果解释器出现问题,则返回412错误。 |
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId] |
| 成功代码 | 200 |
| 失败代码 | 404或412 |
| 示例JSON响应 |
{"status": "OK"}
{
"status": "NOT_FOUND",
"message": "note not found."
}
{
"status": "PRECONDITION_FAILED",
"message": "paragraph_1469771130099_-278315611 Not selected or Invalid Interpreter
bind"
}
停止所有段落
| 描述 | 此DELETE方法停止给定笔记ID中的所有段落。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{"status":"OK"}
清除所有段落结果
| 描述 | 此PUT方法清除给定ID的笔记中的所有段落结果。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/clear |
| 成功代码 | 200 |
| 禁止代码 | 401 |
| 未找到代码 | 404 |
| 失败代码 | 500 |
| 示例JSON响应 |
{"status": "OK"}
段落操作
创建一个新段落
| 描述 | 此POST方法使用JSON负载创建一个新段落。
返回的JSON的body字段包含新段落的ID。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph |
| 成功代码 | 201 |
| 失败代码 | 500 |
| 示例JSON输入(添加到末尾) |
{
"title": "Paragraph insert revised",
"text": "%spark\nprintln(\"Paragraph insert revised\")"
}
{
"title": "Paragraph insert revised",
"text": "%spark\nprintln(\"Paragraph insert revised\")",
"index": 0
}
{
"title": "paragraph title2",
"text": "paragraph text2",
"config": {
"title": true,
"colWidth": 6.0,
"results": [
{
"graph": {
"mode": "pieChart",
"optionOpen": true
}
}
]
}
}
{
"status": "OK",
"message": "",
"body": "20151218-100330\_1754029574"
}
获取段落信息
| 描述 | 此GET方法使用给定的id检索现有段落的信息。
返回的JSON的body字段包含有关段落的信息。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"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",
"results": {
"code": "SUCCESS",
"msg": [
{
"type": "TEXT",
"data": "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
}
}
获取单个段落的状态
| 描述 | 此GET方法通过给定的笔记和段落ID获取单个段落的状态。
返回的JSON的body字段包含由段落ID、段落状态、段落完成日期、段落开始日期组成的数组。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]/[paragraphId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"status": "OK",
"body": {
"id":"20151121-212654\_766735423",
"status":"FINISHED",
"finished":"Tue Nov 24 14:21:40 KST 2015",
"started":"Tue Nov 24 14:21:39 KST 2015"
}
}
更新段落
| 描述 | 此PUT方法使用给定的ID更新段落内容,例如{"text": "hello"}
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId] |
| 成功代码 | 200 |
| 错误请求代码 | 400 |
| 禁止代码 | 403 |
| 未找到代码 | 404 |
| 失败代码 | 500 |
| 示例JSON输入 |
{
"title": "Hello world",
"text": "println(\"hello world\")"
}
{
"status": "OK",
"message": ""
}
更新段落配置
| 描述 | 此PUT方法使用给定的ID更新段落配置,以便用户可以更改段落设置,如图表类型、显示或隐藏编辑器/结果以及段落大小等。您可以更新您想要的某些字段,例如您可以通过发送带有有效载荷{"colWidth": 12.0}的请求仅更新colWidth字段。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]/config |
| 成功代码 | 200 |
| 错误请求代码 | 400 |
| 禁止代码 | 403 |
| 未找到代码 | 404 |
| 失败代码 | 500 |
| 示例JSON输入 |
{
"colWidth": 6.0,
"graph": {
"mode": "lineChart",
"height": 200.0,
"optionOpen": false,
"keys": [
{
"name": "age",
"index": 0.0,
"aggr": "sum"
}
],
"values": [
{
"name": "value",
"index": 1.0,
"aggr": "sum"
}
],
"groups": [],
"scatter": {}
},
"editorHide": true,
"editorMode": "ace/mode/markdown",
"tableHide": false
}
{
"status":"OK",
"message":"",
"body":{
"text":"%sql \nselect age, count(1) value\nfrom bank \nwhere age \u003c 30 \ngroup by
age \norder by age",
"config":{
"colWidth":6.0,
"graph":{
"mode":"lineChart",
"height":200.0,
"optionOpen":false,
"keys":[
{
"name":"age",
"index":0.0,
"aggr":"sum"
}
],
"values":[
{
"name":"value",
"index":1.0,
"aggr":"sum"
}
],
"groups":[],
"scatter":{}
},
"tableHide":false,
"editorMode":"ace/mode/markdown",
"editorHide":true
},
"settings":{
"params":{},
"forms":{}
},
"apps":[],
"jobName":"paragraph_1423500782552_-1439281894",
"id":"20150210-015302_1492795503",
"results":{
"code":"SUCCESS",
"msg": [
{
"type":"TABLE",
"data":"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
}
}
删除一个段落
| 描述 | 此DELETE方法通过给定的笔记和段落ID删除一个段落。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{"status": "OK","message": ""}
异步运行一个段落
| 描述 | 此POST方法通过给定的笔记和段落ID异步运行段落。即使段落的执行稍后失败,此API也始终返回SUCCESS,因为API是异步的
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]/[paragraphId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON输入(可选,仅在需要更新动态表单的值时需要) |
{
"name": "name of new note",
"params": {
"formLabel1": "value1",
"formLabel2": "value2"
}
}
{"status": "OK"}
同步运行一个段落
| 描述 | 此POST方法通过给定的笔记和段落ID同步运行段落。此API可以根据段落执行的结果返回SUCCESS或ERROR
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/run/[noteId]/[paragraphId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON输入(可选,仅在需要更新动态表单的值时需要) |
{
"name": "name of new note",
"params": {
"formLabel1": "value1",
"formLabel2": "value2"
}
}
{"status": "OK"}
{
"status": "INTERNAL\_SERVER\_ERROR",
"body": {
"code": "ERROR",
"type": "TEXT",
"msg": "bash: -c: line 0: unexpected EOF while looking for matching ``'\nbash: -c:
line 1: syntax error: unexpected end of file\nExitValue: 2"
}
}
停止一个段落
| 描述 | 此DELETE方法通过给定的笔记和段落ID停止段落。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]/[paragraphId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{"status": "OK"}
将段落移动到特定索引
| 描述 | 此POST方法将段落从笔记移动到特定索引(顺序)。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]/move/[newIndex] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{"status": "OK","message": ""}
在所有笔记的段落中进行全文搜索
| 描述 | GET 请求将返回匹配段落的列表
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/search?q=[query] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例 JSON 响应 |
{
"status": "OK",
"body": [
{
"id": "<noteId>/paragraph/<paragraphId>",
"name":"Note Name",
"snippet":"",
"text":""
}
]
}
定时任务
添加定时任务
| 描述 | 此POST方法通过给定的笔记ID添加定时任务。
releaseResource的默认值为false。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/cron/[noteId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON输入 |
{"cron": "cron expression of note", "releaseResource": "false"}
{"status": "OK"}
删除定时任务
| 描述 | 此DELETE方法通过给定的笔记ID移除定时任务。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/cron/[noteId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{"status": "OK"}
获取定时任务
| 描述 | 此GET方法获取给定笔记ID的cron作业表达式。
返回的JSON的body字段包含cron表达式和releaseResource标志。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/cron/[noteId] |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"status": "OK",
"body": {
"cron": "0 0/1 * * * ?",
"releaseResource": true
}
}
权限
获取笔记权限信息
| 描述 | 此GET方法获取笔记授权信息。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/permissions |
| 成功代码 | 200 |
| 禁止代码 | 403 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"status":"OK",
"message":"",
"body":{
"readers":[
"user2"
],
"owners":[
"user1"
],
"runners":[
"user2"
],
"writers":[
"user2"
]
}
}
设置笔记权限
| 描述 | 此PUT方法设置笔记授权信息。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/permissions |
| 成功代码 | 200 |
| 禁止代码 | 403 |
| 失败代码 | 500 |
| 示例JSON输入 |
{
"readers": [
"user1"
],
"owners": [
"user2"
],
"runners":[
"user2"
],
"writers": [
"user1"
]
}
{
"status": "OK"
}
版本控制
获取笔记的修订版本
| 描述 | 此GET方法获取笔记的修订版本。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/revision |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"status": "OK",
"body": [
{
"id": "f97ce5c7f076783023d33623ad52ca994277e5c1",
"message": "first commit",
"time": 1645712061
},
{
"id": "e9b964bebdecec6a59efe085f97db4040ae333aa",
"message": "second commit",
"time": 1645693163
}
]
}
保存笔记的修订版本
| 描述 | 此POST方法保存笔记的修订。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/revision |
| 成功代码 | 200 |
| 错误请求代码 | 400 |
| 失败代码 | 500 |
| 示例JSON输入 |
{
"commitMessage": "first commit"
}
{
"status": "OK",
"message": "",
"body": "6a5879218dfb797b013bcd24a594808045e34875"
}
获取笔记的修订版本
| 描述 | 这个GET方法获取笔记的一个修订版本。
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/revision/{revisionId} |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"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",
"results": {
"code": "SUCCESS",
"msg": [
{
"type": "TABLE",
"data": "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": {}
}
}
将笔记恢复到指定版本
| 描述 | 此PUT方法将笔记恢复到指定版本
|
| URL | http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/revision/{revisionId} |
| 成功代码 | 200 |
| 失败代码 | 500 |
| 示例JSON响应 |
{
"status": "OK"
}