4
votes

I am new to the Google cloud Spanner and to explore it I started with documentation provided by google Here. To explore any database we start with data operations and the same I did, I started with writing data to the spanner using simple java application given here https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/spanner/cloud-client/src/main/java/com/example/spanner/SpannerSample.java.
I have made changes in driver class on respective places shown in following code snippet:

 public static void main(String[] args) throws Exception {
            String path = "File_Path";

            SpannerOptions.Builder options = SpannerOptions.newBuilder().setCredentials(GoogleCredentials.fromStream(new FileInputStream(path)));
            options.setProjectId("Project_id");
            Spanner spanner = (options.build()).getService();
            try {
                DatabaseId db = DatabaseId.of("project_id", "spannerInstance", "Database_name");
                DatabaseClient dbClient = spanner.getDatabaseClient(db);
                run(dbClient);
            } finally {
                spanner.closeAsync().get();
            }
            System.out.println("Closed client");
        }

Now, When I am trying to execute the code I end up with following error:

Exception in thread "main" java.lang.IllegalArgumentException: Jetty ALPN/NPN has not been properly configured.
    at io.grpc.netty.GrpcSslContexts.selectApplicationProtocolConfig(GrpcSslContexts.java:174)
    at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:151)
    at io.grpc.netty.GrpcSslContexts.configure(GrpcSslContexts.java:139)
    at io.grpc.netty.GrpcSslContexts.forClient(GrpcSslContexts.java:109)
    at com.google.cloud.spanner.SpannerOptions$NettyRpcChannelFactory.newSslContext(SpannerOptions.java:283)
    at com.google.cloud.spanner.SpannerOptions$NettyRpcChannelFactory.newChannel(SpannerOptions.java:274)
    at com.google.cloud.spanner.SpannerOptions.createChannel(SpannerOptions.java:253)
    at com.google.cloud.spanner.SpannerOptions.createChannels(SpannerOptions.java:240)
    at com.google.cloud.spanner.SpannerOptions.<init>(SpannerOptions.java:89)
    at com.google.cloud.spanner.SpannerOptions.<init>(SpannerOptions.java:43)
    at com.google.cloud.spanner.SpannerOptions$Builder.build(SpannerOptions.java:180)

while searching for this issue I have been suggest to add some dependencies like:

   compile group: 'org.eclipse.jetty.alpn', name: 'alpn-api', version: '1.1.3.v20160715'
   compile group: 'org.mortbay.jetty.alpn', name: 'jetty-alpn-agent', version: '2.0.6'
   compile group: 'io.grpc', name: 'grpc-all', version: '1.2.0'
   compile group: 'io.netty', name: 'netty-all', version: '4.0.29.Final'
   compile group: 'org.eclipse.jetty.orbit', name: 'javax.servlet', version: '3.0.0.v201112011016'

but facing same issue, I am also using Bigquery and other GCP's feature one same working environment and they all are working fine except google-Spanner, any suggestion on this is appreciated.
Thanks.

1
There might be conflicting libraries in the classpath, could you list versions of GCP libraries that you are using so we could try to reproduce? Meanwhile, you might want to look into updating libraries to newest versions.Mairbek Khadikov
compile group: 'com.google.cloud', name: 'google-cloud-spanner', version: '0.17.1-beta' here is the gradle dependency I have added.Vaijnath Polsane
Now I am using latest spanner API and cloud API as compile group: 'com.google.cloud', name: 'google-cloud-spanner', version: '0.20.0-beta' and compile group: 'com.google.cloud', name: 'google-cloud', version: '0.20.0-alpha' still the error is same. any suggestionVaijnath Polsane
Could you try to check if there are conflicting libraries in you classpath?docs.gradle.org/current/userguide/…Mairbek Khadikov
So this seems to be a unresolved dependency of tcnative library, see github.com/grpc/grpc-java/issues/3025. Two possible options 1. Another version of tcnative is being pulled in, either by Tomcat or another version of Netty, and gRPC is not compatible with that version of tcnative; 2. The platform isn't supported by tcnative (ARM processors for example aren't supported). Here is the setup documentation for it by gRPC: github.com/grpc/grpc-java/blob/master/…Mairbek Khadikov

1 Answers

2
votes

Please read the comments on the question, @Mairbek Khadikov and my discussion on this conclude the actual reason of the issue. As discussed in comment the actual problem was with another dependencies. By adding

configurations {
    compile.exclude module: 'netty-all'
}

to the build.gradle file this issue has resolved.

Here is the link of github issue I raised regarding to this error. github issue where I posted exact issue eventually which I got to know and the resolution of that by, '@michaelbausor'.