大数据任务调度工具azkaban深入使用

前言

我们使用的是最新版本的azkaban,所编写的调度文件是.flow文件,非常方便,之前使用的job文件一个文件只能写一个任务,但是有了flow文件后可以直接将所有的调度任务写在里面,对于工程级别的项目非常适合

一.flow文件格式(yaml)

flow文件是yaml格式,所以在使用前我先首先介绍一下yaml格式
yaml格式在springboot项目中也经常使用,它是一种全新的配置文件格式,kv格式支持嵌套

1.基本语法

  • 大小写敏感
  • 使用空格缩进
  • 不可使用tab(可以将ide的tab设置成2个或者4个空格)
  • 相同层级左对齐
  • #注释

2.数据类型

  • 对象:kv集合
  • 数组:一个list
  • 纯量:不可再分的值比如boolean,int,string,date,datetime等类型的值

3.对象

# 使用冒号分割,冒号后面有一个空格,多个属性的话保持左侧对齐
person1:
    name: tom
    age: 18
person2:
    name: jack
    age: 19

4.数组

# 一维数组
friend:
    - tom
    - jack
    - dane
# 多维数组
x:
 - 
  - 01
  - 02
  - 03
 - 
  - 11
  - 12
  - 13

5.纯量

包含如下类型:

  • 字符串
  • 布尔值
  • 整数
  • 浮点数
  • Null
  • 时间
  • 日期
boolean: 
    - TRUE  #true,True都可以
    - FALSE  #false,False都可以
float:
    - 3.14
    - 6.8523015e+5  #可以使用科学计数法
int:
    - 123
    - 0b1010_0111_0100_1010_1110    #二进制表示
null:
    nodeName: 'node'
    parent: ~  #使用~表示null
string:
    - 哈哈
    - 'Hello world'  #可以使用双引号或者单引号包裹特殊字符
    - newline
      newline2    #字符串可以拆成多行,每一行会被转化成一个空格
date:
    - 2018-02-17    #日期必须使用ISO 8601格式,即yyyy-MM-dd
datetime: 
    -  2018-02-17T15:02:31+08:00    #时间使用ISO 8601格式,时间和日期之间使用T连接,最后使用+代表时区

6.其他

以上内容均整理自菜鸟教程
跟多详细内容点击以下链接
https://www.runoob.com/w3cnote/yaml-intro.html

二.flow文件编写

1.常见的属性

  • nodes : 任务节点列表
  • name : 任务节点的名称
  • type : 任务节点的类型
  • config : 任务节点的配置
  • command : 需要执行的命令
  • dependsOn :当前节点所依赖的节点

有如上几个属性,几乎大部分的项目都就可以配置了,接下来逐一对每个属性进行解释

2.各个属性的详细解释

nodes

任务节点list,支持嵌套

nodes:
 - name: JobA
   type: command
   config:
    command: echo "JobA"
    # 嵌套任务
 - name: JobB
   type: flow # 这里需要注意的是如果要嵌套一个任务流,这里需要写成flow
   nodes:
     - name: JobBA
       type: command
       config:
        command: echo "JobBA"
     - name: JobBB
       type: command
       config:
        command: echo "JobBB"

name

任务节点的名称,这个没有什么讲的

type

任务节点的类型,azkaban支持多种任务类型,但是其实大部分的类型都可以用command来运行,因为它可以运行shell脚本
一般我们经常写的类型有:

  • command 万金油,大部分任务类型都可以
  • flow 如果要写嵌套的任务,就需要将type写成flow
  • javaprocess java任务类型,其实也可以用command来代替

config

我们可以使用该属性给一个单个任务或者一个任务流做一些配置
如下:
Job config

nodes:
  - name: pigJob
    type: pig
    config:
      pig.script: sql/pig/script.pig

flow config

config:
  user.to.proxy: foo
  failure.emails: noreply@foo.com

nodes:
  - name: jobA
    type: command
    config:
      command: echo "This is an echoed text."

command

当type=command时,我们需要在config属性下加上改属性来说明我们要执行的命令

dependsOn

任务节点之间的依赖关系,是一个数组
例子:

nodes:
 - name: JobA
   type: command
   config:
    command: echo "JobA"
 nodes:
 - name: JobC
   type: command
   config:
    command: echo "JobC"
    # 嵌套任务
 - name: JobB
   type: flow # 这里需要注意的是如果要嵌套一个任务流,这里需要写成flow
   dependsOn:
    - JobA
    - JobC
   nodes:
     - name: JobBA
       type: command
       config:
        command: echo "JobBA"
     - name: JobBB
       type: command
       config:
        command: echo "JobBB"

如上的意思就是JobA和JobC是可以并行执行的,JobB需要等A和C执行完成后才能执行

三.实例

1.shell 脚本任务

test_shell.sh

#! /bin/bash
mkdir test_azkaban
touch test_azkaban/a.txt
pwd
echo "hello azkaban">test_azkaban/a.txt
cat test_azkaban/a.txt

flow20.project

azkaban-flow-version: 2.0

test_shell.flow

nodes:
 - name: test_shell
   type: command
   config:
    command: /bin/bash test_shell/test_shell.sh

文件目录结构

  • test_shell
    • flow20.project
    • test_shell.sh
    • test_shell.flow

将以上文件打成zip包然后上次执行
运行结果:
在这里插入图片描述

2.java任务

helloworld.java

package com.antg.main;

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("hello world");
    }
}

注意:
maven打包的时候加上这个依赖,否则会报清单为找到的错误

<build>
        <plugins>
            <!-- 使用maven-assembly-plugin插件打包 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <archive>
                        <manifest>
                            <!-- 配置入口main方法类所在路径 -->
                            <mainClass>com.antg.main.HelloWorld</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

flow20.project

azkaban-flow-version: 2.0

test_java.flow

nodes:
 - name: test_shell
   type: javaprocess
   config:
    java.class: com.antg.main.HelloWorld
    classpath: test_java/helloworld.jar

目录结构

  • test_java
    • helloworld.jar
    • flow20.project
    • test_java.flow

运行结果
在这里插入图片描述

3.hive任务

我们查询一些信息然后将其落地到本地
test_hive.sh

#! /bin/bash
hive -e"
use dim;
select dic_code,dic_name from dim_column_dictionary_info limit 10;
"

flow20.project

azkaban-flow-version: 2.0

test_hive.flow

nodes:
  - name: test_hive
    type: command
    config:
      command: /bin/bash test_hive/test_hive.sh

目录结构

  • test_hive
    • flow20.project
    • test_hive.sh
    • test_hive.flow

运行结果(其实这个和shell任务一样)
在这里插入图片描述

四.其他

其实大部分的任务我们都可以通过shell来实现,所以这里就不多赘述了
azkaban还支持任务定时执行(在页面上执行即可)和条件执行(condition属性),任务状态邮件通报等功能
这些我们知道就可以了
之前听过前辈说的一句话
懂不懂和听没听过是两个境界
很多时候我们只要知道这个功能可以用什么来实现就好了,技术千千万,学是学不完的
多去了解一些技术,也不用深入,对于自己想要发展的领域,再去深入的探究,要深入到源码级别
当然还有一些计算机的基础知识,比如网络原理,组成原理,操作系统,数据结构等这几个永远是优秀的程序员在修炼的基本功。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Antgeek

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值