package grayscalefromfile_exc;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.File;
import java.util.List;
import java.util.Arrays;
import java.util.Iterator;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;
import org.apache.hadoop.util.GenericOptionsParser;
import hipi.imagebundle.mapreduce.ImageBundleInputFormat;
public class StubDriver extends Configured implements Tool {
public int run(String[] args) throws Exception {
Configuration conf = new Configuration();
String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs();
System.out.println("num of args: " + args.length + ":" + args[0] + "," + args[1]);
if (args.length != 2) {
System.out.println("Usage: dumphib ");
System.exit(0);
}
String inputPath = args[0];
String outputPath = args[1];
Job job = new Job(conf);
job.setJobName("grayscalefromfile_exc");
job.setJarByClass(StubDriver.class);
job.setMapperClass(StubMapper.class);
job.setReducerClass(StubReducer.class);
// Set formats
job.setOutputKeyClass(IntWritable.class);
job.setOutputValueClass(Text.class);
job.setInputFormatClass(ImageBundleInputFormat.class);
// Set out/in paths
removeDir(outputPath, conf);
FileOutputFormat.setOutputPath(job, new Path(outputPath));
FileInputFormat.setInputPaths(job, new Path(inputPath));
job.setNumReduceTasks(1);
System.exit(job.waitForCompletion(true) ? 0 : 1);
return 0;
}
public static void main(String[] args) throws Exception {
int exitCode = ToolRunner.run(new StubDriver(), args);
System.exit(exitCode);
}
public static void removeDir(String path, Configuration conf) throws IOException {
Path output_path = new Path(path);
FileSystem fs = FileSystem.get(conf);
if (fs.exists(output_path)) {
fs.delete(output_path, true);
}
}
}