一、azkaban使用步骤:
1、创建project文件,文件内容: azkaban-flow-version: 2.0
2、创建flow文件
3、打成zip包,上传web页面
二、flow文件
1、flow文件yml格式,需要遵循以下规则
①、大小写敏感
②、要有缩进,同一个层次,缩进要一样
③、缩进不能使用tab[除非使用yaml语言]
④、属性与值之间通过:分割,:后面要有空格
nodes:
- name: job名称
type: command #command代表使用命令
config:
command: echo “…”
2、配置job的依赖,通过dependsOn配置依赖,因为依赖可以有多个,所以dependsOn是数组结构
nodes:
- name: A
type: command
config:
command: echo “A” #执行的命令 - name: B
type: command
config:
command: echo “B” #执行的命令
dependsOn:
- A #依赖的job名称
3、自动重试
① retries: 重试次数
② retry.backoff: 每次重试的间隔时间
nodes:
- name: A
type: command
config:
command: echo “A” #执行的命令
retries: 3
retry.backoff: 5000 #单位是毫秒
4、公共配置
要求在首行使用config设置公共参数
config:
retries: 3
retry.backoff: 5000 #单位是毫秒
nodes:
- name: A
type: command
config:
command: echo “A” #执行的命令 - name: B
type: command
config:
command: echo “B” #执行的命令
dependsOn:
- A #依赖的job名称
#上述案例代表A、B两个job都有自动重试的功能,重试次数为3,重试间隔为5s
5、流程 相当于job可以是一个内置的流程
nodes:
- name: A
type: command
config:
command: echo “A” #执行的命令 - name: B
type: flow # flow代表当前job是一个内置流程
nodes: #只有type为flow的时候才有
- name: C
type: command
config:
command: echo “C”
6、运行java程序
type:javaprocess 代表运行java程序
java.class 代表运行哪个类[类中要有main方法]
Xmx: 运行最大内存
Xms: 启动内存
Xms、Xmx两个最好设置的一样,能够减少GC次数
nodes:
- name: A
type: javaprocess
config:
java.class: com.atguigu.demo
Xmx: …
Xms: …
7、条件工作流[当前job必须满足某个条件才能够执行]
condition: 条件
7.1、根据脚本中传递的参数来判断
需要将job的参数在脚本中存入azkaban内置变量中,内置变量名: $JOB_OUTPUT_PROP_FILE
后续取job传入的变量: ${job名称:变量名}
nodes:
- name: A
type: command
config:
command: sh a.sh - name: B
type: command
config:
command: echo “B”
condition: ${A:bb}==“BBB” #条件
a.sh脚本内容为:
echo ‘{“bb”:“BBB”}’ >> $JOB_OUTPUT_PROP_FILE
7.2、根据azkaban内置宏
all_done: 所有依赖任务全部完成[kill,failed,success]才能够运行当前job
all_success: 所有依赖任务全部运行成功才能够运行当前Job
all_failed: 所有依赖任务全部运行失败才能够运行当前Job
one_failed: 所有依赖任务中至少有一个运行失败才能够运行当前Job
one_sucess: 所有依赖任务中至少有一个运行成功才能够运行当前Job
nodes:
- name: A
type: command
config:
command: echo “A” #执行的命令 - name: B
type: command
config:
command: echo “B” #执行的命令
dependsOn:
- A
condition: all_success #指定条件
二、json格式:
普通对象: 通过{} 标识
{}中对象的属性名与属性值通过:分割,属性名要用"“引起来。属性值如果是字符串用”"引起来。属性与属性之间通过,分割
Class Person{
private String name;
private int age;
set/get方法
}
Person p = new Person()
p.setName(“zhangsan”)
p.setAge(20)
此时p对象可以通过json字符串表示: {“name”:“zhangsan”,“age”:20}
集合/数组: 通过[]标识
List 用json表示:[“hello”,“word”,".",…]
List 用json表示:[{“name”:“zhangsan”,“age”:20},{“name”:“lisi”,“age”:30},…]
json解析
1、对象转json
JSON.toJsonString(对象)
2、json转对象
JSON.parseObject(json字符串,类.class)
IDEA 工具从Json自动生成JavaBean
1、先安装GsonFormat插件:File–>Setting–>Plugins–>GsonFormat–>OK
2、new 一个新的Class空文件,然后 Alt+Insert组合快捷键,会弹出一个对话框如下。在对话框里面写Json对象。单击OK。
三、http:
get请求:
get请求的时候,参数都是拼在url后面,url与参数通过?分割,参数与参数之间通过&连接,参数与值之间通过=连接,参数与值之间通过
get请求不会向body中传入参数,而且get请求可以直接在浏览器上执行
url=http://localhost:8080/index/login?name=zhangsan&age=20&address=shenzhen
public static String get(String url) throws IOException {
//1、创建HttpClient
HttpClient client = new HttpClient();
//2、创建Method
GetMethod getMethod = new GetMethod(url);
//3、发起请求
//404 - url不存在
//500 - 接口代码报错
//200 - 请求成功
int code = client.executeMethod(getMethod);
//4、判断请求是否成功
//http://localhost:8080/abc/23?yy=zhangsan&name=wangwu
if(code==200){
//5、返回结果
return getMethod.getResponseBodyAsString();
}
return null;
}
post请求:
post请求的时候,参数可以拼在url后面,url与参数通过?分割,参数与参数之间通过&连接,参数与值之间通过=连接,参数与值之间通过
post一般会在body中传入参数,post不可用直接通过浏览器执行
public static string post(String url,String content) throws IOException{
//1、创建HttpClient
HttpClient client = new HttpClient();
//2、创建Method
PostMethod method = new PostMethod(url);
//3、设置body参数
//设置参数
StringRequestEntity entity = new StringRequestEntity(content,"application/json","utf-8");
method.setRequestEntity(entity);
//4、发起请求
int code = client.executeMethod(method);
//5、判断请求是否成功
if(code==200){
//6、返回结果
return method.getResponseBodyAsString();
}
return null;
}