I am trying to use JAVA API to connect to HBase. My codes are shown below:
public class Test {
public static void main(String[] args) throws IOException{
TableName tableName = TableName.valueOf("TABLE2");
Configuration conf = HBaseConfiguration.create();
conf.set("zookeeper.znode.parent", "/hbase-secure");
conf.set("hbase.zookeeper.property.clientPort", "2181");
conf.set("hbase.zookeeper.quorum", "xxxxxxxxxxxxxx");
conf.set("hbase.master", "xxxxxxxxxxxxx");
Connection conn = ConnectionFactory.createConnection(conf);
Admin admin = conn.getAdmin();
System.out.println(admin.toString());
if(!admin.tableExists(tableName)){
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor("cf")));
}
Table table = conn.getTable(tableName);
Put p = new Put(Bytes.toBytes("AAPL10232015"));
p.addColumn(Bytes.toBytes("cf"), Bytes.toBytes("close"), Bytes.toBytes(119));
table.put(p);
Result r = table.get(new Get(Bytes.toBytes("AAPL10232015")));
System.out.println(r);
}
}
When I run this program in my cluster, I got exception: I ran this and got error below:
Exception in thread "main" org.apache.hadoop.hbase.client.RetriesExhaustedException: Can't get the locations
at org.apache.hadoop.hbase.client.RpcRetryingCallerWithReadReplicas.getRegionLocations(RpcRetryingCallerWithReadReplicas.java:312)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:151)
at org.apache.hadoop.hbase.client.ScannerCallableWithReplicas.call(ScannerCallableWithReplicas.java:59)
at org.apache.hadoop.hbase.client.RpcRetryingCaller.callWithoutRetries(RpcRetryingCaller.java:200)
at org.apache.hadoop.hbase.client.ClientScanner.call(ClientScanner.java:320)
at org.apache.hadoop.hbase.client.ClientScanner.nextScanner(ClientScanner.java:295)
at org.apache.hadoop.hbase.client.ClientScanner.initializeScannerInConstruction(ClientScanner.java:160)
at org.apache.hadoop.hbase.client.ClientScanner.<init>(ClientScanner.java:155)
at org.apache.hadoop.hbase.client.HTable.getScanner(HTable.java:821)
at org.apache.hadoop.hbase.MetaTableAccessor.fullScan(MetaTableAccessor.java:602)
at org.apache.hadoop.hbase.MetaTableAccessor.tableExists(MetaTableAccessor.java:366)
at org.apache.hadoop.hbase.client.HBaseAdmin.tableExists(HBaseAdmin.java:303)
at java2hbase.Test.main(Test.java:31)
I ran this in a HDP cluster, exception happens after hbaseAdmin instantiation. It seems that JAVA client is not able to connect to Hbase using zookeeper, but I can use command "hbase zkcli" to open shell successfully.
Anyone knows what is problem? Is there any way to check zookeeper is good or not? Any help is appreciated.
hbase classpath
? – Muckyhbase classpath
java2hbase-0.0.1-SNAPSHOT-jar-with-dependencies.jar. I guess name of server cannot be recognized, so I will change them into IP addr and try. – Rumple