4

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.

Vaijnath Polsane
  • 608
  • 6
  • 21
  • 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 Jun 20 '17 at 04:26
  • compile group: 'com.google.cloud', name: 'google-cloud-spanner', version: '0.17.1-beta' here is the gradle dependency I have added. – Vaijnath Polsane Jun 20 '17 at 06:25
  • 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 suggestion – Vaijnath Polsane Jun 20 '17 at 08:42
  • Could you try to check if there are conflicting libraries in you classpath?https://docs.gradle.org/current/userguide/userguide_single.html#sec:listing_dependencies – Mairbek Khadikov Jun 20 '17 at 17:54
  • No, there is not, when i debug the code I end up with ClassNotFound Exception internally it was looking for org.eclipse.jetty.alpn.ALPN, even though it is in the classpath. when it tries to find out above class it gives call to the Class.java's forName() method, where it is skipping some steps, as System.getSecurityManager() returning a Null. please help me out – Vaijnath Polsane Jun 27 '17 at 13:23
  • 1
    So this seems to be a unresolved dependency of tcnative library, see https://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`: https://github.com/grpc/grpc-java/blob/master/SECURITY.md#tls-with-openssl – Mairbek Khadikov Jun 28 '17 at 17:15
  • Hey Mairbek thanks, yeah that seems to be dependency problem, I am able to execute the spanner application but, only when I am removing spark dependencies from my project that allow me to run spanner on cost of removing spark from my project, that is not going to help me. I need to write the Spark's DataFrame to Spanner. Any thing that i can do to make it work. – Vaijnath Polsane Jun 29 '17 at 05:32
  • I tried with two project setup 1)with Spark 2) without Spark dependencies and as debug them I endup with difference in selection of SslProvider from GrpcSslContexts class 1st select JDK and failing 2nd select OpenSSL and running fine. – Vaijnath Polsane Jun 30 '17 at 06:08
  • I would suggest you to open a bug against http://github.com/GoogleCloudPlatform/google-cloud-java, where you could specify version of Spark that you are using, so cloud Java experts can assist you. – Mairbek Khadikov Jun 30 '17 at 20:59

1 Answers1

2

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'.

Vaijnath Polsane
  • 608
  • 6
  • 21