JobControl的使用及获取计数器
生活随笔
收集整理的這篇文章主要介紹了
JobControl的使用及获取计数器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
JobControl的使用##
####1.JobControl配置 ##
//1.首先聲明一個JobControl JobControl jobControl = new JobControl("groupName");//2.然后寫conf的配置 Configuration conf = new Configuration(); conf.set("name","value"); ...省略配置......一般這里會判斷輸出路徑是否存在... FileSystem fileSystem = FileSystem.get(new Configuration()); if (fileSystem.exists(new Path(outputPath))) {LOG.warn("output: " + outputPath + " already exists! DELETE");fileSystem.delete(new Path(outputPath), true);}//3.開始寫job配置 Job job = Job.getInstance(conf);trackViewJob.setJarByClass(xxx.class);trackViewJob.setJobName("jobName");trackViewJob.setInputFormatClass(OrcNewInputFormat.class);for(String date: dateList) {//這里最好加一個輸入路徑是否存在的判斷MultipleInputs.addInputPath(job, new Path(inputPath), RCFileMapReduceInputFormat.class, TrackDataMapper.class);}job.setMapperClass(TrackDataMapper.class);job.setReducerClass(TrackDataReducer.class);job.setMapOutputKeyClass(TextTuple.class);job.setMapOutputValueClass(TextTuple.class);job.setNumReduceTasks(5000);job.setOutputKeyClass(TextTuple.class);job.setOutputValueClass(TextTuple.class);job.setOutputFormatClass(SequenceFileOutputFormat.class);SequenceFileOutputFormat.setOutputPath(job, new Path(outputPath));//4.job寫完,創建ControlledJob//job加入ControlledJob ControlledJob cj = new ControlledJob(conf);cj.setJob(job); //5.如果有其他依賴,則把依賴寫在這里,例如cj.addDependingJob(other_cj1);cj.addDependingJob(other_cj2);//表示當前cj依賴于其他other_cj完成,他才能提交運行,有多個就add多個//如果他不需要其他程序運行完在運行,則這里可以不寫//6.把剛創建的 ControlledJob加入 JobControljobControl.addJob(cj);以上完成JobControl配置 下面運行####2.JobControl運行 ##
應該有直接運行的方法。下面是自己寫的方法
直接貼代碼了,不多說。
調用方法:
boolean res = RunTool.runJobControll(job, true);
####3.JobControl成功或失敗判斷 ##
if (res) {//成功,獲取計數器的值List<ControlledJob> finishList = job.getSuccessfulJobList();for (ControlledJob controlledJob : finishList) {Counters counters = controlledJob.getJob().getCounters(); //**下面這部分輸出所有的計數器,調試用,不管什么,大大小小的統計一并輸出Iterable<String> gcList = counters.getGroupNames(); //獲取所有計數器名字for (String counter_name : gcList) {CounterGroup gc = counters.getGroup(counter_name);cnt.add( counter_name +"# start ~~~~~");for (Counter counter : gc) {cnt.add( counter.getName() +"#"+counter.getValue());LOG.info( counter.getName() + "\t" + counter.getValue() );}cnt.add( counter_name +"# end ~~~~~");}/**最終要的結果,只有每部分輸出以及最終輸出統計CounterGroup gc = counters.getGroup(Consts.COUNTER_NAME);for (Counter counter : gc) {cnt.add( counter.getName() +"#"+counter.getValue());LOG.info( counter.getName() + "\t" + counter.getValue() );}**/ }}else {//失敗,獲取失敗的任務名字List<ControlledJob> failedList = job.getFailedJobList();for (ControlledJob fail : failedList) {failed.add( fail.getJob().getJobName() );LOG.info("### Failed:\t" + fail.getJob().getJobName());}}如果是多線程,那么需要一個鎖。
synchronized (this) {isSucc = res;isFinished = true;}####4.JobControl獲取計數器值 ##
代碼在3中都有,既可以獲取指定計數器的值,也可以獲取所有mapreduce 計數器的值
總結
以上是生活随笔為你收集整理的JobControl的使用及获取计数器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux内核 checksum,Che
- 下一篇: 智能开发——蓝牙宠物喂食器方案