GoogleCloudPlatform / GoogleCloudPlatform/cloud-spanner-samples

Failure to start FinAppServer in Cloud Shell environment

Open
#89 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
36
Forks
32
PR merge metrics
No merged PRs in 30d

Description

When FinApp Server is started in a **Cloud Shell environment**, the following Exception is thrown and it does not start.

According to the [doc](https://cloud.google.com/docs/authentication/provide-credentials-adc#cloud-based-dev
), when we use a Google Cloud cloud-based development environment such as Cloud Shell or Cloud Code, the applications running on the environment uses the credentials we provided when we logged in, and manages any authorizations required.

However, the grpc-java used by FinApp Server does not take this into account, so an error occurs when FinApp Server is started in a Cloud Shell environment.

As far as I've tried, using grpc-java v1.43.0+ instead of v1.38.0 solved this issue.

Since this application is used as the official Cloud Spanner sample, this fix should help users.

## Expected Behavior
```
$ java -jar server/target/server-1.0-SNAPSHOT-jar-with-dependencies.jar --spanner_project_id= --spanner_instance_id= --spanner_database_id=finance-db
Dec 09, 2022 3:55:00 PM com.google.finapp.FinAppServer start
INFO: Server started, listening on 8080
```

## Actual Behavior
```
$ java -jar server/target/server-1.0-SNAPSHOT-jar-with-dependencies.jar --spanner_project_id= --spanner_instance_id= --spanner_database_id=finance-db
Exception in thread "main" java.lang.NoSuchMethodError: 'io.grpc.alts.GoogleDefaultChannelCredentials$Builder io.grpc.alts.GoogleDefaultChannelCredentials.newBuilder()'
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:326)
at com.google.api.gax.grpc.ChannelPool.(ChannelPool.java:105)
at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:83)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:236)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:230)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:201)
at com.google.cloud.spanner.v1.stub.GrpcSpannerStub.create(GrpcSpannerStub.java:231)
at com.google.cloud.spanner.spi.v1.GapicSpannerRpc.(GapicSpannerRpc.java:411)
at com.google.cloud.spanner.spi.v1.GapicSpannerRpc.(GapicSpannerRpc.java:302)
at com.google.cloud.spanner.SpannerOptions$DefaultSpannerRpcFactory.create(SpannerOptions.java:469)
at com.google.cloud.spanner.SpannerOptions$DefaultSpannerRpcFactory.create(SpannerOptions.java:464)
at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:560)
at com.google.cloud.spanner.SpannerOptions.getSpannerRpcV1(SpannerOptions.java:1320)
at com.google.cloud.spanner.SpannerImpl.(SpannerImpl.java:132)
at com.google.cloud.spanner.SpannerOptions$DefaultSpannerFactory.create(SpannerOptions.java:459)
at com.google.cloud.spanner.SpannerOptions$DefaultSpannerFactory.create(SpannerOptions.java:454)
at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:540)
at com.google.finapp.ServerMain.getSpannerDao(ServerMain.java:55)
at com.google.finapp.ServerMain.main(ServerMain.java:33)
```

## Steps to Reproduce the Problem

1. Open Cloud Shell environment.
2. Initialize `finance-db`
3. Run `java -jar server/target/server-1.0-SNAPSHOT-jar-with-dependencies.jar --spanner_project_id= --spanner_instance_id= --spanner_database_id=finance-db`

## Solution
- Use grpc-java v1.43.0 instead of v1.38.0
- https://github.com/grpc/grpc-java/pull/8548

## Specifications

- Version: latest as of 2022-12-09 #87
- Platform: Cloud Shell

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.