[英]Remotely access HBase Table List using Java
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HBaseAdmin;
public class ListTables {
public static void main(String args[])throws MasterNotRunningException, IOException {
ConnectionFactory.createConnection();
System.out.println("stage 1. . . . ");
Configuration conf = HBaseConfiguration.create();
conf.set("hbase.zookeeper.quorum", "192.168.*.***");
conf.set("hbase.master", "192.168.*.***:60000");
conf.set("hbase.zookeeper.property.clientPort","2181");
conf.set("zookeeper.znode.parent","/hbase-unsecure");
Connection connection = ConnectionFactory.createConnection(conf);
try {
HBaseAdmin admin1 = (HBaseAdmin)connection.getAdmin();
System.out.println("stage 3. . . . ");
HTableDescriptor tableDescriptor[] = admin1.listTables();
for (int i=0; i<tableDescriptor.length; i++) {
System.out.println(tableDescriptor[i].getNameAsString());
}
} catch (Exception e) {
System.out.println(e);
}
}
}
OUTPUT OUTPUT
log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
stage 1. . . .
stage 3. . . .
This is the Error 这是错误
After this line, i'm waiting for huge time, but No RESPONSE. 在这条线之后,我正在等待大量时间,但是没有响应。
I had the same error, and I had to create the log4j.properties, It is because Hadoop use log4j to write its logs: 我遇到了同样的错误,我不得不创建log4j.properties,这是因为Hadoop使用log4j编写其日志:
project Java: resources / log4j.properties 项目Java:资源/ log4j.properties
# Root logger option
log4j.rootLogger=DEBUG, stdout, file
# Redirect log messages to console
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
# Redirect log messages to a log file, support file rolling.
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=C:\\path of your `enter code here`file\\pruebas\\log\\log.log
log4j.appender.file.MaxFileSize=5MB
log4j.appender.file.MaxBackupIndex=10
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
I hope this helps you. 我希望这可以帮助你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.