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"
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>>(
43 [](
google::spanner::admin::instance::v1::
44 ListInstanceConfigsRequest
const&) {
46 ListInstanceConfigsResponse
>{};
48 [](
google::spanner::admin::instance::v1::
49 ListInstanceConfigsResponse
const&) {
51 google::spanner::admin::instance::v1::InstanceConfig>();
55 StatusOr<
google::spanner::admin::instance::v1::InstanceConfig>
57 google::spanner::admin::instance::v1::GetInstanceConfigRequest
const&) {
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>>(
67 [](
google::spanner::admin::instance::v1::ListInstancesRequest
const&) {
71 [](
google::spanner::admin::instance::v1::ListInstancesResponse
const&) {
72 return std::vector<
google::spanner::admin::instance::v1::Instance>();
76 StatusOr<
google::spanner::admin::instance::v1::Instance>
78 google::spanner::admin::instance::v1::GetInstanceRequest
const&) {
82 future<StatusOr<
google::spanner::admin::instance::v1::Instance>>
84 google::spanner::admin::instance::v1::CreateInstanceRequest
const&) {
90 future<StatusOr<
google::spanner::admin::instance::v1::Instance>>
92 google::spanner::admin::instance::v1::UpdateInstanceRequest
const&) {
99 google::spanner::admin::instance::v1::DeleteInstanceRequest
const&) {
104 google::iam::v1::SetIamPolicyRequest
const&) {
109 google::iam::v1::GetIamPolicyRequest
const&) {
113 StatusOr<
google::iam::v1::TestIamPermissionsResponse>
115 google::iam::v1::TestIamPermissionsRequest
const&) {
122 InstanceAdminConnectionImpl(
126 : background_(std::move(background)),
127 stub_(std::move(stub)),
128 retry_policy_prototype_(
130 backoff_policy_prototype_(
132 polling_policy_prototype_(
138 ~InstanceAdminConnectionImpl()
override =
default;
140 StreamRange<
google::spanner::admin::instance::v1::InstanceConfig>
142 google::spanner::admin::instance::v1::ListInstanceConfigsRequest request)
144 request.clear_page_token();
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());
151 char const* function_name =
__func__;
152 return google::
cloud::internal::MakePaginationRange<
153 StreamRange<
google::spanner::admin::instance::v1::InstanceConfig>>(
155 [stub, retry, backoff, idempotency,
156 function_name](
google::spanner::admin::instance::v1::
157 ListInstanceConfigsRequest
const& r) {
159 retry->clone(), backoff->clone(), idempotency,
160 [stub](grpc::ClientContext& context,
161 google::spanner::admin::instance::v1::
162 ListInstanceConfigsRequest
const& request) {
167 [](
google::spanner::admin::instance::v1::ListInstanceConfigsResponse
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());
177 StatusOr<
google::spanner::admin::instance::v1::InstanceConfig>
179 google::spanner::admin::instance::v1::GetInstanceConfigRequest
const&
182 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
184 [
this](grpc::ClientContext& context,
185 google::spanner::admin::instance::v1::
186 GetInstanceConfigRequest
const& request) {
192 StreamRange<
google::spanner::admin::instance::v1::Instance> ListInstances(
193 google::spanner::admin::instance::v1::ListInstancesRequest request)
195 request.clear_page_token();
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());
202 char const* function_name =
__func__;
203 return google::
cloud::internal::MakePaginationRange<
204 StreamRange<
google::spanner::admin::instance::v1::Instance>>(
206 [stub, retry, backoff, idempotency, function_name](
207 google::spanner::admin::instance::v1::ListInstancesRequest
const&
210 retry->clone(), backoff->clone(), idempotency,
211 [stub](grpc::ClientContext& context,
212 google::spanner::admin::instance::v1::
213 ListInstancesRequest
const& request) {
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());
227 StatusOr<
google::spanner::admin::instance::v1::Instance> GetInstance(
228 google::spanner::admin::instance::v1::GetInstanceRequest
const& request)
231 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
233 [
this](grpc::ClientContext& context,
234 google::spanner::admin::instance::v1::GetInstanceRequest
const&
239 future<StatusOr<
google::spanner::admin::instance::v1::Instance>>
241 google::spanner::admin::instance::v1::CreateInstanceRequest
const&
244 return google::
cloud::internal::AsyncLongRunningOperation<
245 google::spanner::admin::instance::v1::Instance>(
246 background_->
cq(), request,
249 std::unique_ptr<grpc::ClientContext> context,
250 google::spanner::admin::instance::v1::CreateInstanceRequest
const&
255 std::unique_ptr<grpc::ClientContext> context,
256 google::longrunning::GetOperationRequest
const& request) {
260 std::unique_ptr<grpc::ClientContext> context,
261 google::longrunning::CancelOperationRequest
const& request) {
264 &
google::
cloud::internal::ExtractLongRunningResultResponse<
265 google::spanner::admin::instance::v1::Instance>,
266 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
268 polling_policy_prototype_->
clone(),
__func__);
271 future<StatusOr<
google::spanner::admin::instance::v1::Instance>>
273 google::spanner::admin::instance::v1::UpdateInstanceRequest
const&
276 return google::
cloud::internal::AsyncLongRunningOperation<
277 google::spanner::admin::instance::v1::Instance>(
278 background_->
cq(), request,
281 std::unique_ptr<grpc::ClientContext> context,
282 google::spanner::admin::instance::v1::UpdateInstanceRequest
const&
287 std::unique_ptr<grpc::ClientContext> context,
288 google::longrunning::GetOperationRequest
const& request) {
292 std::unique_ptr<grpc::ClientContext> context,
293 google::longrunning::CancelOperationRequest
const& request) {
296 &
google::
cloud::internal::ExtractLongRunningResultResponse<
297 google::spanner::admin::instance::v1::Instance>,
298 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
300 polling_policy_prototype_->
clone(),
__func__);
304 google::spanner::admin::instance::v1::DeleteInstanceRequest
const&
307 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
310 grpc::ClientContext& context,
311 google::spanner::admin::instance::v1::DeleteInstanceRequest
const&
316 StatusOr<
google::iam::v1::Policy> SetIamPolicy(
317 google::iam::v1::SetIamPolicyRequest
const& request)
override {
319 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
321 [
this](grpc::ClientContext& context,
322 google::iam::v1::SetIamPolicyRequest
const& request) {
328 StatusOr<
google::iam::v1::Policy> GetIamPolicy(
329 google::iam::v1::GetIamPolicyRequest
const& request)
override {
331 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
333 [
this](grpc::ClientContext& context,
334 google::iam::v1::GetIamPolicyRequest
const& request) {
340 StatusOr<
google::iam::v1::TestIamPermissionsResponse> TestIamPermissions(
341 google::iam::v1::TestIamPermissionsRequest
const& request)
override {
343 retry_policy_prototype_->clone(), backoff_policy_prototype_->clone(),
345 [
this](grpc::ClientContext& context,
346 google::iam::v1::TestIamPermissionsRequest
const& request) {
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_;
366 auto background = internal::MakeBackgroundThreadsFactory(options)();
368 background->
cq(), options
);
369 return std::make_shared<InstanceAdminConnectionImpl>(
370 std::move(background), std::move(stub), options);
387 return std::make_shared<
spanner_admin::InstanceAdminConnectionImpl>(
388 internal::MakeBackgroundThreadsFactory(options)(), std::move(stub),