Google Cloud Spanner C++ Client  1.32.0
A C++ Client Library for Google Cloud Spanner
database_admin_client.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/database/v1/spanner_database_admin.proto
18 
19 #include "google/cloud/spanner/admin/database_admin_client.h"
20 #include "google/cloud/spanner/admin/database_admin_options.h"
21 #include "google/cloud/spanner/admin/internal/database_admin_option_defaults.h"
22 #include <memory>
23 #include <thread>
24 
25 namespace google {
26 namespace cloud {
27 namespace spanner_admin {
29 
31  std::shared_ptr<DatabaseAdminConnection> connection)
32  : connection_(std::move(connection)) {}
34 
35 StreamRange<google::spanner::admin::database::v1::Database>
36 DatabaseAdminClient::ListDatabases(std::string const& parent) {
37  google::spanner::admin::database::v1::ListDatabasesRequest request;
38  request.set_parent(parent);
39  return connection_->ListDatabases(request);
40 }
41 
42 future<StatusOr<google::spanner::admin::database::v1::Database>>
43 DatabaseAdminClient::CreateDatabase(std::string const& parent,
44  std::string const& create_statement) {
45  google::spanner::admin::database::v1::CreateDatabaseRequest request;
46  request.set_parent(parent);
47  request.set_create_statement(create_statement);
48  return connection_->CreateDatabase(request);
49 }
50 
51 StatusOr<google::spanner::admin::database::v1::Database>
52 DatabaseAdminClient::GetDatabase(std::string const& name) {
53  google::spanner::admin::database::v1::GetDatabaseRequest request;
54  request.set_name(name);
55  return connection_->GetDatabase(request);
56 }
57 
58 future<
59  StatusOr<google::spanner::admin::database::v1::UpdateDatabaseDdlMetadata>>
61  std::string const& database, std::vector<std::string> const& statements) {
62  google::spanner::admin::database::v1::UpdateDatabaseDdlRequest request;
63  request.set_database(database);
64  *request.mutable_statements() = {statements.begin(), statements.end()};
65  return connection_->UpdateDatabaseDdl(request);
66 }
67 
68 Status DatabaseAdminClient::DropDatabase(std::string const& database) {
69  google::spanner::admin::database::v1::DropDatabaseRequest request;
70  request.set_database(database);
71  return connection_->DropDatabase(request);
72 }
73 
74 StatusOr<google::spanner::admin::database::v1::GetDatabaseDdlResponse>
75 DatabaseAdminClient::GetDatabaseDdl(std::string const& database) {
76  google::spanner::admin::database::v1::GetDatabaseDdlRequest request;
77  request.set_database(database);
78  return connection_->GetDatabaseDdl(request);
79 }
80 
81 StatusOr<google::iam::v1::Policy> DatabaseAdminClient::SetIamPolicy(
82  std::string const& resource, google::iam::v1::Policy const& policy) {
83  google::iam::v1::SetIamPolicyRequest request;
84  request.set_resource(resource);
85  *request.mutable_policy() = policy;
86  return connection_->SetIamPolicy(request);
87 }
88 
89 StatusOr<google::iam::v1::Policy> DatabaseAdminClient::SetIamPolicy(
90  std::string const& resource, IamUpdater const& updater, Options options) {
91  internal::CheckExpectedOptions<DatabaseAdminBackoffPolicyOption>(options,
92  __func__);
93  options =
95  auto backoff_policy =
97  for (;;) {
98  auto recent = GetIamPolicy(resource);
99  if (!recent) {
100  return recent.status();
101  }
102  auto policy = updater(*std::move(recent));
103  if (!policy) {
104  return Status(StatusCode::kCancelled, "updater did not yield a policy");
105  }
106  auto result = SetIamPolicy(resource, *std::move(policy));
107  if (result || result.status().code() != StatusCode::kAborted) {
108  return result;
109  }
110  std::this_thread::sleep_for(backoff_policy->OnCompletion());
111  }
112 }
113 
114 StatusOr<google::iam::v1::Policy> DatabaseAdminClient::GetIamPolicy(
115  std::string const& resource) {
116  google::iam::v1::GetIamPolicyRequest request;
117  request.set_resource(resource);
118  return connection_->GetIamPolicy(request);
119 }
120 
121 StatusOr<google::iam::v1::TestIamPermissionsResponse>
123  std::string const& resource, std::vector<std::string> const& permissions) {
124  google::iam::v1::TestIamPermissionsRequest request;
125  request.set_resource(resource);
126  *request.mutable_permissions() = {permissions.begin(), permissions.end()};
127  return connection_->TestIamPermissions(request);
128 }
129 
130 future<StatusOr<google::spanner::admin::database::v1::Backup>>
132  std::string const& parent,
133  google::spanner::admin::database::v1::Backup const& backup,
134  std::string const& backup_id) {
135  google::spanner::admin::database::v1::CreateBackupRequest request;
136  request.set_parent(parent);
137  *request.mutable_backup() = backup;
138  request.set_backup_id(backup_id);
139  return connection_->CreateBackup(request);
140 }
141 
142 StatusOr<google::spanner::admin::database::v1::Backup>
143 DatabaseAdminClient::GetBackup(std::string const& name) {
144  google::spanner::admin::database::v1::GetBackupRequest request;
145  request.set_name(name);
146  return connection_->GetBackup(request);
147 }
148 
149 StatusOr<google::spanner::admin::database::v1::Backup>
151  google::spanner::admin::database::v1::Backup const& backup,
152  google::protobuf::FieldMask const& update_mask) {
153  google::spanner::admin::database::v1::UpdateBackupRequest request;
154  *request.mutable_backup() = backup;
155  *request.mutable_update_mask() = update_mask;
156  return connection_->UpdateBackup(request);
157 }
158 
159 Status DatabaseAdminClient::DeleteBackup(std::string const& name) {
160  google::spanner::admin::database::v1::DeleteBackupRequest request;
161  request.set_name(name);
162  return connection_->DeleteBackup(request);
163 }
164 
165 StreamRange<google::spanner::admin::database::v1::Backup>
166 DatabaseAdminClient::ListBackups(std::string const& parent) {
167  google::spanner::admin::database::v1::ListBackupsRequest request;
168  request.set_parent(parent);
169  return connection_->ListBackups(request);
170 }
171 
172 future<StatusOr<google::spanner::admin::database::v1::Database>>
173 DatabaseAdminClient::RestoreDatabase(std::string const& parent,
174  std::string const& database_id,
175  std::string const& backup) {
176  google::spanner::admin::database::v1::RestoreDatabaseRequest request;
177  request.set_parent(parent);
178  request.set_database_id(database_id);
179  request.set_backup(backup);
180  return connection_->RestoreDatabase(request);
181 }
182 
183 StreamRange<google::longrunning::Operation>
184 DatabaseAdminClient::ListDatabaseOperations(std::string const& parent) {
185  google::spanner::admin::database::v1::ListDatabaseOperationsRequest request;
186  request.set_parent(parent);
187  return connection_->ListDatabaseOperations(request);
188 }
189 
190 StreamRange<google::longrunning::Operation>
191 DatabaseAdminClient::ListBackupOperations(std::string const& parent) {
192  google::spanner::admin::database::v1::ListBackupOperationsRequest request;
193  request.set_parent(parent);
194  return connection_->ListBackupOperations(request);
195 }
196 
197 StreamRange<google::spanner::admin::database::v1::Database>
199  google::spanner::admin::database::v1::ListDatabasesRequest request) {
200  return connection_->ListDatabases(std::move(request));
201 }
202 
203 future<StatusOr<google::spanner::admin::database::v1::Database>>
205  google::spanner::admin::database::v1::CreateDatabaseRequest const&
206  request) {
207  return connection_->CreateDatabase(request);
208 }
209 
210 StatusOr<google::spanner::admin::database::v1::Database>
212  google::spanner::admin::database::v1::GetDatabaseRequest const& request) {
213  return connection_->GetDatabase(request);
214 }
215 
216 future<
217  StatusOr<google::spanner::admin::database::v1::UpdateDatabaseDdlMetadata>>
219  google::spanner::admin::database::v1::UpdateDatabaseDdlRequest const&
220  request) {
221  return connection_->UpdateDatabaseDdl(request);
222 }
223 
225  google::spanner::admin::database::v1::DropDatabaseRequest const& request) {
226  return connection_->DropDatabase(request);
227 }
228 
229 StatusOr<google::spanner::admin::database::v1::GetDatabaseDdlResponse>
231  google::spanner::admin::database::v1::GetDatabaseDdlRequest const&
232  request) {
233  return connection_->GetDatabaseDdl(request);
234 }
235 
236 StatusOr<google::iam::v1::Policy> DatabaseAdminClient::SetIamPolicy(
237  google::iam::v1::SetIamPolicyRequest const& request) {
238  return connection_->SetIamPolicy(request);
239 }
240 
241 StatusOr<google::iam::v1::Policy> DatabaseAdminClient::GetIamPolicy(
242  google::iam::v1::GetIamPolicyRequest const& request) {
243  return connection_->GetIamPolicy(request);
244 }
245 
246 StatusOr<google::iam::v1::TestIamPermissionsResponse>
248  google::iam::v1::TestIamPermissionsRequest const& request) {
249  return connection_->TestIamPermissions(request);
250 }
251 
252 future<StatusOr<google::spanner::admin::database::v1::Backup>>
254  google::spanner::admin::database::v1::CreateBackupRequest const& request) {
255  return connection_->CreateBackup(request);
256 }
257 
258 StatusOr<google::spanner::admin::database::v1::Backup>
260  google::spanner::admin::database::v1::GetBackupRequest const& request) {
261  return connection_->GetBackup(request);
262 }
263 
264 StatusOr<google::spanner::admin::database::v1::Backup>
266  google::spanner::admin::database::v1::UpdateBackupRequest const& request) {
267  return connection_->UpdateBackup(request);
268 }
269 
271  google::spanner::admin::database::v1::DeleteBackupRequest const& request) {
272  return connection_->DeleteBackup(request);
273 }
274 
275 StreamRange<google::spanner::admin::database::v1::Backup>
277  google::spanner::admin::database::v1::ListBackupsRequest request) {
278  return connection_->ListBackups(std::move(request));
279 }
280 
281 future<StatusOr<google::spanner::admin::database::v1::Database>>
283  google::spanner::admin::database::v1::RestoreDatabaseRequest const&
284  request) {
285  return connection_->RestoreDatabase(request);
286 }
287 
288 StreamRange<google::longrunning::Operation>
290  google::spanner::admin::database::v1::ListDatabaseOperationsRequest
291  request) {
292  return connection_->ListDatabaseOperations(std::move(request));
293 }
294 
295 StreamRange<google::longrunning::Operation>
297  google::spanner::admin::database::v1::ListBackupOperationsRequest request) {
298  return connection_->ListBackupOperations(std::move(request));
299 }
300 
301 } // namespace GOOGLE_CLOUD_CPP_GENERATED_NS
302 } // namespace spanner_admin
303 } // namespace cloud
304 } // namespace google