Zeppelin Notebook 操作REST API

Apache Zeppelin Notebook REST API

Overview

Apache Zeppelin 提供了多个REST APIs用于远程功能交互操作。 所有的REST APIs 都通过 endpoint http://[zeppelin-server]:[zeppelin-port]/api 进行操作。注意,Apache Zeppelin 的REST APIs 都接受和返回 JSON 对象, 建议安装 JSON viewers, 比如 JSONView

Notebooks REST API 支持下列操作:List, Create, Get, Delete, Clone, Run, Export, Import,详情如下:

Notebook操作

notes列表

DescriptionThis GET method lists the available notes on your server. Notebook JSON contains the name and id of all notes.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook
Success code200
Fail code500
sample JSON response
{
  "status": "OK",
  "message": "",
  "body": [
    {
      "name":"Homepage",
      "id":"2AV4WUEMK"
    },
    {
      "name":"Zeppelin Tutorial",
      "id":"2A94M5J1Z"
    }
  ]
}

 

创建新的 note

DescriptionThis POST method creates a new note using the given name or default name if none given. The body field of the returned JSON contains the new note id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook
Success code200
Fail code500
sample JSON input (without paragraphs)
{"name": "name of new note"}
sample JSON input (with initial paragraphs)
{
  "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
            }
          }
        ]
      }
    }
  ]
}
sample JSON response
{
  "status": "CREATED",
  "message": "",
  "body": "2AZPHY918"
}

得到所有的 paragraphs的状态

DescriptionThis GET method gets the status of all paragraphs by the given note id. The body field of the returned JSON contains of the array that compose of the paragraph id, paragraph status, paragraph finish date, paragraph started date.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]
Success code200
Fail code500
sample JSON response
{
  "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"
    }
  ]
}

获得 note 的信息

DescriptionThis GET method retrieves an existing note's information using the given id. The body field of the returned JSON contain information about paragraphs in the note.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]
Success code200
Fail code500
sample JSON response
{
  "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": {}
  }
}

删除 note

DescriptionThis DELETE method deletes a note by the given note id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]
Success code200
Fail code500
sample JSON response
{"status": "OK","message": ""}

 

复制 note

DescriptionThis POST method clones a note by the given id and create a new note using the given name or default name if none given. The body field of the returned JSON contains the new note id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]
Success code200
Fail code500
sample JSON input
{"name": "name of new note"}
sample JSON response
{
  "status": "CREATED",
  "message": "",
  "body": "2AZPHY918"
}

导出 note

DescriptionThis GET method exports a note by the given id and gernerates a JSON
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/export/[noteId]
Success code201
Fail code500
sample JSON response
{
  "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": {}
}

 

导入 note

DescriptionThis POST method imports a note from the note JSON input
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/import
Success code201
Fail code500
sample JSON input
{
  "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": {}
}
sample JSON response
{
  "status": "CREATED",
  "message": "",
  "body": "2AZPHY918"
}

 

运行所有的 paragraphs

DescriptionThis POST method runs all paragraphs in the given note id.
If you can not find Note id 404 returns. If there is a problem with the interpreter returns a 412 error.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]
Success code200
Fail code404 or 412
sample JSON response
{"status": "OK"}
sample JSON error response
{
             "status": "NOTFOUND",
             "message": "note not found."
           }
         
 
           {
             "status": "PRECONDITIONFAILED",
             "message": "paragraph1469771130099-278315611 Not selected or Invalid Interpreter bind"
           }

 

停止所有的 paragraphs

DescriptionThis DELETE method stops all paragraphs in the given note id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]
Success code200
Fail code500
sample JSON response
{"status":"OK"}

 

清除所有的 paragraph 输出结果

DescriptionThis PUT method clear all paragraph results from note of given id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/clear
Success code200
Forbidden code401
Not Found code404
Fail code500
sample JSON response
{"status": "OK"}

 

Paragraph 操作

 

创建新的 paragraph

DescriptionThis POST method create a new paragraph using JSON payload. The body field of the returned JSON contain the new paragraph id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph
Success code201
Fail code500
sample JSON input (add to the last)
{
  "title": "Paragraph insert revised",
  "text": "%spark\nprintln(\"Paragraph insert revised\")"
}
sample JSON input (add to specific index)
{
  "title": "Paragraph insert revised",
  "text": "%spark\nprintln(\"Paragraph insert revised\")",
  "index": 0
}
sample JSON input (providing paragraph config)
{
  "title": "paragraph title2",
  "text": "paragraph text2",
  "config": {
    "title": true,
    "colWidth": 6.0,
    "results": [
      {
        "graph": {
          "mode": "pieChart",
          "optionOpen": true
        }
      }
    ]
  }
}
sample JSON response
{
  "status": "CREATED",
  "message": "",
  "body": "20151218-100330_1754029574"
}

 

获得一个 paragraph 的信息

DescriptionThis GET method retrieves an existing paragraph's information using the given id. The body field of the returned JSON contain information about paragraph.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]
Success code200
Fail code500
sample JSON response
{
  "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
  }
}

 

得到单个 paragraph的状态

DescriptionThis GET method gets the status of a single paragraph by the given note and paragraph id. The body field of the returned JSON contains of the array that compose of the paragraph id, paragraph status, paragraph finish date, paragraph started date.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]/[paragraphId]
Success code200
Fail code500
sample JSON response
{
  "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"
    }
}

 

更新 paragraph 的配置

DescriptionThis PUT method update paragraph configuration using given id so that user can change paragraph setting such as graph type, show or hide editor/result and paragraph size, etc. You can update certain fields you want, for example you can update colWidth field only by sending request with payload {"colWidth": 12.0}.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]/config
Success code200
Bad Request code400
Forbidden code403
Not Found code404
Fail code500
sample JSON input
{
  "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
}
sample JSON response
{
  "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
  }
}

 

 

删除一个 paragraph

 

DescriptionThis DELETE method deletes a paragraph by the given note and paragraph id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]
Success code200
Fail code500
sample JSON response
{"status": "OK","message": ""}

 

异步运行一个 paragraph

DescriptionThis POST method runs the paragraph asynchronously by given note and paragraph id. This API always return SUCCESS even if the execution of the paragraph fails later because the API is asynchronous
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]/[paragraphId]
Success code200
Fail code500
sample JSON input (optional, only needed when if you want to update dynamic form's value)
{
  "name": "name of new note",
  "params": {
    "formLabel1": "value1",
    "formLabel2": "value2"
  }
}
sample JSON response
{"status": "OK"}

 

同步运行一个 paragraph

DescriptionThis POST method runs the paragraph synchronously by given note and paragraph id. This API can return SUCCESS or ERROR depending on the outcome of the paragraph execution
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/run/[noteId]/[paragraphId]
Success code200
Fail code500
sample JSON input (optional, only needed when if you want to update dynamic form's value)
{
  "name": "name of new note",
  "params": {
    "formLabel1": "value1",
    "formLabel2": "value2"
  }
}
sample JSON response
{"status": "OK"}
sample JSON error
{
   "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"
   }
}

 

停止 paragraph

DescriptionThis DELETE method stops the paragraph by given note and paragraph id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/job/[noteId]/[paragraphId]
Success code200
Fail code500
sample JSON response
{"status": "OK"}

 

移动一个 paragraph 到给定的索引

DescriptionThis POST method moves a paragraph to the specific index (order) from the note.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/paragraph/[paragraphId]/move/[newIndex]
Success code200
Fail code500
sample JSON response
{"status": "OK","message": ""}

 

在所有的note通过paragraphs全文搜索

DescriptionGET request will return list of matching paragraphs
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/search?q=[query]
Success code200
Fail code500
Sample JSON response
{
  "status": "OK",
  "body": [
    {
      "id": "/paragraph/",
      "name":"Note Name", 
      "snippet":"",
      "text":""
    }
  ]
}

 

调度 jobs

添加一个 Cron Job

DescriptionThis POST method adds cron job by the given note id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/cron/[noteId]
Success code200
Fail code500
sample JSON input
{"cron": "cron expression of note"}
sample JSON response
{"status": "OK"}

 

删除一个 Cron Job

DescriptionThis DELETE method removes cron job by the given note id.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/cron/[noteId]
Success code200
Fail code500
sample JSON response
{"status": "OK"}

 

获得 Cron Job

DescriptionThis GET method gets cron job expression of given note id. The body field of the returned JSON contains the cron expression.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/cron/[noteId]
Success code200
Fail code500
sample JSON response
{"status": "OK", "body": "* * * * * ?"}

 

权限

获得note 的permission信息

DescriptionThis GET method gets a note authorization information.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/permissions
Success code200
Forbidden code403
Fail code500
sample JSON response
{

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

      "readers":[

         "user2"
      ],
      "owners":[

         "user1"
      ],
      "writers":[

         "user2"
      ]
   }
}

 

设置 note permission

DescriptionThis PUT method set note authorization information.
URLhttp://[zeppelin-server]:[zeppelin-port]/api/notebook/[noteId]/permissions
Success code200
Forbidden code403
Fail code500
sample JSON input
{
  "readers": [
    "user1"
  ],
  "owners": [
    "user2"
  ],
  "writers": [
    "user1"
  ]
}
sample JSON response
{
  "status": "OK"
}

转载于:https://my.oschina.net/u/2306127/blog/894618

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值