Google Cloud Spanner C++ Client  1.33.0
A C++ Client Library for Google Cloud Spanner
instance_admin_connection.cc
Go to the documentation of this file.
1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 // Generated by the Codegen C++ plugin.
16 // If you make any local changes, they will be lost.
17 // source: google/spanner/admin/instance/v1/spanner_instance_admin.proto
18 
19 #include "google/cloud/spanner/admin/instance_admin_connection.h"
20 #include "google/cloud/spanner/admin/instance_admin_options.h"
21 #include "google/cloud/spanner/admin/internal/instance_admin_option_defaults.h"
22 #include "google/cloud/spanner/admin/internal/instance_admin_stub_factory.h"
23 #include "google/cloud/background_threads.h"
24 #include "google/cloud/grpc_options.h"
25 #include "google/cloud/internal/async_long_running_operation.h"
26 #include "google/cloud/internal/pagination_range.h"
27 #include "google/cloud/internal/retry_loop.h"
28 #include <memory>
29 
30 namespace google {
31 namespace cloud {
32 namespace spanner_admin {
34 
36 
37 StreamRange<google::spanner::admin::instance::v1::InstanceConfig>
39  google::spanner::admin::instance::v1::ListInstanceConfigsRequest request) {
40  return google::cloud::internal::MakePaginationRange<
41  StreamRange<google::spanner::admin::instance::v1::InstanceConfig>>(
42  std::move(request),
43  [](google::spanner::admin::instance::v1::
44  ListInstanceConfigsRequest const&) {
45  return StatusOr<google::spanner::admin::instance::v1::
46  ListInstanceConfigsResponse>{};
47  },
48  [](google::spanner::admin::instance::v1::
49  ListInstanceConfigsResponse const&) {
50  return std::vector<
51  google::spanner::admin::instance::v1::InstanceConfig>();
52  });
53 }
54 
55 StatusOr<google::spanner::admin::instance::v1::InstanceConfig>
57  google::spanner::admin::instance::v1::GetInstanceConfigRequest const&) {
58  return Status(StatusCode::kUnimplemented, "not implemented");
59 }
60 
61 StreamRange<google::spanner::admin::instance::v1::Instance>
63  google::spanner::admin::instance::v1::ListInstancesRequest request) {
64  return google::cloud::internal::MakePaginationRange<
65  StreamRange<google::spanner::admin::instance::v1::Instance>>(
66  std::move(request),
67  [](google::spanner::admin::instance::v1::ListInstancesRequest const&) {
68  return StatusOr<
69  google::spanner::admin::instance::v1::ListInstancesResponse>{};
70  },
71  [](google::spanner::admin::instance::v1::ListInstancesResponse const&) {
72  return std::vector<google::spanner::admin::instance::v1::Instance>();
73  });
74 }
75 
76 StatusOr<google::spanner::admin::instance::v1::Instance>
78  google::spanner::admin::instance::v1::GetInstanceRequest const&) {
79  return Status(StatusCode::kUnimplemented, "not implemented");
80 }
81 
82 future<StatusOr<google::spanner::admin::instance::v1::Instance>>
84  google::spanner::admin::instance::v1::CreateInstanceRequest const&) {
86  StatusOr<google::spanner::admin::instance::v1::Instance>>(
87  Status(StatusCode::kUnimplemented, "not implemented"));
88 }
89 
90 future<StatusOr<google::spanner::admin::instance::v1::Instance>>
92  google::spanner::admin::instance::v1::UpdateInstanceRequest const&) {
94  StatusOr<google::spanner::admin::instance::v1::Instance>>(
95  Status(StatusCode::kUnimplemented, "not implemented"));
96 }
97 
99  google::spanner::admin::instance::v1::DeleteInstanceRequest const&) {
100  return Status(StatusCode::kUnimplemented, "not implemented");
101 }
102 
103 StatusOr<google::iam::v1::Policy> InstanceAdminConnection::SetIamPolicy(
104  google::iam::v1::SetIamPolicyRequest const&) {
105  return Status(StatusCode::kUnimplemented, "not implemented");
106 }
107 
108 StatusOr<google::iam::v1::Policy> InstanceAdminConnection::GetIamPolicy(
109  google::iam::v1::GetIamPolicyRequest const&) {
110  return Status(StatusCode::kUnimplemented, "not implemented");
111 }
112 
113 StatusOr<google::iam::v1::TestIamPermissionsResponse>
115  google::iam::v1::TestIamPermissionsRequest const&) {
116  return Status(StatusCode::kUnimplemented, "not implemented");
117 }
118 
119 namespace {
120 class InstanceAdminConnectionImpl : public InstanceAdminConnection {
121  public:
122  InstanceAdminConnectionImpl(
123  std::unique_ptr<google::cloud::BackgroundThreads> background,
124  std::shared_ptr<spanner_admin_internal::InstanceAdminStub> stub,
125  Options const& options)
126  : background_(std::move(background)),
127  stub_(std::move(stub)),
128  retry_policy_prototype_(
130  backoff_policy_prototype_(
132  polling_policy_prototype_(
134  idempotency_policy_(
136  ->clone()) {}
137 
138  ~InstanceAdminConnectionImpl() override = default;
139 
140  StreamRange<google::spanner::admin::instance::v1::InstanceConfig>
141  ListInstanceConfigs(
142  google::spanner::admin::instance::v1::ListInstanceConfigsRequest request)
143  override {
144  request.clear_page_token();
145  auto stub = stub_;
146  auto retry = std::shared_ptr<InstanceAdminRetryPolicy const>(
147  retry_policy_prototype_->clone());
148  auto backoff = std::shared_ptr<BackoffPolicy const>(
149  backoff_policy_prototype_->clone());
150  auto idempotency = idempotency_policy_->ListInstanceConfigs(request);
151  char const* function_name = __func__;
152  return google::cloud::internal::MakePaginationRange<
153  StreamRange<google::spanner::admin::instance::v1::InstanceConfig>>(
154  std::move(request),
155  [stub, retry, backoff, idempotency,
156  function_name](google::spanner::admin::instance::v1::
157  ListInstanceConfigsRequest const& r) {
158  return google::cloud::internal::RetryLoop(
159  retry->clone(), backoff->clone(), idempotency,
160  [stub](grpc::ClientContext& context,
161  google::spanner::admin::instance::v1::
162  ListInstanceConfigsRequest const& request) {
163  return stub->ListInstanceConfigs(context, request);
164  },
165  r, function_name);
166  },
167  [](google::spanner::admin::instance::v1::ListInstanceConfigsResponse
168  r) {
169  std::vector<google::spanner::admin::instance::v1::InstanceConfig>
170  result(r.instance_configs().size());
171  auto& messages = *r.mutable_instance_configs();
172  std::move(messages.begin(), messages.end(), result.begin());
173  return result;
174  });
175  }
176 
177  StatusOr<google::spanner::admin::instance::v1::InstanceConfig>
178  GetInstanceConfig(
179  google::spanner::admin::instance::v1::GetInstanceConfigRequest const&
180  request) override {
181  return google::cloud::internal::RetryLoop(
182  retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
183  idempotency_policy_->GetInstanceConfig(request),
184  [this](grpc::ClientContext& context,
185  google::spanner::admin::instance::v1::
186  GetInstanceConfigRequest const& request) {
187  return stub_->GetInstanceConfig(context, request);
188  },
189  request, __func__);
190  }
191 
192  StreamRange<google::spanner::admin::instance::v1::Instance> ListInstances(
193  google::spanner::admin::instance::v1::ListInstancesRequest request)
194  override {
195  request.clear_page_token();
196  auto stub = stub_;
197  auto retry = std::shared_ptr<InstanceAdminRetryPolicy const>(
198  retry_policy_prototype_->clone());
199  auto backoff = std::shared_ptr<BackoffPolicy const>(
200  backoff_policy_prototype_->clone());
201  auto idempotency = idempotency_policy_->ListInstances(request);
202  char const* function_name = __func__;
203  return google::cloud::internal::MakePaginationRange<
204  StreamRange<google::spanner::admin::instance::v1::Instance>>(
205  std::move(request),
206  [stub, retry, backoff, idempotency, function_name](
207  google::spanner::admin::instance::v1::ListInstancesRequest const&
208  r) {
209  return google::cloud::internal::RetryLoop(
210  retry->clone(), backoff->clone(), idempotency,
211  [stub](grpc::ClientContext& context,
212  google::spanner::admin::instance::v1::
213  ListInstancesRequest const& request) {
214  return stub->ListInstances(context, request);
215  },
216  r, function_name);
217  },
218  [](google::spanner::admin::instance::v1::ListInstancesResponse r) {
219  std::vector<google::spanner::admin::instance::v1::Instance> result(
220  r.instances().size());
221  auto& messages = *r.mutable_instances();
222  std::move(messages.begin(), messages.end(), result.begin());
223  return result;
224  });
225  }
226 
227  StatusOr<google::spanner::admin::instance::v1::Instance> GetInstance(
228  google::spanner::admin::instance::v1::GetInstanceRequest const& request)
229  override {
230  return google::cloud::internal::RetryLoop(
231  retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
232  idempotency_policy_->GetInstance(request),
233  [this](grpc::ClientContext& context,
234  google::spanner::admin::instance::v1::GetInstanceRequest const&
235  request) { return stub_->GetInstance(context, request); },
236  request, __func__);
237  }
238 
239  future<StatusOr<google::spanner::admin::instance::v1::Instance>>
240  CreateInstance(
241  google::spanner::admin::instance::v1::CreateInstanceRequest const&
242  request) override {
243  auto stub = stub_;
244  return google::cloud::internal::AsyncLongRunningOperation<
245  google::spanner::admin::instance::v1::Instance>(
246  background_->cq(), request,
247  [stub](
249  std::unique_ptr<grpc::ClientContext> context,
250  google::spanner::admin::instance::v1::CreateInstanceRequest const&
251  request) {
252  return stub->AsyncCreateInstance(cq, std::move(context), request);
253  },
254  [stub](google::cloud::CompletionQueue& cq,
255  std::unique_ptr<grpc::ClientContext> context,
256  google::longrunning::GetOperationRequest const& request) {
257  return stub->AsyncGetOperation(cq, std::move(context), request);
258  },
259  [stub](google::cloud::CompletionQueue& cq,
260  std::unique_ptr<grpc::ClientContext> context,
261  google::longrunning::CancelOperationRequest const& request) {
262  return stub->AsyncCancelOperation(cq, std::move(context), request);
263  },
264  &google::cloud::internal::ExtractLongRunningResultResponse<
265  google::spanner::admin::instance::v1::Instance>,
266  retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
267  idempotency_policy_->CreateInstance(request),
268  polling_policy_prototype_->clone(), __func__);
269  }
270 
271  future<StatusOr<google::spanner::admin::instance::v1::Instance>>
272  UpdateInstance(
273  google::spanner::admin::instance::v1::UpdateInstanceRequest const&
274  request) override {
275  auto stub = stub_;
276  return google::cloud::internal::AsyncLongRunningOperation<
277  google::spanner::admin::instance::v1::Instance>(
278  background_->cq(), request,
279  [stub](
281  std::unique_ptr<grpc::ClientContext> context,
282  google::spanner::admin::instance::v1::UpdateInstanceRequest const&
283  request) {
284  return stub->AsyncUpdateInstance(cq, std::move(context), request);
285  },
286  [stub](google::cloud::CompletionQueue& cq,
287  std::unique_ptr<grpc::ClientContext> context,
288  google::longrunning::GetOperationRequest const& request) {
289  return stub->AsyncGetOperation(cq, std::move(context), request);
290  },
291  [stub](google::cloud::CompletionQueue& cq,
292  std::unique_ptr<grpc::ClientContext> context,
293  google::longrunning::CancelOperationRequest const& request) {
294  return stub->AsyncCancelOperation(cq, std::move(context), request);
295  },
296  &google::cloud::internal::ExtractLongRunningResultResponse<
297  google::spanner::admin::instance::v1::Instance>,
298  retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
299  idempotency_policy_->UpdateInstance(request),
300  polling_policy_prototype_->clone(), __func__);
301  }
302 
303  Status DeleteInstance(
304  google::spanner::admin::instance::v1::DeleteInstanceRequest const&
305  request) override {
306  return google::cloud::internal::RetryLoop(
307  retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
308  idempotency_policy_->DeleteInstance(request),
309  [this](
310  grpc::ClientContext& context,
311  google::spanner::admin::instance::v1::DeleteInstanceRequest const&
312  request) { return stub_->DeleteInstance(context, request); },
313  request, __func__);
314  }
315 
316  StatusOr<google::iam::v1::Policy> SetIamPolicy(
317  google::iam::v1::SetIamPolicyRequest const& request) override {
318  return google::cloud::internal::RetryLoop(
319  retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
320  idempotency_policy_->SetIamPolicy(request),
321  [this](grpc::ClientContext& context,
322  google::iam::v1::SetIamPolicyRequest const& request) {
323  return stub_->SetIamPolicy(context, request);
324  },
325  request, __func__);
326  }
327 
328  StatusOr<google::iam::v1::Policy> GetIamPolicy(
329  google::iam::v1::GetIamPolicyRequest const& request) override {
330  return google::cloud::internal::RetryLoop(
331  retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
332  idempotency_policy_->GetIamPolicy(request),
333  [this](grpc::ClientContext& context,
334  google::iam::v1::GetIamPolicyRequest const& request) {
335  return stub_->GetIamPolicy(context, request);
336  },
337  request, __func__);
338  }
339 
340  StatusOr<google::iam::v1::TestIamPermissionsResponse> TestIamPermissions(
341  google::iam::v1::TestIamPermissionsRequest const& request) override {
342  return google::cloud::internal::RetryLoop(
343  retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
344  idempotency_policy_->TestIamPermissions(request),
345  [this](grpc::ClientContext& context,
346  google::iam::v1::TestIamPermissionsRequest const& request) {
347  return stub_->TestIamPermissions(context, request);
348  },
349  request, __func__);
350  }
351 
352  private:
353  std::unique_ptr<google::cloud::BackgroundThreads> background_;
354  std::shared_ptr<spanner_admin_internal::InstanceAdminStub> stub_;
355  std::unique_ptr<InstanceAdminRetryPolicy const> retry_policy_prototype_;
356  std::unique_ptr<BackoffPolicy const> backoff_policy_prototype_;
357  std::unique_ptr<PollingPolicy const> polling_policy_prototype_;
358  std::unique_ptr<InstanceAdminConnectionIdempotencyPolicy> idempotency_policy_;
359 };
360 } // namespace
361 
363  Options options) {
364  options =
366  auto background = internal::MakeBackgroundThreadsFactory(options)();
368  background->cq(), options);
369  return std::make_shared<InstanceAdminConnectionImpl>(
370  std::move(background), std::move(stub), options);
371 }
372 
374 } // namespace spanner_admin
375 } // namespace cloud
376 } // namespace google
377 
378 namespace google {
379 namespace cloud {
380 namespace spanner_admin_internal {
382 
383 std::shared_ptr<spanner_admin::InstanceAdminConnection>
385  Options options) {
386  options = InstanceAdminDefaultOptions(std::move(options));
387  return std::make_shared<spanner_admin::InstanceAdminConnectionImpl>(
388  internal::MakeBackgroundThreadsFactory(options)(), std::move(stub),
389  std::move(options));
390 }
391 
393 } // namespace spanner_admin_internal
394 } // namespace cloud
395 } // namespace google