Oozie调度执行多个Job

  1. 编辑job.properties
     

    #HDFS地址
    nameNode=hdfs://hadoop111:8020
    #ResourceManager地址,默认端口8032
    jobTracker=hadoop112:8032
    #队列名称
    queueName=default
    examplesRoot=oozie-apps
    #这里指定的是job.properties和workflow.xml文件上传到hdfs上的路径
    #结果:http://192.168.191.111:8020/user/kgf/oozie-apps/shell2
    oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/shell2
    

     

  2. 编辑workflow.xml文件

    <workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf">
        <!--开始节点-->
    	<start to="p1-shell-node"/>
    	<!--动作节点1-->
        <action name="p1-shell-node">
            <shell xmlns="uri:oozie:shell-action:0.2">
                <job-tracker>${jobTracker}</job-tracker>
                <name-node>${nameNode}</name-node>
                <configuration>
                    <property>
                        <name>mapred.job.queue.name</name>
                        <value>${queueName}</value>
                    </property>
                </configuration>
                <exec>mkdir</exec>
                <argument>/usr/local/module/OozieTest/shell2</argument>
                <capture-output/>
            </shell>
    		<!--成功后调用动作节点2-->
            <ok to="p2-shell-node"/>
            <error to="fail"/>
        </action>
    	<!--动作节点2-->
        <action name="p2-shell-node">
            <shell xmlns="uri:oozie:shell-action:0.2">
                <job-tracker>${jobTracker}</job-tracker>
                <name-node>${nameNode}</name-node>
                <configuration>
                    <property>
                        <name>mapred.job.queue.name</name>
                        <value>${queueName}</value>
                    </property>
                </configuration>
                <exec>mkdir</exec>
                <argument>/usr/local/module/OozieTest/shell3</argument>
                <capture-output/>
            </shell>
            <ok to="end"/>
            <error to="fail"/>
        </action>
        <kill name="fail">
            <message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
        </kill>
        <end name="end"/>
    </workflow-app>
    

     

  3. 将job.properties文件和workflow.xml文件放到/usr/local/module/oozie-4.0.0-cdh5.3.6/oozie-apps/shell2目录下
     

  4. 将shell2目录文件上传到hdfs上去
     
     

  5. 执行任务,在/usr/local/module/oozie-4.0.0-cdh5.3.6根目录下执行
     命令:bin/oozie job -oozie http://hadoop111:11000/oozie -config oozie-apps/shell2/job.properties -run
     

  6. 注意!!!!!!!!!!
     因为我们是在hadoop集群上运行oozie,那么我们在运行oozie调用shell命令时一定要注意权限的问题,
    比如上面我们执行的是mkdir /usr/local/module/OozieTest/shell3 和 mkdir /usr/local/module/OozieTest/shell2
    但是因为OozieTest这个中间目录不存在,那么我们的hadoop111,hadoop112,hadoop113都要先创建/usr/local/module/OozieTest/
    目录,否则肯定创建失败。

  7. 还有一个带有分支结构的例子如下
    a:job.properties

    #HDFS地址
    nameNode=hdfs://hadoop111:8020
    #ResourceManager地址,默认端口8032
    jobTracker=hadoop112:8032
    #队列名称
    queueName=default
    examplesRoot=oozie-apps
    #这里指定的是job.properties和workflow.xml文件上传到hdfs上的路径
    #结果:http://192.168.191.111:8020/user/kgf/oozie-apps/shell2
    oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/xshell
    


    b:workflow.xml  
       

    <workflow-app xmlns="uri:oozie:workflow:0.4" name="shell-wf">
    <!--开始节点-->
    <start to="p1-shell-node"/>
    <!--动作节点1-->
    <action name="p1-shell-node">
    	<shell xmlns="uri:oozie:shell-action:0.2">
    		<job-tracker>${jobTracker}</job-tracker>
    		<name-node>${nameNode}</name-node>
    		<configuration>
    			<property>
    				<name>mapred.job.queue.name</name>
    				<value>${queueName}</value>
    			</property>
    		</configuration>
    		<exec>mkdir</exec>
    		<argument>/usr/local/module/OozieTest/shell1</argument>
    		<capture-output/>
    	</shell>
    	<ok to="forking"/>
    	<error to="fail"/>
    </action>
    <!--动作节点2-->
    <action name="p2-shell-node">
    	<shell xmlns="uri:oozie:shell-action:0.2">
    		<job-tracker>${jobTracker}</job-tracker>
    		<name-node>${nameNode}</name-node>
    		<configuration>
    			<property>
    				<name>mapred.job.queue.name</name>
    				<value>${queueName}</value>
    			</property>
    		</configuration>
    		<exec>mkdir</exec>
    		<argument>/usr/local/module/OozieTest/shell2</argument>
    		<capture-output/>
    	</shell>
    	<ok to="joining"/>
    	<error to="fail"/>
    </action>
    <!--动作节点3-->
    <action name="p3-shell-node">
    	<shell xmlns="uri:oozie:shell-action:0.2">
    		<job-tracker>${jobTracker}</job-tracker>
    		<name-node>${nameNode}</name-node>
    		<configuration>
    			<property>
    				<name>mapred.job.queue.name</name>
    				<value>${queueName}</value>
    			</property>
    		</configuration>
    		<exec>mkdir</exec>
    		<argument>/usr/local/module/OozieTest/shell3</argument>
    		<capture-output/>
    	</shell>
    	<ok to="joining"/>
    	<error to="fail"/>
    </action>
    <!--动作节点4-->
    <action name="p4-shell-node">
    	<shell xmlns="uri:oozie:shell-action:0.2">
    		<job-tracker>${jobTracker}</job-tracker>
    		<name-node>${nameNode}</name-node>
    		<configuration>
    			<property>
    				<name>mapred.job.queue.name</name>
    				<value>${queueName}</value>
    			</property>
    		</configuration>
    		<exec>mkdir</exec>
    		<argument>/usr/local/module/OozieTest/shell4</argument>
    		<capture-output/>
    	</shell>
    	<ok to="end"/>
    	<error to="fail"/>
    </action>
    <fork name="forking">
            <path start="p2-shell-node"/>
            <path start="p3-shell-node"/>
    </fork>
    <join name="joining" to="p4-shell-node"/>
    <kill name="fail">
    	<message>Shell action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end"/>
    </workflow-app>
    

    c:流程图
      

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值