1

I am trying to submit a mapreduce job from eclipse to a jobtracker (in this case its running on local machine)

Here is the code

package org.myorg;

import org.apache.hadoop.conf.Configuration;
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.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.apache.hadoop.mapreduce.lib.output.TextOutputFormat;

public class WordCount {

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();

        conf.set("fs.defaultFS", "hdfs://localhost:8020");
        conf.set("mapred.job.tracker", "localhost:8021");

        Job job = new Job(conf, "wordcount");

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

        job.setMapperClass(Map.class);
        job.setReducerClass(Reduce.class);

        job.setInputFormatClass(TextInputFormat.class);
        job.setOutputFormatClass(TextOutputFormat.class);

        FileInputFormat.addInputPath(job, new Path("hdfs://localhost:8020/tmp/nages/cooper.txt"));
        FileOutputFormat.setOutputPath(job, new Path("hdfs://localhost:8020/tmp/nages/output"));

        job.setJarByClass(WordCount.class);     
        job.waitForCompletion(true);
    }

}

Mapper file

package org.myorg;

import java.io.IOException;
import java.util.StringTokenizer;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

public class Map extends Mapper<LongWritable, Text, Text, IntWritable> {
    private final static IntWritable one = new IntWritable(1);
    private Text word = new Text();

    public void map(LongWritable key, Text value, Context context)
            throws IOException, InterruptedException {
        String line = value.toString();
        StringTokenizer tokenizer = new StringTokenizer(line);
        while (tokenizer.hasMoreTokens()) {
            word.set(tokenizer.nextToken());
            context.write(word, one);
        }
    }
}

Reducer file

package org.myorg;

import java.io.IOException;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

public class Reduce extends Reducer<Text, IntWritable, Text, IntWritable> {

    public void reduce(Text key, Iterable<IntWritable> values, Context context)
            throws IOException, InterruptedException {
        int sum = 0;
        for (IntWritable val : values) {
            sum += val.get();
        }
        context.write(key, new IntWritable(sum));
    }
}

I am getting the below error

14/09/23 11:09:41 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
14/09/23 11:09:42 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
14/09/23 11:09:42 WARN mapred.JobClient: No job jar file set.  User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
14/09/23 11:09:42 INFO input.FileInputFormat: Total input paths to process : 1
14/09/23 11:09:42 WARN conf.Configuration: fs.default.name is deprecated. Instead, use fs.defaultFS
14/09/23 11:09:43 INFO mapred.JobClient: Running job: job_201409221650_0012
14/09/23 11:09:44 INFO mapred.JobClient:  map 0% reduce 0%
14/09/23 11:09:50 INFO mapred.JobClient: Task Id : attempt_201409221650_0012_m_000000_0, Status : FAILED
java.lang.RuntimeException: java.lang.ClassNotFoundException: Class org.myorg.Map not found
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1774)
    at org.apache.hadoop.mapreduce.task.JobContextImpl.getMapperClass(JobContextImpl.java:191)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:631)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:330)
    at org.apache.hadoop.mapred.Child$4.run(Child.java:268)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1408)
    at org.apache.hadoop.mapred.Child.main(Child.java:262)
Caused by: java.lang.ClassNotFoundException: Class org.myorg.Map not found
    at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:1680)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:1772)
    ... 8 more

How to resolve this?

Nageswaran
  • 7,481
  • 14
  • 55
  • 74

2 Answers2

0

localhost: checks file in local Filesystem

try to give HDFS ip instead of localhost

config.set("fs.defaultFS", "hdfs://HDFSclusterip:8020/");
config.set("hadoop.job.ugi", "hdfs");

And for input/output too

FileInputFormat.addInputPath(job, new Path("hdfs://HDFSclusterip:8020/tmp/nages/cooper.txt")); FileOutputFormat.setOutputPath(job, new Path("hdfs://HDFSclusterip:8020/tmp/nages/output"));

Let me know if that works.

USB
  • 6,019
  • 15
  • 62
  • 93
  • I'm running HDFS cluster in my local machine. – Nageswaran Sep 23 '14 at 06:52
  • Are all dependencies included? – USB Sep 23 '14 at 07:07
  • Ya, all dependencies are configured in eclipse. Its just a word count program. Just need to patch this 3 classes alone all other dependencies should be available in hadoop cluster. – Nageswaran Sep 23 '14 at 07:59
  • This is a similar question: http://stackoverflow.com/questions/11236305/launch-a-mapreduce-job-from-eclipse?answertab=oldest#tab-top – USB Sep 23 '14 at 08:28
-1

Its jar issue, Map class not found. Add into Driver Code, job.setJarByClass(WordCount.class);

Cheers!

neeraj
  • 890
  • 2
  • 15
  • 22