1 /* 2 * Copyright 2022 Google LLC 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.cloud.billing.v1.stub; 18 19 import static com.google.cloud.billing.v1.CloudBillingClient.ListBillingAccountsPagedResponse; 20 import static com.google.cloud.billing.v1.CloudBillingClient.ListProjectBillingInfoPagedResponse; 21 22 import com.google.api.gax.core.BackgroundResource; 23 import com.google.api.gax.core.BackgroundResourceAggregation; 24 import com.google.api.gax.grpc.GrpcCallSettings; 25 import com.google.api.gax.grpc.GrpcStubCallableFactory; 26 import com.google.api.gax.rpc.ClientContext; 27 import com.google.api.gax.rpc.UnaryCallable; 28 import com.google.cloud.billing.v1.BillingAccount; 29 import com.google.cloud.billing.v1.CreateBillingAccountRequest; 30 import com.google.cloud.billing.v1.GetBillingAccountRequest; 31 import com.google.cloud.billing.v1.GetProjectBillingInfoRequest; 32 import com.google.cloud.billing.v1.ListBillingAccountsRequest; 33 import com.google.cloud.billing.v1.ListBillingAccountsResponse; 34 import com.google.cloud.billing.v1.ListProjectBillingInfoRequest; 35 import com.google.cloud.billing.v1.ListProjectBillingInfoResponse; 36 import com.google.cloud.billing.v1.ProjectBillingInfo; 37 import com.google.cloud.billing.v1.UpdateBillingAccountRequest; 38 import com.google.cloud.billing.v1.UpdateProjectBillingInfoRequest; 39 import com.google.common.collect.ImmutableMap; 40 import com.google.iam.v1.GetIamPolicyRequest; 41 import com.google.iam.v1.Policy; 42 import com.google.iam.v1.SetIamPolicyRequest; 43 import com.google.iam.v1.TestIamPermissionsRequest; 44 import com.google.iam.v1.TestIamPermissionsResponse; 45 import com.google.longrunning.stub.GrpcOperationsStub; 46 import io.grpc.MethodDescriptor; 47 import io.grpc.protobuf.ProtoUtils; 48 import java.io.IOException; 49 import java.util.concurrent.TimeUnit; 50 import javax.annotation.Generated; 51 52 // AUTO-GENERATED DOCUMENTATION AND CLASS. 53 /** 54 * gRPC stub implementation for the CloudBilling service API. 55 * 56 * <p>This class is for advanced usage and reflects the underlying API directly. 57 */ 58 @Generated("by gapic-generator-java") 59 public class GrpcCloudBillingStub extends CloudBillingStub { 60 private static final MethodDescriptor<GetBillingAccountRequest, BillingAccount> 61 getBillingAccountMethodDescriptor = 62 MethodDescriptor.<GetBillingAccountRequest, BillingAccount>newBuilder() 63 .setType(MethodDescriptor.MethodType.UNARY) 64 .setFullMethodName("google.cloud.billing.v1.CloudBilling/GetBillingAccount") 65 .setRequestMarshaller( 66 ProtoUtils.marshaller(GetBillingAccountRequest.getDefaultInstance())) 67 .setResponseMarshaller(ProtoUtils.marshaller(BillingAccount.getDefaultInstance())) 68 .build(); 69 70 private static final MethodDescriptor<ListBillingAccountsRequest, ListBillingAccountsResponse> 71 listBillingAccountsMethodDescriptor = 72 MethodDescriptor.<ListBillingAccountsRequest, ListBillingAccountsResponse>newBuilder() 73 .setType(MethodDescriptor.MethodType.UNARY) 74 .setFullMethodName("google.cloud.billing.v1.CloudBilling/ListBillingAccounts") 75 .setRequestMarshaller( 76 ProtoUtils.marshaller(ListBillingAccountsRequest.getDefaultInstance())) 77 .setResponseMarshaller( 78 ProtoUtils.marshaller(ListBillingAccountsResponse.getDefaultInstance())) 79 .build(); 80 81 private static final MethodDescriptor<UpdateBillingAccountRequest, BillingAccount> 82 updateBillingAccountMethodDescriptor = 83 MethodDescriptor.<UpdateBillingAccountRequest, BillingAccount>newBuilder() 84 .setType(MethodDescriptor.MethodType.UNARY) 85 .setFullMethodName("google.cloud.billing.v1.CloudBilling/UpdateBillingAccount") 86 .setRequestMarshaller( 87 ProtoUtils.marshaller(UpdateBillingAccountRequest.getDefaultInstance())) 88 .setResponseMarshaller(ProtoUtils.marshaller(BillingAccount.getDefaultInstance())) 89 .build(); 90 91 private static final MethodDescriptor<CreateBillingAccountRequest, BillingAccount> 92 createBillingAccountMethodDescriptor = 93 MethodDescriptor.<CreateBillingAccountRequest, BillingAccount>newBuilder() 94 .setType(MethodDescriptor.MethodType.UNARY) 95 .setFullMethodName("google.cloud.billing.v1.CloudBilling/CreateBillingAccount") 96 .setRequestMarshaller( 97 ProtoUtils.marshaller(CreateBillingAccountRequest.getDefaultInstance())) 98 .setResponseMarshaller(ProtoUtils.marshaller(BillingAccount.getDefaultInstance())) 99 .build(); 100 101 private static final MethodDescriptor< 102 ListProjectBillingInfoRequest, ListProjectBillingInfoResponse> 103 listProjectBillingInfoMethodDescriptor = 104 MethodDescriptor 105 .<ListProjectBillingInfoRequest, ListProjectBillingInfoResponse>newBuilder() 106 .setType(MethodDescriptor.MethodType.UNARY) 107 .setFullMethodName("google.cloud.billing.v1.CloudBilling/ListProjectBillingInfo") 108 .setRequestMarshaller( 109 ProtoUtils.marshaller(ListProjectBillingInfoRequest.getDefaultInstance())) 110 .setResponseMarshaller( 111 ProtoUtils.marshaller(ListProjectBillingInfoResponse.getDefaultInstance())) 112 .build(); 113 114 private static final MethodDescriptor<GetProjectBillingInfoRequest, ProjectBillingInfo> 115 getProjectBillingInfoMethodDescriptor = 116 MethodDescriptor.<GetProjectBillingInfoRequest, ProjectBillingInfo>newBuilder() 117 .setType(MethodDescriptor.MethodType.UNARY) 118 .setFullMethodName("google.cloud.billing.v1.CloudBilling/GetProjectBillingInfo") 119 .setRequestMarshaller( 120 ProtoUtils.marshaller(GetProjectBillingInfoRequest.getDefaultInstance())) 121 .setResponseMarshaller(ProtoUtils.marshaller(ProjectBillingInfo.getDefaultInstance())) 122 .build(); 123 124 private static final MethodDescriptor<UpdateProjectBillingInfoRequest, ProjectBillingInfo> 125 updateProjectBillingInfoMethodDescriptor = 126 MethodDescriptor.<UpdateProjectBillingInfoRequest, ProjectBillingInfo>newBuilder() 127 .setType(MethodDescriptor.MethodType.UNARY) 128 .setFullMethodName("google.cloud.billing.v1.CloudBilling/UpdateProjectBillingInfo") 129 .setRequestMarshaller( 130 ProtoUtils.marshaller(UpdateProjectBillingInfoRequest.getDefaultInstance())) 131 .setResponseMarshaller(ProtoUtils.marshaller(ProjectBillingInfo.getDefaultInstance())) 132 .build(); 133 134 private static final MethodDescriptor<GetIamPolicyRequest, Policy> getIamPolicyMethodDescriptor = 135 MethodDescriptor.<GetIamPolicyRequest, Policy>newBuilder() 136 .setType(MethodDescriptor.MethodType.UNARY) 137 .setFullMethodName("google.cloud.billing.v1.CloudBilling/GetIamPolicy") 138 .setRequestMarshaller(ProtoUtils.marshaller(GetIamPolicyRequest.getDefaultInstance())) 139 .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) 140 .build(); 141 142 private static final MethodDescriptor<SetIamPolicyRequest, Policy> setIamPolicyMethodDescriptor = 143 MethodDescriptor.<SetIamPolicyRequest, Policy>newBuilder() 144 .setType(MethodDescriptor.MethodType.UNARY) 145 .setFullMethodName("google.cloud.billing.v1.CloudBilling/SetIamPolicy") 146 .setRequestMarshaller(ProtoUtils.marshaller(SetIamPolicyRequest.getDefaultInstance())) 147 .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) 148 .build(); 149 150 private static final MethodDescriptor<TestIamPermissionsRequest, TestIamPermissionsResponse> 151 testIamPermissionsMethodDescriptor = 152 MethodDescriptor.<TestIamPermissionsRequest, TestIamPermissionsResponse>newBuilder() 153 .setType(MethodDescriptor.MethodType.UNARY) 154 .setFullMethodName("google.cloud.billing.v1.CloudBilling/TestIamPermissions") 155 .setRequestMarshaller( 156 ProtoUtils.marshaller(TestIamPermissionsRequest.getDefaultInstance())) 157 .setResponseMarshaller( 158 ProtoUtils.marshaller(TestIamPermissionsResponse.getDefaultInstance())) 159 .build(); 160 161 private final UnaryCallable<GetBillingAccountRequest, BillingAccount> getBillingAccountCallable; 162 private final UnaryCallable<ListBillingAccountsRequest, ListBillingAccountsResponse> 163 listBillingAccountsCallable; 164 private final UnaryCallable<ListBillingAccountsRequest, ListBillingAccountsPagedResponse> 165 listBillingAccountsPagedCallable; 166 private final UnaryCallable<UpdateBillingAccountRequest, BillingAccount> 167 updateBillingAccountCallable; 168 private final UnaryCallable<CreateBillingAccountRequest, BillingAccount> 169 createBillingAccountCallable; 170 private final UnaryCallable<ListProjectBillingInfoRequest, ListProjectBillingInfoResponse> 171 listProjectBillingInfoCallable; 172 private final UnaryCallable<ListProjectBillingInfoRequest, ListProjectBillingInfoPagedResponse> 173 listProjectBillingInfoPagedCallable; 174 private final UnaryCallable<GetProjectBillingInfoRequest, ProjectBillingInfo> 175 getProjectBillingInfoCallable; 176 private final UnaryCallable<UpdateProjectBillingInfoRequest, ProjectBillingInfo> 177 updateProjectBillingInfoCallable; 178 private final UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable; 179 private final UnaryCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable; 180 private final UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse> 181 testIamPermissionsCallable; 182 183 private final BackgroundResource backgroundResources; 184 private final GrpcOperationsStub operationsStub; 185 private final GrpcStubCallableFactory callableFactory; 186 create(CloudBillingStubSettings settings)187 public static final GrpcCloudBillingStub create(CloudBillingStubSettings settings) 188 throws IOException { 189 return new GrpcCloudBillingStub(settings, ClientContext.create(settings)); 190 } 191 create(ClientContext clientContext)192 public static final GrpcCloudBillingStub create(ClientContext clientContext) throws IOException { 193 return new GrpcCloudBillingStub(CloudBillingStubSettings.newBuilder().build(), clientContext); 194 } 195 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)196 public static final GrpcCloudBillingStub create( 197 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 198 return new GrpcCloudBillingStub( 199 CloudBillingStubSettings.newBuilder().build(), clientContext, callableFactory); 200 } 201 202 /** 203 * Constructs an instance of GrpcCloudBillingStub, using the given settings. This is protected so 204 * that it is easy to make a subclass, but otherwise, the static factory methods should be 205 * preferred. 206 */ GrpcCloudBillingStub(CloudBillingStubSettings settings, ClientContext clientContext)207 protected GrpcCloudBillingStub(CloudBillingStubSettings settings, ClientContext clientContext) 208 throws IOException { 209 this(settings, clientContext, new GrpcCloudBillingCallableFactory()); 210 } 211 212 /** 213 * Constructs an instance of GrpcCloudBillingStub, using the given settings. This is protected so 214 * that it is easy to make a subclass, but otherwise, the static factory methods should be 215 * preferred. 216 */ GrpcCloudBillingStub( CloudBillingStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)217 protected GrpcCloudBillingStub( 218 CloudBillingStubSettings settings, 219 ClientContext clientContext, 220 GrpcStubCallableFactory callableFactory) 221 throws IOException { 222 this.callableFactory = callableFactory; 223 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 224 225 GrpcCallSettings<GetBillingAccountRequest, BillingAccount> getBillingAccountTransportSettings = 226 GrpcCallSettings.<GetBillingAccountRequest, BillingAccount>newBuilder() 227 .setMethodDescriptor(getBillingAccountMethodDescriptor) 228 .setParamsExtractor( 229 request -> { 230 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 231 params.put("name", String.valueOf(request.getName())); 232 return params.build(); 233 }) 234 .build(); 235 GrpcCallSettings<ListBillingAccountsRequest, ListBillingAccountsResponse> 236 listBillingAccountsTransportSettings = 237 GrpcCallSettings.<ListBillingAccountsRequest, ListBillingAccountsResponse>newBuilder() 238 .setMethodDescriptor(listBillingAccountsMethodDescriptor) 239 .build(); 240 GrpcCallSettings<UpdateBillingAccountRequest, BillingAccount> 241 updateBillingAccountTransportSettings = 242 GrpcCallSettings.<UpdateBillingAccountRequest, BillingAccount>newBuilder() 243 .setMethodDescriptor(updateBillingAccountMethodDescriptor) 244 .setParamsExtractor( 245 request -> { 246 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 247 params.put("name", String.valueOf(request.getName())); 248 return params.build(); 249 }) 250 .build(); 251 GrpcCallSettings<CreateBillingAccountRequest, BillingAccount> 252 createBillingAccountTransportSettings = 253 GrpcCallSettings.<CreateBillingAccountRequest, BillingAccount>newBuilder() 254 .setMethodDescriptor(createBillingAccountMethodDescriptor) 255 .build(); 256 GrpcCallSettings<ListProjectBillingInfoRequest, ListProjectBillingInfoResponse> 257 listProjectBillingInfoTransportSettings = 258 GrpcCallSettings 259 .<ListProjectBillingInfoRequest, ListProjectBillingInfoResponse>newBuilder() 260 .setMethodDescriptor(listProjectBillingInfoMethodDescriptor) 261 .setParamsExtractor( 262 request -> { 263 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 264 params.put("name", String.valueOf(request.getName())); 265 return params.build(); 266 }) 267 .build(); 268 GrpcCallSettings<GetProjectBillingInfoRequest, ProjectBillingInfo> 269 getProjectBillingInfoTransportSettings = 270 GrpcCallSettings.<GetProjectBillingInfoRequest, ProjectBillingInfo>newBuilder() 271 .setMethodDescriptor(getProjectBillingInfoMethodDescriptor) 272 .setParamsExtractor( 273 request -> { 274 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 275 params.put("name", String.valueOf(request.getName())); 276 return params.build(); 277 }) 278 .build(); 279 GrpcCallSettings<UpdateProjectBillingInfoRequest, ProjectBillingInfo> 280 updateProjectBillingInfoTransportSettings = 281 GrpcCallSettings.<UpdateProjectBillingInfoRequest, ProjectBillingInfo>newBuilder() 282 .setMethodDescriptor(updateProjectBillingInfoMethodDescriptor) 283 .setParamsExtractor( 284 request -> { 285 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 286 params.put("name", String.valueOf(request.getName())); 287 return params.build(); 288 }) 289 .build(); 290 GrpcCallSettings<GetIamPolicyRequest, Policy> getIamPolicyTransportSettings = 291 GrpcCallSettings.<GetIamPolicyRequest, Policy>newBuilder() 292 .setMethodDescriptor(getIamPolicyMethodDescriptor) 293 .setParamsExtractor( 294 request -> { 295 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 296 params.put("resource", String.valueOf(request.getResource())); 297 return params.build(); 298 }) 299 .build(); 300 GrpcCallSettings<SetIamPolicyRequest, Policy> setIamPolicyTransportSettings = 301 GrpcCallSettings.<SetIamPolicyRequest, Policy>newBuilder() 302 .setMethodDescriptor(setIamPolicyMethodDescriptor) 303 .setParamsExtractor( 304 request -> { 305 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 306 params.put("resource", String.valueOf(request.getResource())); 307 return params.build(); 308 }) 309 .build(); 310 GrpcCallSettings<TestIamPermissionsRequest, TestIamPermissionsResponse> 311 testIamPermissionsTransportSettings = 312 GrpcCallSettings.<TestIamPermissionsRequest, TestIamPermissionsResponse>newBuilder() 313 .setMethodDescriptor(testIamPermissionsMethodDescriptor) 314 .setParamsExtractor( 315 request -> { 316 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 317 params.put("resource", String.valueOf(request.getResource())); 318 return params.build(); 319 }) 320 .build(); 321 322 this.getBillingAccountCallable = 323 callableFactory.createUnaryCallable( 324 getBillingAccountTransportSettings, 325 settings.getBillingAccountSettings(), 326 clientContext); 327 this.listBillingAccountsCallable = 328 callableFactory.createUnaryCallable( 329 listBillingAccountsTransportSettings, 330 settings.listBillingAccountsSettings(), 331 clientContext); 332 this.listBillingAccountsPagedCallable = 333 callableFactory.createPagedCallable( 334 listBillingAccountsTransportSettings, 335 settings.listBillingAccountsSettings(), 336 clientContext); 337 this.updateBillingAccountCallable = 338 callableFactory.createUnaryCallable( 339 updateBillingAccountTransportSettings, 340 settings.updateBillingAccountSettings(), 341 clientContext); 342 this.createBillingAccountCallable = 343 callableFactory.createUnaryCallable( 344 createBillingAccountTransportSettings, 345 settings.createBillingAccountSettings(), 346 clientContext); 347 this.listProjectBillingInfoCallable = 348 callableFactory.createUnaryCallable( 349 listProjectBillingInfoTransportSettings, 350 settings.listProjectBillingInfoSettings(), 351 clientContext); 352 this.listProjectBillingInfoPagedCallable = 353 callableFactory.createPagedCallable( 354 listProjectBillingInfoTransportSettings, 355 settings.listProjectBillingInfoSettings(), 356 clientContext); 357 this.getProjectBillingInfoCallable = 358 callableFactory.createUnaryCallable( 359 getProjectBillingInfoTransportSettings, 360 settings.getProjectBillingInfoSettings(), 361 clientContext); 362 this.updateProjectBillingInfoCallable = 363 callableFactory.createUnaryCallable( 364 updateProjectBillingInfoTransportSettings, 365 settings.updateProjectBillingInfoSettings(), 366 clientContext); 367 this.getIamPolicyCallable = 368 callableFactory.createUnaryCallable( 369 getIamPolicyTransportSettings, settings.getIamPolicySettings(), clientContext); 370 this.setIamPolicyCallable = 371 callableFactory.createUnaryCallable( 372 setIamPolicyTransportSettings, settings.setIamPolicySettings(), clientContext); 373 this.testIamPermissionsCallable = 374 callableFactory.createUnaryCallable( 375 testIamPermissionsTransportSettings, 376 settings.testIamPermissionsSettings(), 377 clientContext); 378 379 this.backgroundResources = 380 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 381 } 382 getOperationsStub()383 public GrpcOperationsStub getOperationsStub() { 384 return operationsStub; 385 } 386 387 @Override getBillingAccountCallable()388 public UnaryCallable<GetBillingAccountRequest, BillingAccount> getBillingAccountCallable() { 389 return getBillingAccountCallable; 390 } 391 392 @Override 393 public UnaryCallable<ListBillingAccountsRequest, ListBillingAccountsResponse> listBillingAccountsCallable()394 listBillingAccountsCallable() { 395 return listBillingAccountsCallable; 396 } 397 398 @Override 399 public UnaryCallable<ListBillingAccountsRequest, ListBillingAccountsPagedResponse> listBillingAccountsPagedCallable()400 listBillingAccountsPagedCallable() { 401 return listBillingAccountsPagedCallable; 402 } 403 404 @Override updateBillingAccountCallable()405 public UnaryCallable<UpdateBillingAccountRequest, BillingAccount> updateBillingAccountCallable() { 406 return updateBillingAccountCallable; 407 } 408 409 @Override createBillingAccountCallable()410 public UnaryCallable<CreateBillingAccountRequest, BillingAccount> createBillingAccountCallable() { 411 return createBillingAccountCallable; 412 } 413 414 @Override 415 public UnaryCallable<ListProjectBillingInfoRequest, ListProjectBillingInfoResponse> listProjectBillingInfoCallable()416 listProjectBillingInfoCallable() { 417 return listProjectBillingInfoCallable; 418 } 419 420 @Override 421 public UnaryCallable<ListProjectBillingInfoRequest, ListProjectBillingInfoPagedResponse> listProjectBillingInfoPagedCallable()422 listProjectBillingInfoPagedCallable() { 423 return listProjectBillingInfoPagedCallable; 424 } 425 426 @Override 427 public UnaryCallable<GetProjectBillingInfoRequest, ProjectBillingInfo> getProjectBillingInfoCallable()428 getProjectBillingInfoCallable() { 429 return getProjectBillingInfoCallable; 430 } 431 432 @Override 433 public UnaryCallable<UpdateProjectBillingInfoRequest, ProjectBillingInfo> updateProjectBillingInfoCallable()434 updateProjectBillingInfoCallable() { 435 return updateProjectBillingInfoCallable; 436 } 437 438 @Override getIamPolicyCallable()439 public UnaryCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() { 440 return getIamPolicyCallable; 441 } 442 443 @Override setIamPolicyCallable()444 public UnaryCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable() { 445 return setIamPolicyCallable; 446 } 447 448 @Override 449 public UnaryCallable<TestIamPermissionsRequest, TestIamPermissionsResponse> testIamPermissionsCallable()450 testIamPermissionsCallable() { 451 return testIamPermissionsCallable; 452 } 453 454 @Override close()455 public final void close() { 456 try { 457 backgroundResources.close(); 458 } catch (RuntimeException e) { 459 throw e; 460 } catch (Exception e) { 461 throw new IllegalStateException("Failed to close resource", e); 462 } 463 } 464 465 @Override shutdown()466 public void shutdown() { 467 backgroundResources.shutdown(); 468 } 469 470 @Override isShutdown()471 public boolean isShutdown() { 472 return backgroundResources.isShutdown(); 473 } 474 475 @Override isTerminated()476 public boolean isTerminated() { 477 return backgroundResources.isTerminated(); 478 } 479 480 @Override shutdownNow()481 public void shutdownNow() { 482 backgroundResources.shutdownNow(); 483 } 484 485 @Override awaitTermination(long duration, TimeUnit unit)486 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 487 return backgroundResources.awaitTermination(duration, unit); 488 } 489 } 490