window intelij 提交mr到y(tǒng)arn集群方法

https://blog.csdn.net/qq_28039433/article/details/78150649
https://blog.csdn.net/u011654631/article/details/70037219

import java.io.IOException;
import java.util.Properties;
import java.util.StringTokenizer;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hdfs.server.namenode.top.window.RollingWindowManager;
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.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.GenericOptionsParser;

import static org.apache.hadoop.security.UserGroupInformation.isSecurityEnabled;

public class WordCount {

    public static class TokenizerMapper
            extends Mapper<Object, Text, Text, IntWritable> {

        private final static IntWritable one = new IntWritable(1);
        private Text word = new Text();

        public void map(Object key, Text value, Context context) throws IOException, InterruptedException {
            StringTokenizer itr = new StringTokenizer(value.toString());
            while (itr.hasMoreTokens()) {
                word.set(itr.nextToken());
                context.write(word, one);
            }
        }
    }

    public static class IntSumReducer extends Reducer<Text, IntWritable, Text, IntWritable> {
        private IntWritable result = new IntWritable();

        public void reduce(Text key, Iterable<IntWritable> values, Context context) throws IOException, InterruptedException {
            int sum = 0;
            for (IntWritable val : values) {
                sum += val.get();
            }
            result.set(sum);
            context.write(key, result);
        }
    }

    public static void main(String[] args) throws Exception {
        System.setProperty("HADOOP_USER_NAME", "hadoop3");
        System.setProperty("hadoop.home.dir", "d:\\hadoop-2.8.3");
        Configuration conf = new Configuration();
        conf.set("fs.default.name", "hdfs://192.168.47.140:8020");

//        conf.set("hadoop.job.user", "Administrator");
        conf.set("mapreduce.app-submission.cross-platform", "true");
        conf.set("mapreduce.framework.name", "yarn");
        conf.set("mapred.jar","C:\\Users\\Administrator\\IdeaProjects\\mavenYarn\\out\\artifacts\\mavenYarn_jar\\mavenYarn.jar");
        String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
        if (otherArgs.length < 2) {
            System.err.println("Usage: wordcount <in> [<in>...] <out>");
            System.exit(2);
        }
        Job job = Job.getInstance(conf, "word count");
        job.setJarByClass(WordCount.class);
        job.setMapperClass(TokenizerMapper.class);
        job.setCombinerClass(IntSumReducer.class);
        job.setReducerClass(IntSumReducer.class);
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(IntWritable.class);
        for (int i = 0; i < otherArgs.length - 1; ++i) {
            FileInputFormat.addInputPath(job, new Path(otherArgs[i]));
        }
        FileOutputFormat.setOutputPath(job,
                new Path(otherArgs[otherArgs.length - 1]));
        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市拓春,隨后出現(xiàn)的幾起案子释簿,更是在濱河造成了極大的恐慌,老刑警劉巖硼莽,帶你破解...
    沈念sama閱讀 218,941評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件庶溶,死亡現(xiàn)場離奇詭異,居然都是意外死亡懂鸵,警方通過查閱死者的電腦和手機偏螺,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,397評論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來匆光,“玉大人套像,你說我怎么就攤上這事≈障ⅲ” “怎么了夺巩?”我有些...
    開封第一講書人閱讀 165,345評論 0 356
  • 文/不壞的土叔 我叫張陵贞让,是天一觀的道長。 經(jīng)常有香客問我柳譬,道長喳张,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,851評論 1 295
  • 正文 為了忘掉前任征绎,我火速辦了婚禮蹲姐,結(jié)果婚禮上磨取,老公的妹妹穿的比我還像新娘人柿。我一直安慰自己,他們只是感情好忙厌,可當(dāng)我...
    茶點故事閱讀 67,868評論 6 392
  • 文/花漫 我一把揭開白布凫岖。 她就那樣靜靜地躺著,像睡著了一般逢净。 火紅的嫁衣襯著肌膚如雪哥放。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,688評論 1 305
  • 那天爹土,我揣著相機與錄音甥雕,去河邊找鬼。 笑死胀茵,一個胖子當(dāng)著我的面吹牛社露,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播琼娘,決...
    沈念sama閱讀 40,414評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼峭弟,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了脱拼?” 一聲冷哼從身側(cè)響起瞒瘸,我...
    開封第一講書人閱讀 39,319評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎熄浓,沒想到半個月后情臭,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,775評論 1 315
  • 正文 獨居荒郊野嶺守林人離奇死亡赌蔑,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,945評論 3 336
  • 正文 我和宋清朗相戀三年谎柄,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片惯雳。...
    茶點故事閱讀 40,096評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡朝巫,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出石景,到底是詐尸還是另有隱情劈猿,我是刑警寧澤拙吉,帶...
    沈念sama閱讀 35,789評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站揪荣,受9級特大地震影響筷黔,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜仗颈,卻給世界環(huán)境...
    茶點故事閱讀 41,437評論 3 331
  • 文/蒙蒙 一佛舱、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧挨决,春花似錦请祖、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,993評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至盖高,卻和暖如春慎陵,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背喻奥。 一陣腳步聲響...
    開封第一講書人閱讀 33,107評論 1 271
  • 我被黑心中介騙來泰國打工席纽, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人撞蚕。 一個月前我還...
    沈念sama閱讀 48,308評論 3 372
  • 正文 我出身青樓润梯,卻偏偏與公主長得像,于是被迫代替她去往敵國和親诈豌。 傳聞我的和親對象是個殘疾皇子仆救,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,037評論 2 355

推薦閱讀更多精彩內(nèi)容