I'm using hdp 2.6 and hbase1.1.2.
When I submit a map-reduce job from a server which is not in the hdp cluster,
I got the following exception:
Class org.apache.hadoop.hbase.mapreduce.TableOutputFormat not found.
My mapper finished correctly under local job mode and I'm really sure that this class is in my classpath and lib in cluster has this jar either.
I googled several steps that others did:
1. use -libjars
2. add hbase_classpath to hadoop.env and restart the cluster
3. add hbase-master/lib to yarn-site.xml and restart the cluster
But these don't work. Plz help me cause I can only use mr to do this task.
Here are my codes:
package com.test.service;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.mapreduce.ImportTsv;
import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.util.ToolRunner;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class Tsv2HBaseService {
private org.apache.hadoop.conf.Configuration config;
private String principle;
private String keytab;
Tsv2HBaseService(@Value("${hbase.kerberos.REALM}") String principle,
@Value("${hbase.kerberos.keytab}") String keytab) {
this.config = HBaseConfiguration.create();
this.principle = principle;
this.keytab = keytab;
}
public int importMultiKeyWithTableTSV(String table, String tsvfile, String className) throws Exception {
String args[] = {
"-Dimporttsv.mapper.class=" + className,
"-DtableStructure.file=" + tsvfile.replace(".csv", ".xml"),
table,
tsvfile,
"-libjars ./hbase-client-1.1.2.jar,./hbase-server-1.1.2.jar,./hbase-protocol-1.1.2.jar,./hbase-common-1.1.2.jar"
};
config.set("hadoop.security.authentication" , "Kerberos");
UserGroupInformation.setConfiguration(this.config);
UserGroupInformation.loginUserFromKeytab(this.principle, this.keytab);
return ToolRunner.run(config, new ImportTsv(), args);
}
}
package com.test.web;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.hbase.mapreduce.CellCreator;
import org.apache.hadoop.hbase.util.Base64;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
public class GRZHXXTsvImporterMapper extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {
private static final Logger logger = LoggerFactory.getLogger(Tsv2HbaseController.class);
@Override
public void map(LongWritable offset, Text value, Mapper<LongWritable, Text, ImmutableBytesWritable, Put>.Context context)
throws IOException {
try {
String[] row = value.toString().split(",");
ImmutableBytesWritable rowKey = new ImmutableBytesWritable((row[0]+row[1]+row[2]).getBytes());
Put put = new Put(rowKey.copyBytes());
KeyValue kv3 = new KeyValue(rowKey.copyBytes(), "PUBLIC".getBytes(),"GRJCJS".getBytes(), row[3].getBytes());
put.add(kv3);
// Write user table put
context.write(rowKey, put);
} catch (Exception e) {
e.printStackTrace();
}
}
}
...lots of settings...
HADOOP_CLASSPATH=${HADOOP_CLASSPATH}{JAVA_JDBC_LIBS}${HBASE_CLASSPATH}
...lots of settings...
...lots of settings...
yarn.application.classpath=.......,/usr/hdp/current/hbase-master/lib/*
...lots of settings...
Finally I found the solution.
Add hbase-master to classpath below: yarn-site.xml mapred-site.xml
both xml should be modified in cluster and your own jar resources.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.