Hadoop Jar运行但没有输出.驱动程序、映射程序和reduce在namenode中成功编译



我是Hadoop编程的新手,通过在三节点集群上设置Hadoop2.7.1开始学习。我尝试过在Hadoop中运行开箱即用的helloworld jar,它运行得很好,很成功,但我在本地机器中编写了自己的驱动程序代码,并将其捆绑到一个jar中,以这种方式执行,但它失败了,没有错误消息。

这是我的代码,这就是我所做的。

WordCountMapper.java

package mot.com.bin.test;
import java.io.IOException;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.Mapper;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;

public class WordCountMapper  extends MapReduceBase implements Mapper<LongWritable, Text, Text, IntWritable>
{
public void map(LongWritable key, Text Value,
OutputCollector<Text, IntWritable> opc, Reporter r)
throws IOException {
String s = Value.toString();
for (String word :s.split(" ")) {
if( word.length() > 0) {
opc.collect(new Text(word), new IntWritable(1));
}
}
}

}

WordCountReduce.java

package mot.com.bin.test;
import java.io.IOException;
import java.util.Iterator;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapReduceBase;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reducer;
import org.apache.hadoop.mapred.Reporter;
public class WordCountReduce  extends MapReduceBase implements Reducer < Text, IntWritable, Text, IntWritable>{
public void reduce(Text key, Iterator<IntWritable> values,
OutputCollector<Text, IntWritable> opc, Reporter r)
throws IOException {
// TODO Auto-generated method stub
int i = 0;
while (values.hasNext()) {
IntWritable in = values.next();
i+=in.get();
}
opc.collect(key, new IntWritable (i));
}

WordCount.java

/**
* **DRIVER**
*/
package mot.com.bin.test;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.mapred.FileInputFormat;
import org.apache.hadoop.mapred.FileOutputFormat;
import org.apache.hadoop.mapred.JobClient;
import org.apache.hadoop.mapred.JobConf;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.io.Text;
//import com.sun.jersey.core.impl.provider.entity.XMLJAXBElementProvider.Text;
/**
* @author rgb764
*
*/
public class WordCount extends Configured implements Tool{
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
}
public int run(String[] arg0) throws Exception {
if (arg0.length < 2) {
System.out.println("Need input file and output directory");
return -1;
}
JobConf conf = new JobConf();
FileInputFormat.setInputPaths(conf, new Path( arg0[0]));
FileOutputFormat.setOutputPath(conf, new Path( arg0[1]));
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
conf.setMapperClass(WordCountMapper.class);
conf.setReducerClass(WordCountReduce.class);
conf.setOutputKeyClass(Text.class);
conf.setOutputValueClass(IntWritable.class);
JobClient.runJob(conf);
return 0;
}
}

首先,我尝试将它从eclipse中提取为一个jar,并在我的hadoop集群中运行它。没有错误,也没有成功。然后将我的各个java文件移动到我的NameNode,编译每个java文件,然后在那里创建jar文件,hadoop命令仍然不会返回任何结果,但也不会返回任何错误。请帮我做这件事。

hadoop jar WordCout.jar mot.com.bin.test.WordCount /karthik/mytext.txt /tempo

使用Maven提取了所有依赖的jar文件,并将它们添加到我的name节点中的类路径中。帮我弄清楚哪里出了问题。

IMO您的主方法中缺少实例化Tool实现(在您的情况下为WordCount)并运行相同的代码。

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

请参阅此。

最新更新