2323import com .google .api .gax .core .GaxProperties ;
2424import com .google .api .gax .grpc .GaxGrpcProperties ;
2525import com .google .api .gax .grpc .GrpcCallContext ;
26- import com .google .api .gax .grpc .GrpcTransportChannel ;
2726import com .google .api .gax .grpc .InstantiatingGrpcChannelProvider ;
2827import com .google .api .gax .longrunning .OperationFuture ;
2928import com .google .api .gax .rpc .ApiClientHeaderProvider ;
30- import com .google .api .gax .rpc .FixedTransportChannelProvider ;
3129import com .google .api .gax .rpc .HeaderProvider ;
3230import com .google .api .gax .rpc .ServerStream ;
3331import com .google .api .gax .rpc .StatusCode ;
5250import com .google .common .base .MoreObjects ;
5351import com .google .common .collect .ImmutableSet ;
5452import com .google .longrunning .GetOperationRequest ;
53+ import com .google .longrunning .Operation ;
5554import com .google .protobuf .Empty ;
5655import com .google .protobuf .FieldMask ;
5756import com .google .spanner .admin .database .v1 .CreateDatabaseMetadata ;
8382import com .google .spanner .v1 .CreateSessionRequest ;
8483import com .google .spanner .v1 .DeleteSessionRequest ;
8584import com .google .spanner .v1 .ExecuteSqlRequest ;
85+ import com .google .spanner .v1 .PartialResultSet ;
8686import com .google .spanner .v1 .PartitionQueryRequest ;
8787import com .google .spanner .v1 .PartitionReadRequest ;
8888import com .google .spanner .v1 .PartitionResponse ;
89- import com .google .spanner .v1 .PartialResultSet ;
9089import com .google .spanner .v1 .ReadRequest ;
9190import com .google .spanner .v1 .RollbackRequest ;
9291import com .google .spanner .v1 .Session ;
10099import java .util .concurrent .Future ;
101100import javax .annotation .Nullable ;
102101
103- import com .google .longrunning .Operation ;
104-
105102/** Implementation of Cloud Spanner remote calls using Gapic libraries. */
106103public class GapicSpannerRpc implements SpannerRpc {
107104
@@ -145,9 +142,7 @@ public GapicSpannerRpc(SpannerOptions options) throws IOException {
145142 mergedHeaderProvider .getHeaders (),
146143 internalHeaderProviderBuilder .getResourceHeaderKey ());
147144
148- // TODO(pongad): make RPC logging work (formerly LoggingInterceptor)
149145 // TODO(pongad): add watchdog
150- // TODO(pongad): make error augmentation work (formerly SpannerErrorInterceptor)
151146
152147 // TODO(hzyi): make this channelProvider configurable through SpannerOptions
153148 TransportChannelProvider channelProvider =
@@ -156,60 +151,61 @@ public GapicSpannerRpc(SpannerOptions options) throws IOException {
156151 .setEndpoint (options .getEndpoint ())
157152 .setMaxInboundMessageSize (MAX_MESSAGE_SIZE )
158153 .setPoolSize (options .getNumChannels ())
154+ .setInterceptorProvider (new SpannerInterceptorProvider ())
159155 .build ();
160156
161157 CredentialsProvider credentialsProvider =
162158 GrpcTransportOptions .setUpCredentialsProvider (options );
163-
159+
164160 // Disabling retry for now because spanner handles retry in SpannerImpl.
165161 // We will finally want to improve gax but for smooth transitioning we
166162 // preserve the retry in SpannerImpl
167163 try {
168164 // TODO: bump the version of gax and remove this try-catch block
169165 // applyToAllUnaryMethods does not throw exception in the latest version
170166 this .stub =
171- GrpcSpannerStub .create (
172- SpannerStubSettings .newBuilder ()
173- .setTransportChannelProvider (channelProvider )
174- .setCredentialsProvider (credentialsProvider )
175- .applyToAllUnaryMethods (
176- new ApiFunction <UnaryCallSettings .Builder <?, ?>, Void >() {
177- @ Override
178- public Void apply (UnaryCallSettings .Builder <?,?> builder ) {
179- builder .setRetryableCodes (ImmutableSet .<StatusCode .Code >of ());
180- return null ;
181- }
182- })
183- .build ());
184-
185- this .instanceStub =
186- GrpcInstanceAdminStub .create (
187- InstanceAdminStubSettings .newBuilder ()
188- .setTransportChannelProvider (channelProvider )
189- .setCredentialsProvider (credentialsProvider )
190- .applyToAllUnaryMethods (
191- new ApiFunction <UnaryCallSettings .Builder <?, ?>, Void >() {
192- @ Override
193- public Void apply (UnaryCallSettings .Builder <?,?> builder ) {
194- builder .setRetryableCodes (ImmutableSet .<StatusCode .Code >of ());
195- return null ;
196- }
197- })
198- .build ());
199- this .databaseStub =
200- GrpcDatabaseAdminStub .create (
201- DatabaseAdminStubSettings .newBuilder ()
202- .setTransportChannelProvider (channelProvider )
203- .setCredentialsProvider (credentialsProvider )
204- .applyToAllUnaryMethods (
205- new ApiFunction <UnaryCallSettings .Builder <?, ?>, Void >() {
206- @ Override
207- public Void apply (UnaryCallSettings .Builder <?,?> builder ) {
208- builder .setRetryableCodes (ImmutableSet .<StatusCode .Code >of ());
209- return null ;
210- }
211- })
212- .build ());
167+ GrpcSpannerStub .create (
168+ SpannerStubSettings .newBuilder ()
169+ .setTransportChannelProvider (channelProvider )
170+ .setCredentialsProvider (credentialsProvider )
171+ .applyToAllUnaryMethods (
172+ new ApiFunction <UnaryCallSettings .Builder <?, ?>, Void >() {
173+ @ Override
174+ public Void apply (UnaryCallSettings .Builder <?, ?> builder ) {
175+ builder .setRetryableCodes (ImmutableSet .<StatusCode .Code >of ());
176+ return null ;
177+ }
178+ })
179+ .build ());
180+
181+ this .instanceStub =
182+ GrpcInstanceAdminStub .create (
183+ InstanceAdminStubSettings .newBuilder ()
184+ .setTransportChannelProvider (channelProvider )
185+ .setCredentialsProvider (credentialsProvider )
186+ .applyToAllUnaryMethods (
187+ new ApiFunction <UnaryCallSettings .Builder <?, ?>, Void >() {
188+ @ Override
189+ public Void apply (UnaryCallSettings .Builder <?, ?> builder ) {
190+ builder .setRetryableCodes (ImmutableSet .<StatusCode .Code >of ());
191+ return null ;
192+ }
193+ })
194+ .build ());
195+ this .databaseStub =
196+ GrpcDatabaseAdminStub .create (
197+ DatabaseAdminStubSettings .newBuilder ()
198+ .setTransportChannelProvider (channelProvider )
199+ .setCredentialsProvider (credentialsProvider )
200+ .applyToAllUnaryMethods (
201+ new ApiFunction <UnaryCallSettings .Builder <?, ?>, Void >() {
202+ @ Override
203+ public Void apply (UnaryCallSettings .Builder <?, ?> builder ) {
204+ builder .setRetryableCodes (ImmutableSet .<StatusCode .Code >of ());
205+ return null ;
206+ }
207+ })
208+ .build ());
213209 } catch (Exception e ) {
214210 throw SpannerExceptionFactory .newSpannerException (e );
215211 }
0 commit comments