原文链接 : http://zeppelin.apache.org/docs/0.7.2/rest-api/rest-notebook.html

译文链接 : http://cwiki.apachecn.org/pages/viewpage.action?pageId=10031062

贡献者 : 片刻 ApacheCN Apache中文网

概述

Apache Zeppelin提供了几个REST API,用于交互和远程激活zeppelin功能。所有REST API都可以从以下端点开始http://[zeppelin-server]:[zeppelin-port]/api。需要注意的是Apache的齐柏林飞艇的REST API接收或返回JSON对象,建议你安装一些JSON观众如JSONView。如果您使用Apache Zeppelin并发现需要一个额外的REST API,请提出问题或向我们发送电子邮件

笔记本REST API支持以下操作:列表,创建,获取,删除,克隆,运行,导出,导入,具体如下表所示。

注意操作

笔记列表

描述GET方法列出了服务器上的可用注释。笔记本JSON包含了nameid所有音符。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook
成功代码200
失败代码500
示例JSON响应

  1. {
    "status": "OK",
    "message": "",
    "body": [
    {
    "name":"Homepage",
    "id":"2AV4WUEMK"
    },
    {
    "name":"Zeppelin Tutorial",
    "id":"2A94M5J1Z"
    }
    ]
    }


创建新的笔记

描述POST方法使用给定的名称或默认名称创建一个新的注释,如果没有给定。返回的JSON的body字段包含新的note id。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook
成功代码201
失败代码500
示例JSON输入(无段落)

  1. {"name": "name of new note"}


JSON输入示例(含初始段落)

  1. {
    "name": "name of new note",
    "paragraphs": [
    {
    "title": "paragraph title1",
    "text": "paragraph text1"
    },
    {
    "title": "paragraph title2",
    "text": "paragraph text2"
    }
    ]
    }


示例JSON响应

  1. {
    "status": "CREATED",
    "message": "",
    "body": "2AZPHY918"
    }


获取所有段落的状态

描述GET方法通过给定的注释id获取所有段落的状态。返回的JSON的body字段包含由段落id,段落状态,段落完成日期,段落开始日期组成的数组。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]
成功代码200
失败代码500
示例JSON响应

  1. {
    "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字段包含有关注释中段落的信息。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]
成功代码200
失败代码500
示例JSON响应

  1. {
    "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": "paragraph1423500782552-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的注释。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]
成功代码200
失败代码500
示例JSON响应

  1. {"status": "OK","message": ""}


克隆笔记

描述POST方法将按照给定的ID克隆一个注释,并使用给定的名称或默认名称创建一个新的注释,如果没有给定的。返回的JSON的body字段包含新的note id。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]
成功代码201
失败代码500
示例JSON输入

  1. {"name": "name of new note"}


示例JSON响应

  1. {
    "status": "CREATED",
    "message": "",
    "body": "2AZPHY918"
    }


导出笔记

描述GET方法会导出一个给定ID的注释,并且gernerates一个JSON
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/export/[noteId]
成功代码201
失败代码500
示例JSON响应

  1. {
    "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输入中输入一个注释
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/import
成功代码201
失败代码500
示例JSON输入

  1. {
    "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": {}
    }


示例JSON响应

  1. {
    "status": "CREATED",
    "message": "",
    "body": "2AZPHY918"
    }


运行所有段落

描述POST方法运行给定注释id中的所有段落。如果找不到Note id 404返回。如果解释器有问题返回412错误。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]
成功代码200
失败代码404或412
示例JSON响应

  1. {"status": "OK"}


示例JSON错误响应
{ "status": "NOTFOUND", "message": "note not found."}{ "status": "PRECONDITIONFAILED", "message": "paragraph1469771130099-278315611 Not selected or Invalid Interpreter bind"}

停止所有段落

描述DELETE方法将停止给定注释id中的所有段落。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]
成功代码200
失败代码500
示例JSON响应

  1. {"status":"OK"}


清除所有段落结果

描述PUT方法清除给定id的注释的所有段落结果。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/clear
成功代码200
禁止代码401
找不到代码404
失败代码500
示例JSON响应

  1. {"status": "OK"}


段落操作

创建一个新的段落

描述POST方法使用JSON有效载荷创建一个新段落。返回的JSON的body字段包含新的段落ID。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph
成功代码201
失败代码500
示例JSON输入(添加到最后)

  1. {
    "title": "Paragraph insert revised",
    "text": "%spark\nprintln(\"Paragraph insert revised\")"
    }


JSON输入示例(添加到特定索引)

  1. {
    "title": "Paragraph insert revised",
    "text": "%spark\nprintln(\"Paragraph insert revised\")",
    "index": 0
    }


示例JSON响应

  1. {
    "status": "CREATED",
    "message": "",
    "body": "20151218-100330_1754029574"
    }


获取段落信息

描述GET方法使用给定的id检索现有段落的信息。返回的JSON的body字段包含有关段落的信息。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]
成功代码200
失败代码500
示例JSON响应

  1. {
    "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": "paragraph1450391574392-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,段落状态,段落完成日期,段落开始日期组成的数组。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]/[paragraphId]
成功代码200
失败代码500
示例JSON响应

  1. {
    "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更新段落配置,以便用户可以更改段落设置,如图形类型,显示或隐藏编辑器/结果和段落大小等。您可以更新所需的某些字段,例如,colWidth只能通过发送请求更新字段与有效载荷{"colWidth": 12.0}
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]/config
成功代码200
错误请求代码400
禁止代码403
找不到代码404
失败代码500
示例JSON输入

  1. {
    "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
    }


示例JSON响应

  1. {
    "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":"paragraph1423500782552-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删除段落。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]
成功代码200
失败代码500
示例JSON响应

  1. {"status": "OK","message": ""}


异步运行段落

描述POST方法通过给定的注释和段落ID异步运行段落。即使该段落的执行失败,该API也会始终返回SUCCESS,因为API是异步的
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]/[paragraphId]
成功代码200
失败代码500
示例JSON输入(可选,仅当需要更新动态表单的值时才需要)

  1. {
    "name": "name of new note",
    "params": {
    "formLabel1": "value1",
    "formLabel2": "value2"
    }
    }


示例JSON响应

  1. {“status”:“OK”}


同步运行段落

描述POST方法通过给定的注释和段落ID同步运行段落。该API可以根据段执行的结果返回SUCCESS或ERROR
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/run/[noteId]/[paragraphId]
成功代码200
失败代码500
示例JSON输入(可选,仅当需要更新动态表单的值时才需要)

  1. {
    "name": "name of new note",
    "params": {
    "formLabel1": "value1",
    "formLabel2": "value2"
    }
    }


示例JSON响应

  1. {"status": "OK"}


示例JSON错误

  1. {
    "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来停止段落。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]/[paragraphId]
成功代码200
失败代码500
示例JSON响应

  1. {"status": "OK"}


将段落移动到特定索引

描述POST方法将一个段落从注释移动到特定的索引(顺序)。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]/move/[newIndex]
成功代码200
失败代码500
示例JSON响应

  1. {"status": "OK","message": ""}


全文搜索所有笔记中的段落

描述GET 请求将返回匹配段落的列表
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/search?q=[query]
成功代码200
失败代码500
示例JSON响应

  1. {
    "status": "OK",
    "body": [
    {
    "id": "/paragraph/",
    "name":"Note Name",
    "snippet":"",
    "text":""
    }
    ]
    }


Cron工作

添加Cron作业

描述POST方法将cron作业添加到给定的注释id中。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/cron/[noteId]
成功代码200
失败代码500
示例JSON输入

  1. {"cron": "cron expression of note"}


示例JSON响应

  1. {"status": "OK"}


删除Cron作业

描述DELETE方法通过给定的注释id删除cron作业。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/cron/[noteId]
成功代码200
失败代码500
示例JSON响应

  1. {"status": "OK"}


获得Cron工作

描述GET方法获取给定注释id的cron作业表达式。返回的JSON的body字段包含cron表达式。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/cron/[noteId]
成功代码200
失败代码500
示例JSON响应

  1. {"status": "OK", "body": " * ?"}


允许

获取注释权限信息

描述GET方法获取注释授权信息。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/permissions
成功代码200
禁止代码403
失败代码500
示例JSON响应

  1. {

    "status":"OK",
    "message":"",
    "body":{

    "readers":[

    "user2"
    ],
    "owners":[

    "user1"
    ],
    "writers":[

    "user2"
    ]
    }
    }


设置备注权限

描述PUT方法设置备注授权信息。
网址http://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/permissions
成功代码200
禁止代码403
失败代码500
示例JSON输入

  1. {
    "readers": [
    "user1"
    ],
    "owners": [
    "user2"
    ],
    "writers": [
    "user1"
    ]
    }





示例JSON响应

  1. {



  1. "status": "OK"
    }