kylin-cube: 使用REST api来build, 自动构建cube

左手的ㄟ右手 2022-02-17 09:58 406阅读 0赞

文章目录

  • 1,执行cube的相关任务
    • a, build/rebuild cube
    • b, 获取job的状态
  • 2, 元数据备份、恢复
  • 3, 自动构建cube

























api 返回值 描述
http://ip:7070/kylin/api/models json数组 查看所有model元数据
http://ip:7070/kylin/api/cubes json数组 查看所有cube元数据
http://ip:7070/kylin/api/jobs/xxx json数组 查看单个cube提交后的任务

获取用户名密码: 被base64加密后的格式:QURNSU46S1lMSU4=

  1. UserName=ADMIN
  2. Password=KYLIN
  3. baseUsernamePasswd=`python -c "import base64; print base64.standard_b64encode('$UserName:$Password')"`

1,执行cube的相关任务

a, build/rebuild cube

  1. curl -X PUT \
  2. -H "Authorization: Basic $baseUsernamePasswd" \
  3. -H "Content-Type: application/json" \
  4. -d '{ "startTime": 0, "endTime": 1388563200000, "buildType": "BUILD" }' \
  5. http://localhost:7070/kylin/api/cubes/ys_demo/build
  6. #http://localhost:7070/kylin/api/cubes/ys_demo/rebuild
  7. ##数据返回
  8. { "uuid":"2eb3c342-daa2-4fab-abb8-c622beb46d9b", ...}

b, 获取job的状态

  1. curl -X GET \
  2. -H "Authorization: Basic QURNSU46S1lMSU4=" \
  3. -H "Content-Type: application/json" \
  4. http://localhost:7070/kylin/api/jobs/cbfaf44f-c7bb-4b5a-9da4-671f6c84b1bb
  5. ##返回的数据
  6. { ...,"submitter":"ADMIN","job_status":"RUNNING","progress":53.84615384615385...}

2, 元数据备份、恢复

  1. [hdfs@node1 kylin]$ metastore.sh
  2. usage: metastore.sh backup
  3. metastore.sh fetch DATA
  4. metastore.sh reset
  5. metastore.sh refresh-cube-signature
  6. metastore.sh restore PATH_TO_LOCAL_META
  7. metastore.sh list RESOURCE_PATH
  8. metastore.sh cat RESOURCE_PATH
  9. metastore.sh remove RESOURCE_PATH
  10. metastore.sh clean [--delete true]
  11. [hdfs@node1 kylin]$ metastore.sh list /
  12. Starting list /
  13. Retrieving hadoop conf dir......
  14. [/UUID, /acl, /cube, /cube_desc, /cube_statistics, /dict, /execute, /execute_output, /model_desc, /project, /query, /table, /table_exd, /user]
  15. [hdfs@node1 kylin]$ metastore.sh backup
  16. Starting backup to /opt/kylin/meta_backups/meta_2019_04_19_12_11_46.....
  17. [hdfs@node1 kylin]$ ls meta_backups/
  18. meta_2019_04_19_10_29_28 meta_2019_04_19_12_11_46
  19. [hdfs@node1 kylin]$ ls meta_backups/meta_2019_04_19_10_29_28/
  20. acl cube_desc dict execute_output project table user
  21. cube cube_statistics execute model_desc query table_exd UUID
  22. [hdfs@node1 kylin]$ ls meta_backups/meta_2019_04_19_10_29_28/project/
  23. CDR_ADMISSION_INFO.json kylin_demo.json Ys_kylin_Demo.json
  24. [hdfs@node1 kylin]$ ls meta_backups/meta_2019_04_19_10_29_28/cube
  25. aa2423.json aa2.json kylin.json kylinspark.json ys_demo.json

3, 自动构建cube

文档:http://kylin.apache.org/cn/docs/howto/howto_build_cube_with_restapi.html

  • kylin_cube_cron.sh

    !/bin/bash

    set -x

    error_file=/tmp/kylin_error.log
    cubes=(
    cube1
    cube2
    )

    status_check(){

    1. jobid=$1;
    2. error_count=0; try_count=0
    3. while true
    4. do
    5. sleep 20
    6. let try_count++
    7. # look error jobs, resume it!
    8. response=$(curl -s -X GET -H 'Authorization: Basic QURNSU46S1lMSU4=' \ "http://192.168.56.6:7070/kylin/api/jobs/$jobid" )
    9. echo $response |grep -oE job_status.* |grep "FINISHED"
    10. [ $? -eq 0 ] && break
    11. echo $response |grep -oE job_status.* |grep "ERROR"
    12. # try 60 times: 1200 second =20min
    13. if [ $? -eq 0 ] && [ $error_count -le 60 ] ;then
    14. let error_count++
    15. curl -X PUT -H 'Authorization: Basic QURNSU46S1lMSU4=' -H 'Content-Type: application/json' \
    16. -d '{"buildType":"BUILD"}' \
    17. "http://192.168.56.6:7070/kylin/api/jobs/$jobid/resume"
    18. # wait 6 times: 120 second =2 min to finish
    19. elif [ $try_count -ge 6 ] ; then
    20. break
    21. else
    22. continue
    23. fi
    24. done

    }

    curl_build(){

    1. cubeid=$1
    2. #1,build cmd
    3. response=`curl -X PUT -H "Authorization: Basic QURNSU46S1lMSU4=" -H 'Content-Type: application/json' -d '{"buildType":"BUILD"}' \ http://192.168.56.6:7070/kylin/api/cubes/${ cubeid}/rebuild`
    4. #2,resume cmd
    5. jobid=`echo $response |awk -F',' '{print $1}' |grep 'uuid' |awk -F':' '{print $2}' |xargs`
    6. #check if job is error
    7. if [ x$jobid != "x" ] ; then
    8. status_check $jobid
    9. else
    10. echo "$(date '%F %T'), error== $cubeid ==> $response" >> $error_file
    11. fi

    }

  1. for cube in ${cubes[*]}
  2. do
  3. curl_build $cube
  4. done

发表评论

表情:
评论列表 (有 0 条评论,406人围观)

还没有评论,来说两句吧...

相关阅读