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.orgpolicy.v2.stub; 18 19 import static com.google.cloud.orgpolicy.v2.OrgPolicyClient.ListConstraintsPagedResponse; 20 import static com.google.cloud.orgpolicy.v2.OrgPolicyClient.ListPoliciesPagedResponse; 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.orgpolicy.v2.CreatePolicyRequest; 29 import com.google.cloud.orgpolicy.v2.DeletePolicyRequest; 30 import com.google.cloud.orgpolicy.v2.GetEffectivePolicyRequest; 31 import com.google.cloud.orgpolicy.v2.GetPolicyRequest; 32 import com.google.cloud.orgpolicy.v2.ListConstraintsRequest; 33 import com.google.cloud.orgpolicy.v2.ListConstraintsResponse; 34 import com.google.cloud.orgpolicy.v2.ListPoliciesRequest; 35 import com.google.cloud.orgpolicy.v2.ListPoliciesResponse; 36 import com.google.cloud.orgpolicy.v2.Policy; 37 import com.google.cloud.orgpolicy.v2.UpdatePolicyRequest; 38 import com.google.common.collect.ImmutableMap; 39 import com.google.longrunning.stub.GrpcOperationsStub; 40 import com.google.protobuf.Empty; 41 import io.grpc.MethodDescriptor; 42 import io.grpc.protobuf.ProtoUtils; 43 import java.io.IOException; 44 import java.util.concurrent.TimeUnit; 45 import javax.annotation.Generated; 46 47 // AUTO-GENERATED DOCUMENTATION AND CLASS. 48 /** 49 * gRPC stub implementation for the OrgPolicy service API. 50 * 51 * <p>This class is for advanced usage and reflects the underlying API directly. 52 */ 53 @Generated("by gapic-generator-java") 54 public class GrpcOrgPolicyStub extends OrgPolicyStub { 55 private static final MethodDescriptor<ListConstraintsRequest, ListConstraintsResponse> 56 listConstraintsMethodDescriptor = 57 MethodDescriptor.<ListConstraintsRequest, ListConstraintsResponse>newBuilder() 58 .setType(MethodDescriptor.MethodType.UNARY) 59 .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/ListConstraints") 60 .setRequestMarshaller( 61 ProtoUtils.marshaller(ListConstraintsRequest.getDefaultInstance())) 62 .setResponseMarshaller( 63 ProtoUtils.marshaller(ListConstraintsResponse.getDefaultInstance())) 64 .build(); 65 66 private static final MethodDescriptor<ListPoliciesRequest, ListPoliciesResponse> 67 listPoliciesMethodDescriptor = 68 MethodDescriptor.<ListPoliciesRequest, ListPoliciesResponse>newBuilder() 69 .setType(MethodDescriptor.MethodType.UNARY) 70 .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/ListPolicies") 71 .setRequestMarshaller(ProtoUtils.marshaller(ListPoliciesRequest.getDefaultInstance())) 72 .setResponseMarshaller( 73 ProtoUtils.marshaller(ListPoliciesResponse.getDefaultInstance())) 74 .build(); 75 76 private static final MethodDescriptor<GetPolicyRequest, Policy> getPolicyMethodDescriptor = 77 MethodDescriptor.<GetPolicyRequest, Policy>newBuilder() 78 .setType(MethodDescriptor.MethodType.UNARY) 79 .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/GetPolicy") 80 .setRequestMarshaller(ProtoUtils.marshaller(GetPolicyRequest.getDefaultInstance())) 81 .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) 82 .build(); 83 84 private static final MethodDescriptor<GetEffectivePolicyRequest, Policy> 85 getEffectivePolicyMethodDescriptor = 86 MethodDescriptor.<GetEffectivePolicyRequest, Policy>newBuilder() 87 .setType(MethodDescriptor.MethodType.UNARY) 88 .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/GetEffectivePolicy") 89 .setRequestMarshaller( 90 ProtoUtils.marshaller(GetEffectivePolicyRequest.getDefaultInstance())) 91 .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) 92 .build(); 93 94 private static final MethodDescriptor<CreatePolicyRequest, Policy> createPolicyMethodDescriptor = 95 MethodDescriptor.<CreatePolicyRequest, Policy>newBuilder() 96 .setType(MethodDescriptor.MethodType.UNARY) 97 .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/CreatePolicy") 98 .setRequestMarshaller(ProtoUtils.marshaller(CreatePolicyRequest.getDefaultInstance())) 99 .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) 100 .build(); 101 102 private static final MethodDescriptor<UpdatePolicyRequest, Policy> updatePolicyMethodDescriptor = 103 MethodDescriptor.<UpdatePolicyRequest, Policy>newBuilder() 104 .setType(MethodDescriptor.MethodType.UNARY) 105 .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/UpdatePolicy") 106 .setRequestMarshaller(ProtoUtils.marshaller(UpdatePolicyRequest.getDefaultInstance())) 107 .setResponseMarshaller(ProtoUtils.marshaller(Policy.getDefaultInstance())) 108 .build(); 109 110 private static final MethodDescriptor<DeletePolicyRequest, Empty> deletePolicyMethodDescriptor = 111 MethodDescriptor.<DeletePolicyRequest, Empty>newBuilder() 112 .setType(MethodDescriptor.MethodType.UNARY) 113 .setFullMethodName("google.cloud.orgpolicy.v2.OrgPolicy/DeletePolicy") 114 .setRequestMarshaller(ProtoUtils.marshaller(DeletePolicyRequest.getDefaultInstance())) 115 .setResponseMarshaller(ProtoUtils.marshaller(Empty.getDefaultInstance())) 116 .build(); 117 118 private final UnaryCallable<ListConstraintsRequest, ListConstraintsResponse> 119 listConstraintsCallable; 120 private final UnaryCallable<ListConstraintsRequest, ListConstraintsPagedResponse> 121 listConstraintsPagedCallable; 122 private final UnaryCallable<ListPoliciesRequest, ListPoliciesResponse> listPoliciesCallable; 123 private final UnaryCallable<ListPoliciesRequest, ListPoliciesPagedResponse> 124 listPoliciesPagedCallable; 125 private final UnaryCallable<GetPolicyRequest, Policy> getPolicyCallable; 126 private final UnaryCallable<GetEffectivePolicyRequest, Policy> getEffectivePolicyCallable; 127 private final UnaryCallable<CreatePolicyRequest, Policy> createPolicyCallable; 128 private final UnaryCallable<UpdatePolicyRequest, Policy> updatePolicyCallable; 129 private final UnaryCallable<DeletePolicyRequest, Empty> deletePolicyCallable; 130 131 private final BackgroundResource backgroundResources; 132 private final GrpcOperationsStub operationsStub; 133 private final GrpcStubCallableFactory callableFactory; 134 create(OrgPolicyStubSettings settings)135 public static final GrpcOrgPolicyStub create(OrgPolicyStubSettings settings) throws IOException { 136 return new GrpcOrgPolicyStub(settings, ClientContext.create(settings)); 137 } 138 create(ClientContext clientContext)139 public static final GrpcOrgPolicyStub create(ClientContext clientContext) throws IOException { 140 return new GrpcOrgPolicyStub(OrgPolicyStubSettings.newBuilder().build(), clientContext); 141 } 142 create( ClientContext clientContext, GrpcStubCallableFactory callableFactory)143 public static final GrpcOrgPolicyStub create( 144 ClientContext clientContext, GrpcStubCallableFactory callableFactory) throws IOException { 145 return new GrpcOrgPolicyStub( 146 OrgPolicyStubSettings.newBuilder().build(), clientContext, callableFactory); 147 } 148 149 /** 150 * Constructs an instance of GrpcOrgPolicyStub, using the given settings. This is protected so 151 * that it is easy to make a subclass, but otherwise, the static factory methods should be 152 * preferred. 153 */ GrpcOrgPolicyStub(OrgPolicyStubSettings settings, ClientContext clientContext)154 protected GrpcOrgPolicyStub(OrgPolicyStubSettings settings, ClientContext clientContext) 155 throws IOException { 156 this(settings, clientContext, new GrpcOrgPolicyCallableFactory()); 157 } 158 159 /** 160 * Constructs an instance of GrpcOrgPolicyStub, using the given settings. This is protected so 161 * that it is easy to make a subclass, but otherwise, the static factory methods should be 162 * preferred. 163 */ GrpcOrgPolicyStub( OrgPolicyStubSettings settings, ClientContext clientContext, GrpcStubCallableFactory callableFactory)164 protected GrpcOrgPolicyStub( 165 OrgPolicyStubSettings settings, 166 ClientContext clientContext, 167 GrpcStubCallableFactory callableFactory) 168 throws IOException { 169 this.callableFactory = callableFactory; 170 this.operationsStub = GrpcOperationsStub.create(clientContext, callableFactory); 171 172 GrpcCallSettings<ListConstraintsRequest, ListConstraintsResponse> 173 listConstraintsTransportSettings = 174 GrpcCallSettings.<ListConstraintsRequest, ListConstraintsResponse>newBuilder() 175 .setMethodDescriptor(listConstraintsMethodDescriptor) 176 .setParamsExtractor( 177 request -> { 178 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 179 params.put("parent", String.valueOf(request.getParent())); 180 return params.build(); 181 }) 182 .build(); 183 GrpcCallSettings<ListPoliciesRequest, ListPoliciesResponse> listPoliciesTransportSettings = 184 GrpcCallSettings.<ListPoliciesRequest, ListPoliciesResponse>newBuilder() 185 .setMethodDescriptor(listPoliciesMethodDescriptor) 186 .setParamsExtractor( 187 request -> { 188 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 189 params.put("parent", String.valueOf(request.getParent())); 190 return params.build(); 191 }) 192 .build(); 193 GrpcCallSettings<GetPolicyRequest, Policy> getPolicyTransportSettings = 194 GrpcCallSettings.<GetPolicyRequest, Policy>newBuilder() 195 .setMethodDescriptor(getPolicyMethodDescriptor) 196 .setParamsExtractor( 197 request -> { 198 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 199 params.put("name", String.valueOf(request.getName())); 200 return params.build(); 201 }) 202 .build(); 203 GrpcCallSettings<GetEffectivePolicyRequest, Policy> getEffectivePolicyTransportSettings = 204 GrpcCallSettings.<GetEffectivePolicyRequest, Policy>newBuilder() 205 .setMethodDescriptor(getEffectivePolicyMethodDescriptor) 206 .setParamsExtractor( 207 request -> { 208 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 209 params.put("name", String.valueOf(request.getName())); 210 return params.build(); 211 }) 212 .build(); 213 GrpcCallSettings<CreatePolicyRequest, Policy> createPolicyTransportSettings = 214 GrpcCallSettings.<CreatePolicyRequest, Policy>newBuilder() 215 .setMethodDescriptor(createPolicyMethodDescriptor) 216 .setParamsExtractor( 217 request -> { 218 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 219 params.put("parent", String.valueOf(request.getParent())); 220 return params.build(); 221 }) 222 .build(); 223 GrpcCallSettings<UpdatePolicyRequest, Policy> updatePolicyTransportSettings = 224 GrpcCallSettings.<UpdatePolicyRequest, Policy>newBuilder() 225 .setMethodDescriptor(updatePolicyMethodDescriptor) 226 .setParamsExtractor( 227 request -> { 228 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 229 params.put("policy.name", String.valueOf(request.getPolicy().getName())); 230 return params.build(); 231 }) 232 .build(); 233 GrpcCallSettings<DeletePolicyRequest, Empty> deletePolicyTransportSettings = 234 GrpcCallSettings.<DeletePolicyRequest, Empty>newBuilder() 235 .setMethodDescriptor(deletePolicyMethodDescriptor) 236 .setParamsExtractor( 237 request -> { 238 ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); 239 params.put("name", String.valueOf(request.getName())); 240 return params.build(); 241 }) 242 .build(); 243 244 this.listConstraintsCallable = 245 callableFactory.createUnaryCallable( 246 listConstraintsTransportSettings, settings.listConstraintsSettings(), clientContext); 247 this.listConstraintsPagedCallable = 248 callableFactory.createPagedCallable( 249 listConstraintsTransportSettings, settings.listConstraintsSettings(), clientContext); 250 this.listPoliciesCallable = 251 callableFactory.createUnaryCallable( 252 listPoliciesTransportSettings, settings.listPoliciesSettings(), clientContext); 253 this.listPoliciesPagedCallable = 254 callableFactory.createPagedCallable( 255 listPoliciesTransportSettings, settings.listPoliciesSettings(), clientContext); 256 this.getPolicyCallable = 257 callableFactory.createUnaryCallable( 258 getPolicyTransportSettings, settings.getPolicySettings(), clientContext); 259 this.getEffectivePolicyCallable = 260 callableFactory.createUnaryCallable( 261 getEffectivePolicyTransportSettings, 262 settings.getEffectivePolicySettings(), 263 clientContext); 264 this.createPolicyCallable = 265 callableFactory.createUnaryCallable( 266 createPolicyTransportSettings, settings.createPolicySettings(), clientContext); 267 this.updatePolicyCallable = 268 callableFactory.createUnaryCallable( 269 updatePolicyTransportSettings, settings.updatePolicySettings(), clientContext); 270 this.deletePolicyCallable = 271 callableFactory.createUnaryCallable( 272 deletePolicyTransportSettings, settings.deletePolicySettings(), clientContext); 273 274 this.backgroundResources = 275 new BackgroundResourceAggregation(clientContext.getBackgroundResources()); 276 } 277 getOperationsStub()278 public GrpcOperationsStub getOperationsStub() { 279 return operationsStub; 280 } 281 282 @Override listConstraintsCallable()283 public UnaryCallable<ListConstraintsRequest, ListConstraintsResponse> listConstraintsCallable() { 284 return listConstraintsCallable; 285 } 286 287 @Override 288 public UnaryCallable<ListConstraintsRequest, ListConstraintsPagedResponse> listConstraintsPagedCallable()289 listConstraintsPagedCallable() { 290 return listConstraintsPagedCallable; 291 } 292 293 @Override listPoliciesCallable()294 public UnaryCallable<ListPoliciesRequest, ListPoliciesResponse> listPoliciesCallable() { 295 return listPoliciesCallable; 296 } 297 298 @Override listPoliciesPagedCallable()299 public UnaryCallable<ListPoliciesRequest, ListPoliciesPagedResponse> listPoliciesPagedCallable() { 300 return listPoliciesPagedCallable; 301 } 302 303 @Override getPolicyCallable()304 public UnaryCallable<GetPolicyRequest, Policy> getPolicyCallable() { 305 return getPolicyCallable; 306 } 307 308 @Override getEffectivePolicyCallable()309 public UnaryCallable<GetEffectivePolicyRequest, Policy> getEffectivePolicyCallable() { 310 return getEffectivePolicyCallable; 311 } 312 313 @Override createPolicyCallable()314 public UnaryCallable<CreatePolicyRequest, Policy> createPolicyCallable() { 315 return createPolicyCallable; 316 } 317 318 @Override updatePolicyCallable()319 public UnaryCallable<UpdatePolicyRequest, Policy> updatePolicyCallable() { 320 return updatePolicyCallable; 321 } 322 323 @Override deletePolicyCallable()324 public UnaryCallable<DeletePolicyRequest, Empty> deletePolicyCallable() { 325 return deletePolicyCallable; 326 } 327 328 @Override close()329 public final void close() { 330 try { 331 backgroundResources.close(); 332 } catch (RuntimeException e) { 333 throw e; 334 } catch (Exception e) { 335 throw new IllegalStateException("Failed to close resource", e); 336 } 337 } 338 339 @Override shutdown()340 public void shutdown() { 341 backgroundResources.shutdown(); 342 } 343 344 @Override isShutdown()345 public boolean isShutdown() { 346 return backgroundResources.isShutdown(); 347 } 348 349 @Override isTerminated()350 public boolean isTerminated() { 351 return backgroundResources.isTerminated(); 352 } 353 354 @Override shutdownNow()355 public void shutdownNow() { 356 backgroundResources.shutdownNow(); 357 } 358 359 @Override awaitTermination(long duration, TimeUnit unit)360 public boolean awaitTermination(long duration, TimeUnit unit) throws InterruptedException { 361 return backgroundResources.awaitTermination(duration, unit); 362 } 363 } 364