2013-10-18 30 views
1

我有如下需求: 1)有30個節點的hadoop YARN集羣和一個用於作業提交的客戶機。 2)讓我們使用wordcount MR例子,因爲它是世界聞名的。我想從java方法提交併運行wordcount MR作業。如何從Java代碼運行hadoop紗線上的字數統計作業?

那麼提交工作需要什麼代碼?客戶機上配置的任何特定內容?

感謝您的幫助提前。

回答

0

Hadoop應該出現在您的客戶端機器上,其配置與hadoop羣集中的其他機器相同。

要從java方法提交MR作業,請參閱java ProcessBuilder並通過hadoop命令啓動您的wordcount示例。

的命令和單詞計數必要的應用程序的具體要求可以發現here

0

您應該實現工具類。這裏有一個例子:

public class AggregateJob extends Configured implements Tool { 

    @Override 
    public int run(String[] args) throws Exception { 
    Job job = new Job(getConf()); 
    job.setJarByClass(getClass()); 
    job.setJobName(getClass().getSimpleName()); 

    FileInputFormat.addInputPath(job, new Path(args[0])); 
    FileOutputFormat.setOutputPath(job, new Path(args[1])); 

    job.setMapperClass(ProjectionMapper.class); 
    job.setCombinerClass(LongSumReducer.class); 
    job.setReducerClass(LongSumReducer.class); 

    job.setOutputKeyClass(Text.class); 
    job.setOutputValueClass(LongWritable.class); 

    return job.waitForCompletion(true) ? 0 : 1; 
    } 

    public static void main(String[] args) throws Exception { 
    int rc = ToolRunner.run(new AggregateJob(), args); 
    System.exit(rc); 
    } 
} 

這個例子是從here獲得的。正如@ hamsa-zafar所說的那樣,客戶端機器應該有集羣中其他節點的hadoop配置。

相關問題