如何将javahadoop代码转换为在ec2上运行?

xpcnnkqh  于 2021-06-04  发布在  Hadoop
关注(0)|答案(0)|浏览(216)

我用java编写了一个driver、mapper和reducer类,在测试数据上运行k近邻算法,并使用分布式缓存拉入训练集。我使用了一个cloudera虚拟机来测试代码,它在伪分布式模式下工作。
我正在浏览亚马逊的ec2/emr文档。。。似乎应该有一种方法可以轻松地将工作的javahadoop代码转换成在ec2中工作的代码,但是我看到了一大堆我以前从未见过的自定义amazon导入语句和方法。
以下是我的驱动程序代码示例:

  1. import java.net.URI;
  2. import org.apache.hadoop.conf.Configured;
  3. import org.apache.hadoop.conf.Configuration;
  4. import org.apache.hadoop.filecache.DistributedCache;
  5. import org.apache.hadoop.fs.Path;
  6. import org.apache.hadoop.io.IntWritable;
  7. import org.apache.hadoop.mapreduce.Job;
  8. import org.apache.hadoop.util.Tool;
  9. import org.apache.hadoop.util.ToolRunner;
  10. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  11. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  12. public class KNNDriverEC2 extends Configured implements Tool {
  13. public int run(String[] args) throws Exception {
  14. Configuration conf = new Configuration();
  15. conf.setInt("rows",1000);
  16. conf.setInt("columns",613);
  17. DistributedCache.createSymlink(conf);
  18. // might have to start next line with ./!!!
  19. DistributedCache.addCacheFile(new URI("knn-jg/cache_data/train_sample.csv#train_sample.csv"),conf);
  20. DistributedCache.addCacheFile(new URI("knn-jg/cache_data/train_labels.csv#train_labels.csv"),conf);
  21. //DistributedCache.addCacheFile(new URI("cacheData/train_sample.csv"),conf);
  22. //DistributedCache.addCacheFile(new URI("cacheData/train_labels.csv"),conf);
  23. Job job = new Job(conf);
  24. job.setJarByClass(KNNDriverEC2.class);
  25. job.setJobName("KNN");
  26. FileInputFormat.setInputPaths(job, new Path(args[0]));
  27. FileOutputFormat.setOutputPath(job, new Path(args[1]));
  28. job.setMapperClass(KNNMapperEC2.class);
  29. job.setReducerClass(KNNReducerEC2.class);
  30. // job.setInputFormatClass(KeyValueTextInputFormat.class);
  31. job.setMapOutputKeyClass(IntWritable.class);
  32. job.setMapOutputValueClass(IntWritable.class);
  33. job.setOutputKeyClass(IntWritable.class);
  34. job.setOutputValueClass(IntWritable.class);
  35. boolean success = job.waitForCompletion(true);
  36. return success ? 0 : 1;
  37. }
  38. public static void main(String[] args) throws Exception {
  39. int exitCode = ToolRunner.run(new Configuration(), new KNNDriverEC2(), args);
  40. System.exit(exitCode);
  41. }
  42. }

我已使示例运行,但在“fileinputformat.setinputpaths(job,new path(args[0]);”行引发异常。我将尝试通过文档来处理参数,但是到目前为止,我遇到了太多的错误,我想知道我是否还远远没有做到这一点。谢谢你的帮助。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题