Oozie MapReduce Action配置的要点

oozie调度wordcount mapreduce

介绍

创建一个wordcount程序

package com.hadoop.wordcount.mr;

import java.io.IOException;

import javax.naming.spi.DirStateFactory.Result;

import org.apache.commons.collections.map.StaticBucketMap;
import org.apache.hadoop.classification.InterfaceAudience.Private;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Mapper.Context;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.yarn.webapp.hamlet.Hamlet.P;

public class WordCount {

    public static class WordCountMapper extends Mapper<Object, Text, Text, IntWritable>{
        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();

        @Override
        protected void map(Object key, Text value, Context context)
                throws IOException, InterruptedException {
            StringBuilder sBuilder = new StringBuilder(value.toString());
            String[] strings = sBuilder.toString().split("\t");
            for (String tempString: strings){
                word.set(tempString);
                context.write(word, one);
            }

        }

    }


    public static class WordCountReducer extends Reducer<Text, IntWritable, Text, IntWritable>{

        private IntWritable result = new IntWritable();
    @Override
    protected void reduce(Text key, Iterable<IntWritable> values,Context context)
            throws IOException, InterruptedException {


        // TODO Auto-generated method stub
        int sum =0;
        for (IntWritable value : values){
            sum+=value.get();
        }
        result.set(sum);

        context.write(key, result);
    }   

    }


    public static void main(String[] args) throws IOException, InterruptedException, ClassNotFoundException{
        Configuration configuration = new Configuration();
        Job job = Job.getInstance(configuration, "word count");
        job.setJarByClass(WordCount.class);
        job.setMapperClass(WordCountMapper.class);
        job.setCombinerClass(WordCountReducer.class);
        job.setReducerClass(WordCountReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        FileInputFormat.addInputPath(job, new Path(args[0]));
        FileOutputFormat.setOutputPath(job, new Path(args[1]));
        System.exit(job.waitForCompletion(true)?0:1);
    }

}

bin/hdfs dfs -put /opt/jars/file1.txt wordcount/input    
 bin/hadoop jar /opt/jars/mr-wc.jar /user/beifeng/wordcount/input /user/beifeng/wordcount/output1

配置job.properties

nameNode=hdfs://hadoop.beifeng.com:8020
jobTracker=hadoop.beifeng.com:8032
queueName=default
examplesRoot=wordcount

oozie.wf.application.path=${nameNode}/user/${user.name}/${examplesRoot}/oozieapps/map-reduce/workflow.xml
outputDir=map-reduce

配置workflow.xml

<workflow-app xmlns="uri:oozie:workflow:0.5" name="map-reduce-wordcount">
    <start to="mr-node"/>
    <action name="mr-node">
        <map-reduce>
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <prepare>
                <delete path="${nameNode}/user/${wf:user()}/${examplesRoot}/output/${outputDir}"/>
            </prepare>
            <configuration>
                <!--                        mapper properties                         -->
                <property>
                    <name>mapred.mapper.new-api</name>
                    <value>true</value>
                </property>
                <property>
                    <name>mapred.job.queue.name</name>
                    <value>${queueName}</value>
                </property>
                <property>
                    <name>mapreduce.job.map.class</name>
                    <value>com.hadoop.wordcount.mr.WordCount$WordCountMapper</value>
                </property>
                <property>
                    <name>mapreduce.job.output.key.class</name>
                    <value>org.apache.hadoop.io.Text</value>
                </property>
                <property>
                    <name>mapreduce.job.output.value.class</name>
                    <value>org.apache.hadoop.io.IntWritable</value>
                </property>
                <property>
                    <name>mapreduce.input.fileinputformat.inputdir</name>
                    <value>/user/${wf:user()}/${examplesRoot}/input</value>
                </property>
                <!--                         reducer properties                         -->
                <property>
                    <name>mapred.reducer.new-api</name>
                    <value>true</value>
                </property>
                <property>
                    <name>mapreduce.job.reduce.class</name>
                    <value>com.hadoop.wordcount.mr.WordCount$WordCountReducer</value>
                </property>
                <property>
                    <name>mapred.map.tasks</name>
                    <value>1</value>
                </property>
                <property>
                    <name>mapreduce.output.fileoutputformat.outputdir</name>
                    <value>/user/${wf:user()}/${examplesRoot}/output/${outputDir}</value>
                </property>
            </configuration>
        </map-reduce>
        <ok to="end"/>
        <error to="fail"/>
    </action>
    <kill name="fail">
        <message>Map/Reduce failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end"/>
</workflow-app>

测试

bin/oozie job -oozie http://hadoop.beifeng.com:11000/oozie -config oozieapps/map-reduce/job.properties -run

参考资料:

http://blog.csdn.net/nsrainbow/article/details/43746111
http://blog.csdn.net/xiao_jun_0820?viewmode=contents

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值