Want more features on Pastebin? Sign Up, it's FREE!
Guest

user1271518

By: a guest on May 8th, 2012  |  syntax: None  |  size: 2.31 KB  |  views: 30  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package grayscalefromfile_exc;
  2.  
  3. import java.io.IOException;
  4. import java.io.FileInputStream;
  5. import java.io.File;
  6. import java.util.List;
  7. import java.util.Arrays;
  8. import java.util.Iterator;
  9.  
  10. import org.apache.hadoop.conf.Configuration;
  11. import org.apache.hadoop.conf.Configured;
  12. import org.apache.hadoop.fs.FileSystem;
  13. import org.apache.hadoop.fs.Path;
  14. import org.apache.hadoop.io.IntWritable;
  15. import org.apache.hadoop.io.Text;
  16. import org.apache.hadoop.mapreduce.Job;
  17. import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
  18. import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
  19. import org.apache.hadoop.util.Tool;
  20. import org.apache.hadoop.util.ToolRunner;
  21. import org.apache.hadoop.util.GenericOptionsParser;
  22.  
  23. import hipi.imagebundle.mapreduce.ImageBundleInputFormat;
  24.  
  25.  
  26. public class StubDriver extends Configured implements Tool {
  27.         public int run(String[] args) throws Exception {
  28.                
  29.                 Configuration conf = new Configuration();
  30.                 String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
  31.                
  32.                 System.out.println("num of args: " + args.length + ":" + args[0] + "," + args[1]);
  33.                
  34.                 if (args.length != 2) {
  35.                         System.out.println("Usage: dumphib <input hib> <outputdir>");
  36.                         System.exit(0);
  37.                 }
  38.                 String inputPath = args[0];
  39.                 String outputPath = args[1];
  40.                
  41.                 Job job = new Job(conf);
  42.                 job.setJobName("grayscalefromfile_exc");
  43.  
  44.                 job.setJarByClass(StubDriver.class);
  45.                 job.setMapperClass(StubMapper.class);
  46.                 job.setReducerClass(StubReducer.class);
  47.  
  48.                 // Set formats
  49.                 job.setOutputKeyClass(IntWritable.class);
  50.                 job.setOutputValueClass(Text.class);
  51.                 job.setInputFormatClass(ImageBundleInputFormat.class);
  52.  
  53.                 // Set out/in paths
  54.                 removeDir(outputPath, conf);
  55.                 FileOutputFormat.setOutputPath(job, new Path(outputPath));
  56.                 FileInputFormat.setInputPaths(job, new Path(inputPath));       
  57.  
  58.                 job.setNumReduceTasks(1);
  59.                 System.exit(job.waitForCompletion(true) ? 0 : 1);
  60.                 return 0;
  61.  
  62.         }
  63.  
  64.         public static void main(String[] args) throws Exception {
  65.                 int exitCode = ToolRunner.run(new StubDriver(), args);
  66.                 System.exit(exitCode);
  67.         }
  68.  
  69.         public static void removeDir(String path, Configuration conf) throws IOException {
  70.                 Path output_path = new Path(path);
  71.  
  72.                 FileSystem fs = FileSystem.get(conf);
  73.  
  74.                 if (fs.exists(output_path)) {
  75.                         fs.delete(output_path, true);
  76.                 }
  77.         }
  78. }
clone this paste RAW Paste Data