通常,人们希望不必使用Web UI就可以与Azkaban进行交互。Azkaban有一些公开的ajax调用,可以通过curl或其他一些HTTP请求客户端进行访问。所有API调用都首先需要正确的身份验证。
1.认证
通过curl对azkaban的任务进行调度,首先需要登录鉴权。登录成功后返回一个session.id,以后通过session.id进行身份验证。因此每次使用curl指令除了登录操作,其他都需要这个参数。
curl -k -X POST --data "action=login&username=azkaban&password=syswinazkaban" https://localhost:8443
样本响应:
{
“ status”:“成功”,
“ session.id”:“ c001aba5-a90f-4daf-8f11-62330d034c0a”
}
2.执行任务
2.1执行不带参数的任务
curl -k --get --data 'session.id=c001aba5-a90f-4daf-8f11-62330d034c0a' --data 'ajax=executeFlow' --data 'project=test' --data 'flow=persona_end' https://localhost:8443/executor
2.2执行带参数的任务
curl -k --data "session.id=f5d22af3-abf0-4418-a0cc-445973115d94&ajax=executeFlow&flowOverride[yesterday]=20210128&project=test&flow=test_end" https://localhost:8443/executor?ajax=executeFlow
样本回复:
{
消息:“执行已成功提交,其exec ID为295”,
项目:“ test”,
流:“测试”,
execid:295
}
3.shell脚本批量执行
#!/bin/bash
in_date=$1
if [ ! $in_date ]; then
yesterday=`date -d "yesterday" '+%Y%m%d'`
yesterday1=`date -d "yesterday" '+%Y-%m-%d'`
else
yesterday=$in_date
yesterday1=`date -d "$in_date" '+%Y-%m-%d'`
fi
echo $yesterday
echo $yesterday1
curl -k --data "session.id=f5d22af3-abf0-4418-a0cc-445973115d94&ajax=executeFlow&flowOverride[yesterday]='$yesterday'&project=test&flow=test_end" https://localhost:8443/executor?ajax=executeFlow
sleep 30m
#根据项目的实际情况设置休眠间隔
curl -k --data "session.id=f5d22af3-abf0-4418-a0cc-445973115d94&ajax=executeFlow&flowOverride[yesterday]='$yesterday'&project=test1&flow=test1_end" https://localhost:8443/executor?ajax=executeFlow
sleep 1h
curl -k --data "session.id=f5d22af3-abf0-4418-a0cc-445973115d94&ajax=executeFlow&flowOverride[yesterday]='$yesterday'&project=test2&flow=test2_end" https://localhost:8443/executor?ajax=executeFlow
使用curl可以对azkaban的job进行很多的操作,比如创建项目,获取流执行任务等等,具体可以参考https://azkaban.github.io/azkaban/docs/latest/#ajax-api