我在使用java连接到kubernetes gcp群集中的远程hbase服务器时遇到一些问题。这是我为测试连接而编写的代码。
Configuration config = HBaseConfiguration.create();
try {
config.set("hbase.zookeeper.quorum", "34.xx.xxx.109");
HBaseAdmin.checkHBaseAvailable(config);
Connection connection = ConnectionFactory.createConnection(config);
table = connection.getTable(TableName.valueOf("table_name"));
} catch (IOException e) {
e.printStackTrace();
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
}
但是当 HBaseAdmin.checkHBaseAvailable(config);
在引发以下异常时执行:
org.apache.hadoop.hbase.MasterNotRunningException: java.net.UnknownHostException: can not resolve hbase-74fbxxx579-nglz6,16000,1603123848632
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$StubMaker.makeStub(ConnectionManager.java:1625)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation$MasterServiceStubMaker.makeStub(ConnectionManager.java:1645)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.getKeepAliveMasterService(ConnectionManager.java:1802)
at org.apache.hadoop.hbase.client.ConnectionManager$HConnectionImplementation.isMasterRunning(ConnectionManager.java:994)
at org.apache.hadoop.hbase.client.HBaseAdmin.checkHBaseAvailable(HBaseAdmin.java:3229)
at com.arauco.modeloib.service.SensorService.testHbaseConnection(SensorService.java:68)
at com.arauco.modeloib.controller.SensorController.testHbaseConnection(SensorController.java:30)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
我不知道可能是什么我已经编写了以下python代码,它可以工作,所以可能我缺少一些hbaseconfiguration属性,但我非常关心python与java实现之间的连接有多简单:
import happybase
from datetime import date
connection = happybase.Connection('34.xx.xxx.109')
def main():
today = date.today()
table = connection.table('table_name')
format_today = today.strftime('%Y-%m-%d')
for key, data in table.scan(row_prefix='prefix_to_search'.encode()):
print(key, data)
main()
暂无答案!
目前还没有任何答案,快来回答吧!