azkaban使用curl命令对任务进行批量处理

通常,人们希望不必使用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值