无法连接到Google Cloud Bigtable实例

时间:2016-12-27 00:45:26

标签: java google-cloud-platform google-cloud-dataflow google-cloud-bigtable

我正在尝试使用HBase API连接到Google Cloud Bigtable实例。我使用的是Java 1.8。我按照下面的教程:

jsfiddle https://cloud.google.com/bigtable/docs/samples-java-hello

但由于某种原因,我无法连接到此Bigtable实例。我使用的是有效的ProjectID和InstanceID,但我仍然无法连接。请在下面找到例外情况:

java.lang.IllegalStateException: Could not find an appropriate constructor for com.google.cloud.bigtable.hbase1_2.BigtableConnection
    at com.google.cloud.bigtable.hbase.BigtableConfiguration.connect(BigtableConfiguration.java:88)
    at com.google.cloud.bigtable.hbase.BigtableConfiguration.connect(BigtableConfiguration.java:72)
    at com.kp.sensor.iot.IOTSensorPull.makeConnection(IOTSensorPull.java:149)
    at com.kp.sensor.iot.IOTSensorPull.populateTemperature(IOTSensorPull.java:159)
    at com.kp.sensor.iot.IOTSensorPull.readMessagesFromRFIDSub(IOTSensorPull.java:126)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.scheduling.support.ScheduledMethodRunnable.run(ScheduledMethodRunnable.java:65)
    at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54)
    at org.springframework.scheduling.concurrent.ReschedulingRunnable.run(ReschedulingRunnable.java:81)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.google.cloud.bigtable.hbase.BigtableConfiguration.connect(BigtableConfiguration.java:85)
    ... 18 more
Caused by: java.lang.NoSuchMethodError: com.google.cloud.bigtable.config.BigtableOptions$Builder.setInstanceId(Ljava/lang/String;)Lcom/google/cloud/bigtable/config/BigtableOptions$Builder;
    at com.google.cloud.bigtable.hbase.BigtableOptionsFactory.fromConfiguration(BigtableOptionsFactory.java:244)
    at org.apache.hadoop.hbase.client.AbstractBigtableConnection.<init>(AbstractBigtableConnection.java:129)
    at org.apache.hadoop.hbase.client.AbstractBigtableConnection.<init>(AbstractBigtableConnection.java:104)
    at com.google.cloud.bigtable.hbase1_2.BigtableConnection.<init>(BigtableConnection.java:50)

以下是我的maven依赖项:

<dependency>
    <groupId>com.google.cloud.bigtable</groupId>
    <artifactId>bigtable-hbase-1.2</artifactId>
    <version>0.9.4</version>
</dependency>

<dependency>
    <groupId>org.apache.hbase</groupId>
    <artifactId>hbase-client</artifactId>
    <version>1.1.5</version>
</dependency>

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-tcnative-boringssl-static</artifactId>
    <version>1.1.33.Fork19</version>
</dependency>

还有其他依赖项,因为这是一个Spring-boot应用程序。

此外,在这种情况下,ProjectID和InstanceID具有相同的值。

有人可以告诉我这里可能出现的问题吗?

2 个答案:

答案 0 :(得分:1)

对于它的价值,org.apache.hbase的版本是1.2.4 另外我怀疑由于你的项目ID等于实例ID,你指的是ProjectID别名,而不是实际的底层名称,因为我认为一个是自动分配的?我在其他地方遇到过使用Project别名的问题,谷歌似乎期待底层ID。但看看例外似乎问题不在于......

答案 1 :(得分:1)

实际上我觉得我找到了另一个原因,这可能更相关:我注意到当bigtable-hbase-1.2-0.9.4.jar没有准确定位在'/ com / google / cloud的原始路径中/bigtable/bigtable-hbase-1.2/0.9.4/bigtable-hbase-1.2-0.9.4.jar'会出现这个问题,因为代码似乎检查版本号为1.2(基于父文件夹?)< / p>

就我而言,这似乎与API的Bigtable-Dataflow部分有关,而不是与一般Bigtable API(即POM.xml中的bigtable-hbase-dataflow)有关。 Bigtable API的通用部分似乎并不关心JAR的位置。

我在Google的虚拟机上进行测试时遇到了这个问题,为了简单起见,我将所有JAR转储到一个目录中。它适用于通用Bigtable功能,但不适用于Bigtable-Dataflow功能,即使它在我的本地机器上工作,Eclipse在启动代码之前正确构建了所有依赖路径。一旦我将.JAR放在正确的路径上,问题就消失了。

我猜这个并发症来自哪里?
https://github.com/GoogleCloudPlatform/cloud-bigtable-client/blob/master/bigtable-hbase-parent/bigtable-hbase/src/main/java/com/google/cloud/bigtable/hbase/BigtableConfiguration.java#L43

cc:@ solomon-duskis