Azkaban 外部接口的使用与开发

Azkaban 外部接口的使用与开发

此文档可用于Azkaban 任务的https调用,提供了查看任务的状态信息、执行情况、任务的创建、上传、触发、取消、调度等功能接口。可以使开发者在编程过程中直接通过https api的调用,来对任务进行控制,开发者可参考azkaban官网提供的api文档。

azkaban官网提供的api文档:https://azkaban.github.io/azkaban/docs/latest/#ajax-api

API调研结果:

功能是否支持
java api调用支持(https调用开发)
curl  api调用支持
支持https支持
需要认证需要,简单的session会话开发认证(session 24小时过期时间,重复调用上次session会被覆盖)
项目的创建、删除支持
任务的上传支持
任务流的触发、取消、暂停、恢复支持
任务流状态信息的获取支持(所有执行状态都可获取,执行中、执行完的状态)
单个job的执行支持(使用禁用模式)
SLA警报和自动查杀失败任务支持(包括邮件的设置等)
cron定时设置支持
探究中 

如下是对于Api简单Demo。

使用Hutool工具,直接进行https调用,pom

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.5.1</version>
 </dependency>

一、认证

获取session.id,在调用接口时,都会进行session.id的认证,获取到的session.id过期时间为24小时。当会话进行退出、机器关机、切换机器、改变浏览器等操作时,session将会失效。若session.id已过期则重新进行获取即可,应为新会话将覆盖老会话。

请求体【请求方式:post】

ParameterDescription
action=loginThe fixed parameter indicating the login action.
usernameThe Azkaban username.
passwordThe corresponding password.

代码示例:

String body = HttpRequest.post("https://localhost:8443")
                .body("action=login&username=azkaban&password=azkaban")
                .execute()
                .body();
        System.out.println(body);

响应体:

ParameterDescription
errorReturn an error message if the login attempt fails.
session.idReturn a session id if the login attempt succeeds.
{
  "status" : "success",
  "session.id" : "c001aba5-a90f-4daf-8f11-62330d034c0a"
}

二、远程创建一个任务项目

在上传任务zip包时,进行远程创建任务姓名。

请求体

arameterDescription
session.id

The user session id.(会话id)

action=createThe fixed parameter indicating the create project action. (执行任务的动作)
nameThe project name to be uploaded.(项目名)
descriptionThe description for the project. This field cannot be empty.(项目描述)

代码示例:

String body = HttpRequest.post("https://localhost:8443/manager?action=create")
                .body("session.id=9089beb2-576d-47e3-b040-86dbdc7f523e&name=aaaa&description=11")
                .execute()
                .body();
        System.out.println(body);

响应体 (创建失败):

ParameterDescription
messageThe error message.
errorThe error name.
{
  "status":"success",
  "path":"manager?project=aaaa",
  "action":"redirect"
}

三、删除一个任务项目

请求体:

ParameterDescription
session.id

The user session id.

delete=trueThe fixed parameter to indicate the deleting project action.
projectThe project name to be deleted.

代码示例:

HttpRequest.get("https://localhost:8443/manager")
                .body("session.id=bca1d75d-6bae-4163-a5b0-378a7d7b5a91&delete=true&project=test-delete-project")
                .execute();

四、获取项目中的流

azkaban一个项目中可以创建多个流并且每个流中又含有多个依赖job,在此只能获取流

请求参数:

ParameterDescription
session.id

The user session id.

ajax=fetchprojectflowsThe fixed parameter indicating the fetchProjectFlows action.
projectThe project name to be fetched.

示例代码:

String body = HttpRequest.get("https://localhost:8443/manager")
                .body("session.id=6c96e7d8-4df5-470d-88fe-259392c09eea&ajax=fetchprojectflows&project=azkaban-test-project")
                .execute()
                .body();
        System.out.println(body);

响应体:

ParameterDescription
projectThe project name.
projectIdThe numerical id of the project.
flowsA list of flow ids.(任务流的id)

Example values: [{"flowId": "aaa"}, {"flowId": "bbb"}]

{
  "project" : "test-azkaban",
  "projectId" : 192,
  "flows" : [ {
    "flowId" : "test"
  }, {
    "flowId" : "test2"
  } ]
}

五、从流中获取job

azkaban一个项目中可以创建多个流并且每个流中又含有多个依赖job,在此可以获取流以及所有jobs

请求体:

ParameterDescription
session.id

The user session id.

ajax=fetchflowgraphThe fixed parameter indicating the fetchProjectFlows action.
projectThe project name to be fetched.
flowThe project id to be fetched.(返回参数中,含有每个流下所依赖的job id)

示例代码:

String body = HttpRequest.get("https://localhost:8443/manager")
                .body("session.id=bca1d75d-6bae-4163-a5b0-378a7d7b5a91&ajax=fetchflowgraph&project=texter-1-1&flow=test")
                .execute()
                .body();

响应体:

ParameterDescription
projectThe project name.
projectIdThe numerical id of the project.
flowThe flow id fetched.
nodesA list of job nodes belonging to this flow.

Structure:

{
  "id": "job.id"
  "type": "job.type"
  "in": ["job.ids that this job is directly depending upon.
  Indirect ancestors is not included in this list"]
}
                  

 

Example values: [{"id": "first_job", "type": "java"}, {"id": "second_job", "type": "command", "in":["first_job"]}]

{
  "project" : "azkaban-test-project",
  "nodes" : [ {
    "id" : "test-final",
    "type" : "command",
    "in" : [ "test-job-3" ]
  }, {
    "id" : "test-job-start",
    "type" : "java"
  }, {
    "id" : "test-job-3",
    "type" : "java",
    "in" : [ "test-job-2" ]
  }, {
    "id" : "test-job-2",
    "type" : "java",
    "in" : [ "test-job-start" ]
  } ],
  "flow" : "test",
  "projectId" : 192
}

六、执行流

此api可对流进行执行,也对流中的单独的job进行触发

请求参数:

ParameterDescription
session.id

The user session id. (所获取的会话id)

Example Values: 30d538e2-4794-4e7e-8a35-25a9e2fd5300

ajax=executeFlow

The fixed parameter indicating the current ajax action is executeFlow.

project

The project name of the executing flow. (流所在的项目名)

Example Values: run-all-jobs

flow

The flow id to be executed.(需要执行的流)

Example Values: test-flow

disabled (optional)

A list of job names that should be disabled for this execution. Should be formatted as a JSON Array String.

(禁用需要执行的jobs,当一个流中有a,b,c三个依赖job时,若单独执行一个,可将其他两个禁用即可)

Example Values: ["job_name_1", "job_name_2", "job_name_N"]

successEmails (optional)

A list of emails to be notified if the execution succeeds. All emails are delimitted with [,|;|\\s+].

Example Values: foo@email.com,bar@email.com

failureEmails (optional)

A list of emails to be notified if the execution fails. All emails are delimitted with [,|;|\\s+].

Example Values: foo@email.com,bar@email.com

successEmailsOverride (optional)

Whether uses system default email settings to override successEmails.

Possible Values: true, false

failureEmailsOverride (optional)

Whether uses system default email settings to override failureEmails.

Possible Values: true, false

notifyFailureFirst (optional)

Whether sends out email notifications as long as the first failure occurs.

Possible Values: true, false

notifyFailureLast (optional)

Whether sends out email notifications as long as the last failure occurs.

Possible Values: true, false

failureAction (Optional)

If a failure occurs, how should the execution behaves.如果发生故障,执行应该如何表现【认为当前是成功或者取消流的执行】

Possible Values: finishCurrent, cancelImmediately, finishPossible

concurrentOption (Optional)

Concurrent choices. Use ignore if nothing specifical is required.

Possible Values: ignore, pipeline, skip

flowOverride[flowProperty] (Optional)

Override specified flow property with specified value.

Example Values : flowOverride[failure.email]=test@gmail.com

代码示例:

String body = HttpRequest.get("https://localhost:8443/executor")
                .body("session.id=189b956b-f39f-421e-9a95-e3117e7543c9&ajax=executeFlow&project=azkaban-test-project&flow=test")
                .execute()
                .body();
        System.out.println(body);

响应体:

ParameterDescription
errorError message if the call has failed
flowThe executed flow id
execidThe execution id
{
  message: "Execution submitted successfully with exec id 295",
  project: "foo-demo",
  flow: "test",
  execid: 295
}

七、取消流的执行

若未运行,则返回错误信息,成功则无返回

请求体:

ParameterDescription
session.id

The user session id.

ajax=cancelFlow

The fixed parameter indicating the current ajax action is cancelFlow.

execid

The execution id.【执行id,当job执行时,生成的唯一id】

代码示例:

String body = HttpRequest.get("https://localhost:8443/executor")
                .body("session.id=34ba08fd-5cfa-4b65-94c4-9117aee48dda&ajax=cancelFlow&execid=302")
                .execute()
                .body();
        System.out.println(body);

响应体(失败状态):

{
  "error" : "Execution 302 of flow test isn't running."
}

注意:

在开发者进行调用时api调用时,Azkaban管理员创建的project其他角色无法访问。

 

以上是提取了常用的api方法,若需更全的api使用可以查看官网 https://azkaban.github.io/azkaban/docs/latest/#ajax-api

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值