如何将参数传递给Oozie中的mapreduce作业

时间:2015-04-16 21:46:30

标签: hadoop mapreduce oozie oozie-coordinator

我将mapreduce作业打包为jar文件(mymapreduce.jar)。运行时,需要一些参数,例如hadoop jar mymapreduce.jar StartClass -i input -p parameter1 -u parameter2。如何将其作为Oozie工作流文件中的操作编写?

2 个答案:

答案 0 :(得分:1)

在job.properties文件中的oozie工作流中编写要使用的参数,如下所示

 nameNode=hdfs://localhost:9000 
hdfs://abc.xyz.yahoo.com:8020
    jobTracker=localhost:9001        
    queueName=default
    examplesRoot=map-reduce
    oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}
    inputDir=/user/input-data
    outputDir=/user/map-reduce

您可以在workflow.xml中的job.properties中添加配置和变量,如下所示。

<workflow-app name='wordcount-wf' xmlns="uri:oozie:workflow:0.2">
    <start to='wordcount'/>
    <action name='wordcount'>
        <map-reduce>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <prepare>
            </prepare>
            <configuration>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queueName}</value>
                </property>
                <property>
                    <name>mapred.mapper.class</name>
                    <value>org.myorg.WordCount.Map</value>
                </property>
                <property>
                    <name>mapred.reducer.class</name>
                    <value>org.myorg.WordCount.Reduce</value>
                </property>
                <property>
                    <name>mapred.input.dir</name>
                    <value>${inputDir}</value>
                </property>
                <property>
                    <name>mapred.output.dir</name>
                    <value>${outputDir}</value>
                </property>
            </configuration>
        </map-reduce>
        <ok to='end'/>
        <error to='end'/>
    </action>
    <kill name='kill'>
        <value>${wf:errorCode("wordcount")}</value>
    </kill/>
    <end name='end'/>
</workflow-app>

希望这有帮助。

答案 1 :(得分:1)

您可以使用java动作调用mapreduce作业。应将mapreduce驱动程序类指定为main-class。此外,您可以将所需参数作为args传递。参数解析逻辑应在驱动程序类中定义。

<workflow-app name="mapreduce-wf" xmlns="uri:oozie:workflow:0.4">   
    <start to="mapreduce_node"/>
    <action name="mapreduce_node">
       <java>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <main-class>com.test.MyMapreduceDriver</main-class>
            <arg>-i</arg>
            <arg>-p</arg>
            <arg>parameter1</arg>
            <arg>-u</arg>
            <arg>parameter2</arg>
        </java>
        <ok to="end"/>
        <error to="kill"/>
    </action>
    <kill name="kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end"/>
</workflow-app>

另一种选择是将其作为mapreduce操作执行。由于不会指定驱动程序类,因此您可以将所需参数作为配置属性添加到其他mapreduce属性中。您可以使用配置对象在mapper和reducer类中访问这些参数。

<workflow-app name='mapreduce-wf' xmlns="uri:oozie:workflow:0.2">
<start to='mapreduce'/>
<action name='mapreduce'>
    <map-reduce>
        <job-tracker>${jobTracker}</job-tracker>
        <name-node>${nameNode}</name-node>
        <prepare>
        </prepare>
        <configuration>
            <property>
                <name>p</name>
                <value>parameter1</value>
            </property>
             <property>
                <name>u</name>
                <value>parameter2</value>
            </property>
            <property>
                <name>mapred.job.queue.name</name>
                <value>${queueName}</value>
            </property>
            <property>
                <name>mapred.mapper.class</name>
                <value>org.myorg.WordCount.Map</value>
            </property>
            <property>
                <name>mapred.reducer.class</name>
                <value>org.myorg.WordCount.Reduce</value>
            </property>
            <property>
                <name>mapred.input.dir</name>
                <value>${inputDir}</value>
            </property>
            <property>
                <name>mapred.output.dir</name>
                <value>${outputDir}</value>
            </property>
        </configuration>
    </map-reduce>
    <ok to='end'/>
    <error to='end'/>
</action>
<kill name='kill'>
    <value>${wf:errorCode("mapreduce")}</value>
</kill/>
<end name='end'/>
</workflow-app>