Oozie调度定时任务的使用方式-05

在执行下面操作之前,首先得配置好oozie的时区,因为它默认时区和咱们时间相差8小时

https://blog.csdn.net/kxj19980524/article/details/89556348  这里面有配置时区的.

拷贝定时器的官方模板到oozie根目录下

nameNode=hdfs://hadoop-senior01.buba.com:8020
jobTracker=hadoop-senior02.buba.com:8032
queueName=default
examplesRoot=oozie-apps

oozie.coord.application.path=${nameNode}/user/${user.name}/${examplesRoot}/apps/cron
#start:必须设置为未来时间,否则任务失败
start=2019-04-27T14:50+0800
end=2019-04-28T17:00+0800
workflowAppUri=${nameNode}/user/${user.name}/${examplesRoot}/cron

EXEC1=p1.sh
EXEC2=p2.sh

<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
  
       http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<!-- 每10分钟执行一次,频率不要低于5分钟以下,不然会出错.因为这一系列是对离线业务进行操作的,不是实时的. -->
<coordinator-app name="cron-coord" frequency="${coord:minutes(10)}" start="${start}" end="${end}" timezone="Asia/Shanghai"
                 xmlns="uri:oozie:coordinator:0.2">
        <action>
		<!-- 指定workflow的文件位置 -->
        <workflow>
            <app-path>${workflowAppUri}</app-path>
            <configuration>
                <property>
                    <name>jobTracker</name>
                    <value>${jobTracker}</value>
                </property>
                <property>
                    <name>nameNode</name>
                    <value>${nameNode}</value>
                </property>
                <property>
                    <name>queueName</name>
                    <value>${queueName}</value>
                </property>
            </configuration>
        </workflow>
    </action>
</coordinator-app>

<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements.  See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership.  The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License.  You may obtain a copy of the License at
  
       http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<workflow-app xmlns="uri:oozie:workflow:0.5" name="one-op-wf">
    <!-- start是先执行名字为shell-node的动作,可以随便起名 -->
    <start to="p1-shell-node"/>
    <action name="p1-shell-node">
        <shell xmlns="uri:oozie:shell-action:0.2">
			<!-- 这边的变量都是引用的job.properties里的变量 -->
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <configuration>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queueName}</value>
                </property>
            </configuration>
			<!-- 把这个改为那边定义的脚本变量 -->
            <exec>${EXEC1}</exec>
            <!-- <argument>my_output=Hello Oozie</argument> -->
			<file>/user/kxj/oozie-apps/shell/${EXEC1}#${EXEC1}</file>
            <capture-output/>
        </shell>
		
		<!-- ok就是如果上面的动作执行成功的话跳转到哪儿,错误的话跳转到哪儿 -->
        <ok to="p2-shell-node"/>
        <error to="fail"/>
    </action>
	
	<action name="p2-shell-node">
        <shell xmlns="uri:oozie:shell-action:0.2">
			<!-- 这边的变量都是引用的job.properties里的变量 -->
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <configuration>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queueName}</value>
                </property>
            </configuration>
			<!-- 把这个改为那边定义的脚本变量 -->
            <exec>${EXEC2}</exec>
            <!-- <argument>my_output=Hello Oozie</argument> -->
			<file>/user/kxj/oozie-apps/shell/${EXEC2}#${EXEC2}</file>
            <capture-output/>
        </shell>
		
		<!-- ok就是如果上面的动作执行成功的话跳转到哪儿,错误的话跳转到哪儿 -->
        <ok to="end"/>
        <error to="fail"/>
    </action>
	
    <decision name="check-output">
        <switch>
            <case to="end">
                ${wf:actionData('shell-node')['my_output'] eq 'Hello Oozie'}
            </case>
            <default to="fail-output"/>
        </switch>
    </decision>
    <kill name="fail">
        <message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <kill name="fail-output">
        <message>Incorrect output, expected [Hello Oozie] but was [${wf:actionData('shell-node')['my_output']}]</message>
    </kill>
    <end name="end"/>
</workflow-app>

执行的任务还是之前执行过的两个shell脚本.在我之前博客里.把这两个脚本复制到cron下面

上传配置文件到hdfs

执行oozie

 bin/oozie job -oozie http://hadoop-senior01.buba.com:11000/oozie -config oozie-apps/cron/job.properties -run

执行完上面运行命令后,不会马上除来job,只有到自己设定的时间后才会出来.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值