Apache Kylin使用REST api定时构建cube

  • kylin_cube_cron.sh
#!/bin/bash
set -x

resumefile=/tmp/kylin_resume.sh
checkfile=/tmp/kylin_status_check.sh
echo -n "" > $resumefile
echo -n "" > $resumefile

#1,执行cube构建
curl_build(){
        cubeid=$1

        #a,build cmd
        response=`curl -X PUT -H "Authorization: Basic QURNSU46S1lMSU4=" -H 'Content-Type: application/json' -d '{"buildType":"BUILD"}' \
        http://192.168.56.11:7070/kylin/api/cubes/${cubeid}/rebuild`

        #b,resume/check cmd
        jobid=`echo $response |awk -F',' '{print $1}' |awk -F':' '{print $2}' |xargs`

        cat >>        $resumefile <<EOF
                curl -X PUT -H "Authorization: Basic QURNSU46S1lMSU4=" -H 'Content-Type: application/json' -d '{"buildType":"BUILD"}' \
                http://192.168.56.11:7070/kylin/api/jobs/$jobid/resume
EOF

        cat >>        $checkfile <<EOF
                curl -X GET -H "Authorization: Basic QURNSU46S1lMSU4=" \
                http://192.168.56.11:7070/kylin/api/jobs/$jobid
EOF
}

#2,执行任务状态检测
status_check(){
        sleep 600

        while true
        do
           error_count=0
           while read line
           do
              sleep 20

              url=`echo $line|awk '{print $NF}'`
              jobid=`echo ${url##*/}`

              #3,look error jobs, resume it!
              echo $line |bash |grep  -oE job_status.* |grep "ERROR"
              res=$?
              if [ $res -eq 0 ] ;then
                 let error_count++
                 cat $resumefile |grep $jobid |sh
              fi
           done <$checkfile


           #break loop
           [ $error_count -eq 0 ] && break
        done
}

#2.2,状态示例
#[root@hadoop02 ~]# curl -X GET -H "Authorization: Basic QURNSU46S1lMSU4="  http://192.168.56.11:7070/kylin/api/jobs/2cac4a23-03c5-f326-aa8b-3ec5afd352e7 |grep  -oE job_status.*
#job_status":"RUNNING","build_instance":"60738@hadoop02","progress":46.15384615384615}
#
#[root@hadoop02 ~]# curl -X GET -H "Authorization: Basic QURNSU46S1lMSU4="  http://192.168.56.11:7070/kylin/api/jobs/1758a1f0-31e2-b44e-9014-0d469f2634fc |grep  -oE job_status.*
#job_status":"ERROR","build_instance":"60738@hadoop02","progress":6.666666666666667}
#
#[root@hadoop02 ~]# curl -X GET -H "Authorization: Basic QURNSU46S1lMSU4="  http://192.168.56.11:7070/kylin/api/jobs/0d84e166-5e57-a9bc-4416-e539c1d217ad |grep  -oE job_status.*
#job_status":"FINISHED","build_instance":"60738@hadoop02","progress":100.0}

#3,添加要构建的cube
curl_build test_cube1
curl_build test_cube2

#4,job status check
status_check
发布了280 篇原创文章 · 获赞 44 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/eyeofeagle/article/details/105638861