Hadoop实战之多个job在同一个main方法中提交

有两种方式,一般是用shell脚本。还可以在main函数中编写,例如:

	public static void main(String[] args) throws Exception {

		Configuration conf = new Configuration();	
		
		//先构造job_one
		Job job_one = Job.getInstance(conf);
		
		job_one.setJarByClass(InverseIndexStepTwo.class);
		job_one.setMapperClass(StepOneMapper.class);
		job_one.setReducerClass(StepOneReducer.class);
		//......
		
		
		//构造job_two
		Job job_tow = Job.getInstance(conf);
		
		job_tow.setJarByClass(InverseIndexStepTwo.class);
		
		job_tow.setMapperClass(StepTwoMapper.class);
		job_tow.setReducerClass(StepTwoReducer.class);
		
		job_tow.setOutputKeyClass(Text.class);
		job_tow.setOutputValueClass(Text.class);
		
		FileInputFormat.setInputPaths(job_tow, new Path(args[0]));
		
		//检查一下参数所指定的输出路径是否存在,如果已存在,先删除
		Path output = new Path(args[1]);
		FileSystem fs = FileSystem.get(conf);
		if(fs.exists(output)){
			fs.delete(output, true);
		}
		
		FileOutputFormat.setOutputPath(job_tow, output);
		
		
		//先提交job_one执行
		boolean one_result = job_one.waitForCompletion(true);
		if(one_result){
		System.exit(job_tow.waitForCompletion(true)?0:1);
		}
		
	}

猜你喜欢

转载自blog.csdn.net/ZG_24/article/details/80689950
今日推荐