Kylin 使用RESTful API进行cube的增量更新

来源:互联网 发布:pitstop汉化破解版mac 编辑:程序博客网 时间:2024/05/16 02:13

一、生成鉴权文件,之后每一步都需要使用cookfile.txt

curl -c cookfile.txt -X POST \-H "Authorization:Basic QURNSU46S1lMSU4=" \-H "Content-Type: application/json" \http://hostname:7070/kylin/api/user/authentication

ADMIN:KYLIN使用Base64编码后的结果为:QURNSU46S1lMSU4=。
-c : cookie写入的文件。
-H : 自定义header传递给服务器。
-X : 指定使用的请求命令。
返回json格式结果如下:

{    "userDetails": {        "accountNonExpired": true,         "accountNonLocked": true,         "authorities": [            {                "authority": "ROLE_ADMIN"            },             {                "authority": "ROLE_ANALYST"            },             {                "authority": "ROLE_MODELER"            }        ],         "credentialsNonExpired": true,         "enabled": true,         "password": null,         "username": "ADMIN"    }}

二、获取project下面所有的cube

curl -b cookfile.txt \-X GET \-H "Content-Type: application/json" \hostname:7070/kylin/api/cubes?projectName=TEST\&offset=0\&limit=1

projectName:工程名大写
projectName=TEST\&offset=0\&limit=1:在linux系统中& 会使进程系统后台运行
必须对&进行下转义才能$_GET获取到所有参数。我开始没有转义&,只获取到了第一个参数。

三、获取一个cube的详细信息

curl -b cookfile.txt \-H "Content-Type: application/json" \hostname:7070/kylin/api/cubes/cubeName

四、获取一个model的信息

curl -b cookfile.txt \-H "Content-Type: application/json" \hostname:7070/kylin/api/model/modelName

五、更新cube,增量更新cube

curl -b cookfile.txt \-X PUT -H "Content-Type: application/json" \-d '{"endTime":'1483977600000',"buildType":"BUILD"}' \http://hostname:7070/kylin/api/cubes/cubeName/rebuild 

startTime : 做增量时,startTime 为上一次build的endTime。
endTime:时间精确到毫秒。
buildType:可选BUILD,MERGE,REDRESH

六、获取cube在build过程的状态

curl -b cookfile.txt \-X GET \http://hostname:7070/kylin/api/jobs/uuid

uuid:从cube提交build时返回的json格式数据中获得。
返回结果中job_status有FINISHED,ERROR,DISCARDED等状态。

七、当cube build过程中出错,重新执行

curl -b cookfile.txt \-X PUT -H "Content-Type: application/json" \http://hostname:7070/kylin/api/jobs/uuid/resume

uuid:从cube提交build时返回的json格式数据中获得。

八、通过RESTful API查询SQL

curl -b cookfile.txt \-X post \-H "Content-Type: application/json" \-d '{    "sql":"select part_dt,sum(price) as total_selled,count(distinct seller_id) as        sellers from KYLIN_SALES group by part_dt",    "offset":0,    "limit":2,    "acceptPartial":false,    "project":"LEARN_KYLIN"}'  http://hostname:7070/kylin/api/query 

先写这些,以上查询返回结果均为json格式数据。
shell调度这些命令执行可以使用jq工具解析json数据。关于jq的使用不在本篇讨论范围,下面给一个例子,获取一个工程下所有cube列表。

array_cube=()cubeList=`curl -b cookfile.txt \-X GET \-H "Content-Type: application/json" \http://hostname:7070/kylin/api/cubes?projectName=${projectName}`cube=`echo ${cubeList} | jq  -r '.'[0]'.name'`i=0while [ "$cube" != "null" ]; do     status=`echo ${cubeList} | jq -r '.'[${i}]'.status'`    if [ "$status" = "READY" ]; then        array_cube[ ${i} ]=${cube}    fi    let i++      cube=`echo ${cubeList}|jq -r '.'[${i}]'.name'`done#echo ${array_cube[@]}

有错误的地方或者有什么问题留言大家一起讨论。

0 0
原创粉丝点击