Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
database_admin_connection.h
1// Copyright 2019 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#ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_DATABASE_ADMIN_CONNECTION_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_DATABASE_ADMIN_CONNECTION_H
17
18#include "google/cloud/spanner/backoff_policy.h"
19#include "google/cloud/spanner/backup.h"
20#include "google/cloud/spanner/database.h"
21#include "google/cloud/spanner/encryption_config.h"
22#include "google/cloud/spanner/instance.h"
23#include "google/cloud/spanner/internal/database_admin_stub.h"
24#include "google/cloud/spanner/polling_policy.h"
25#include "google/cloud/spanner/retry_policy.h"
26#include "google/cloud/spanner/timestamp.h"
27#include "google/cloud/spanner/version.h"
28#include "google/cloud/backoff_policy.h"
29#include "google/cloud/internal/pagination_range.h"
30#include "google/cloud/options.h"
31#include "absl/types/optional.h"
32#include <google/spanner/admin/database/v1/spanner_database_admin.pb.h>
33#include <chrono>
34#include <string>
35#include <vector>
36
37namespace google {
38namespace cloud {
39namespace spanner {
40GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
41
42/**
43 * An input range to stream all the databases in a Cloud Spanner instance.
44 *
45 * This type models an [input range][cppref-input-range] of
46 * `google::spanner::admin::v1::Database` objects. Applications can make a
47 * single pass through the results.
48 *
49 * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
50 */
51using ListDatabaseRange = ::google::cloud::internal::PaginationRange<
52 google::spanner::admin::database::v1::Database>;
53
54/**
55 * An input range to stream backup operations in Cloud Spanner instance.
56 *
57 * This type models an [input range][cppref-input-range] of
58 * `google::longrunning::Operation` objects. Applications can make a
59 * single pass through the results.
60 *
61 * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
62 */
63using ListBackupOperationsRange =
64 google::cloud::internal::PaginationRange<google::longrunning::Operation>;
65
66/**
67 * An input range to stream database operations in Cloud Spanner instance.
68 *
69 * This type models an [input range][cppref-input-range] of
70 * `google::longrunning::Operation` objects. Applications can make a
71 * single pass through the results.
72 *
73 * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
74 */
75using ListDatabaseOperationsRange =
76 google::cloud::internal::PaginationRange<google::longrunning::Operation>;
77
78/**
79 * An input range to stream backups in Cloud Spanner instance.
80 *
81 * This type models an [input range][cppref-input-range] of
82 * `google::longrunning::Operation` objects. Applications can make a
83 * single pass through the results.
84 *
85 * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
86 */
87using ListBackupsRange = ::google::cloud::internal::PaginationRange<
88 google::spanner::admin::database::v1::Backup>;
89
90/**
91 * A connection to the Cloud Spanner instance administration service.
92 *
93 * @deprecated Please use #google::cloud::spanner_admin::DatabaseAdminClient
94 * and #google::cloud::spanner_admin::DatabaseAdminConnection instead.
95 *
96 * This interface defines pure-virtual methods for each of the user-facing
97 * overload sets in `DatabaseAdminClient`. This allows users to inject custom
98 * behavior (e.g., with a Google Mock object) in a `DatabaseAdminClient` object
99 * for use in their own tests.
100 *
101 * To create a concrete instance that connects you to a real Cloud Spanner
102 * instance administration service, see `MakeDatabaseAdminConnection()`.
103 */
104class GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED("DatabaseAdminConnection")
106 public:
107 virtual ~DatabaseAdminConnection() = 0;
108
109 ///@{
110 /**
111 * @name Define the arguments for each member function.
112 *
113 * Applications may define classes derived from `DatabaseAdminConnection`, for
114 * example, because they want to mock the class. To avoid breaking all such
115 * derived classes when we change the number or type of the arguments to the
116 * member functions we define light weight structures to pass the arguments.
117 */
118 /// Wrap the arguments for `CreateDatabase()`.
119 struct CreateDatabaseParams {
120 /// The name of the database.
122 /// Any additional statements to execute after creating the database.
123 std::vector<std::string> extra_statements;
124 /// How to encrypt the database.
125 EncryptionConfig encryption_config;
126 };
127
128 /// Wrap the arguments for `GetDatabase()`.
129 struct GetDatabaseParams {
130 /// The name of the database.
132 };
133
134 /// Wrap the arguments for `GetDatabaseDdl()`.
135 struct GetDatabaseDdlParams {
136 /// The name of the database.
138 };
139
140 /// Wrap the arguments for `UpdateDatabase()`.
141 struct UpdateDatabaseParams {
142 /// The name of the database.
144 /// The DDL statements updating the database schema.
145 std::vector<std::string> statements;
146 };
147
148 /// Wrap the arguments for `DropDatabase()`.
149 struct DropDatabaseParams {
150 /// The name of the database.
152 };
153
154 /// Wrap the arguments for `ListDatabases()`.
155 struct ListDatabasesParams {
156 /// The name of the instance.
158 };
159
160 /// Wrap the arguments for `GetIamPolicy()`.
161 struct GetIamPolicyParams {
162 /// The name of the database.
164 };
165
166 /// Wrap the arguments for `SetIamPolicy()`.
167 struct SetIamPolicyParams {
168 /// The name of the database.
170 google::iam::v1::Policy policy;
171 };
172
173 /// Wrap the arguments for `TestIamPermissions()`.
175 /// The name of the database.
177 std::vector<std::string> permissions;
178 };
179
180 /// Wrap the arguments for `CreateBackup()`.
181 struct CreateBackupParams {
182 /// The name of the database.
184 std::string backup_id;
185 /// @deprecated `DatabaseAdminClient::CreateBackup()` initializes
186 /// `expire_time`, but `DatabaseAdminConnection::CreateBackup()` now
187 /// ignores it. Use `expire_timestamp` instead.
188 std::chrono::system_clock::time_point expire_time;
190 /// The backup will contain an externally consistent copy of the database
191 /// at `version_time`. If `version_time` is not specified, the system will
192 /// set `version_time` to the `create_time` of the backup.
193 absl::optional<Timestamp> version_time;
194 /// How to encrypt the backup.
195 EncryptionConfig encryption_config;
196 };
197
198 /// Wrap the arguments for `GetBackup()`.
199 struct GetBackupParams {
200 /// The name of the backup.
201 std::string backup_full_name;
202 };
203
204 /// Wrap the arguments for `DeleteBackup()`.
205 struct DeleteBackupParams {
206 /// The name of the backup.
207 std::string backup_full_name;
208 };
209
210 /// Wrap the arguments for `ListBackups()`.
211 struct ListBackupsParams {
212 /// The name of the instance.
214 std::string filter;
215 };
216
217 /// Wrap the arguments for `RestoreDatabase()`.
218 struct RestoreDatabaseParams {
219 /// The name of the database.
221 /// The source backup for the restore.
222 std::string backup_full_name;
223 /// How to encrypt the database.
224 EncryptionConfig encryption_config;
225 };
226
227 /// Wrap the arguments for `UpdateBackup()`.
228 struct UpdateBackupParams {
229 google::spanner::admin::database::v1::UpdateBackupRequest request;
230 };
231
232 /// Wrap the arguments for `ListBackupOperations()`.
234 /// The name of the instance.
236 std::string filter;
237 };
238
239 /// Wrap the arguments for `ListDatabaseOperations()`.
241 /// The name of the instance.
243 std::string filter;
244 };
245 ///@}
246
247 virtual Options options() { return Options{}; }
248
249 /// Define the interface for a google.spanner.v1.DatabaseAdmin.CreateDatabase
250 /// RPC.
251 virtual future<StatusOr<google::spanner::admin::database::v1::Database>>
253
254 /// Define the interface for a google.spanner.v1.DatabaseAdmin.GetDatabase
255 /// RPC.
256 virtual StatusOr<google::spanner::admin::database::v1::Database> GetDatabase(
258
259 /// Define the interface for a google.spanner.v1.DatabaseAdmin.GetDatabaseDdl
260 /// RPC.
261 virtual StatusOr<google::spanner::admin::database::v1::GetDatabaseDdlResponse>
263
264 /// Define the interface for a google.spanner.v1.DatabaseAdmin.UpdateDatabase
265 /// RPC.
266 virtual future<
267 StatusOr<google::spanner::admin::database::v1::UpdateDatabaseDdlMetadata>>
269
270 /// Define the interface for a google.spanner.v1.DatabaseAdmin.DropDatabase
271 /// RPC.
273
274 /// Define the interface for a google.spanner.v1.DatabaseAdmin.DropDatabase
275 /// RPC.
276 virtual ListDatabaseRange ListDatabases(ListDatabasesParams) = 0;
277
278 /// Define the interface for a google.spanner.v1.DatabaseAdmin.RestoreDatabase
279 /// RPC.
280 virtual future<StatusOr<google::spanner::admin::database::v1::Database>>
282
283 /// Define the interface for a google.spanner.v1.DatabaseAdmin.GetIamPolicy
284 /// RPC.
285 virtual StatusOr<google::iam::v1::Policy> GetIamPolicy(
287
288 /// Define the interface for a google.spanner.v1.DatabaseAdmin.SetIamPolicy
289 /// RPC.
290 virtual StatusOr<google::iam::v1::Policy> SetIamPolicy(
292
293 /// Define the interface for a
294 /// google.spanner.v1.DatabaseAdmin.TestIamPermissions RPC.
295 virtual StatusOr<google::iam::v1::TestIamPermissionsResponse>
297
298 /// Define the interface for a google.spanner.v1.DatabaseAdmin.CreateBackup
299 /// RPC.
300 virtual future<StatusOr<google::spanner::admin::database::v1::Backup>>
302
303 /// Define the interface for a google.spanner.v1.DatabaseAdmin.GetBackup RPC.
304 virtual StatusOr<google::spanner::admin::database::v1::Backup> GetBackup(
306
307 /// Define the interface for a google.spanner.v1.DatabaseAdmin.DeleteBackup
308 /// RPC.
310
311 /// Define the interface for a google.spanner.v1.DatabaseAdmin.ListBackups
312 /// RPC.
313 virtual ListBackupsRange ListBackups(ListBackupsParams);
314
315 /// Define the interface for a google.spanner.v1.DatabaseAdmin.UpdateBackup
316 /// RPC.
317 virtual StatusOr<google::spanner::admin::database::v1::Backup> UpdateBackup(
319
320 /// Define the interface for a
321 /// google.spanner.v1.DatabaseAdmin.ListBackupOperations RPC.
322 virtual ListBackupOperationsRange ListBackupOperations(
324
325 /// Define the interface for a
326 /// google.spanner.v1.DatabaseAdmin.ListDatabaseOperations RPC.
327 virtual ListDatabaseOperationsRange ListDatabaseOperations(
329};
330
331/**
332 * Returns a DatabaseAdminConnection object that can be used for interacting
333 * with Cloud Spanner's admin APIs.
334 *
335 * The returned connection object should not be used directly; instead it
336 * should be given to a `DatabaseAdminClient` instance.
337 *
338 * The optional @p opts argument may be used to configure aspects of the
339 * returned `DatabaseAdminConnection`. Expected options are any of types in the
340 * following option lists.
341 *
342 * - `google::cloud::CommonOptionList`
343 * - `google::cloud::GrpcOptionList`
344 * - `google::cloud::SpannerPolicyOptionList`
345 *
346 * @see `DatabaseAdminConnection`
347 *
348 * @param opts (optional) configure the `DatabaseAdminConnection` created by
349 * this function.
350 */
351GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED("MakeDatabaseAdminConnection()")
353 Options opts = {});
354
355/**
356 * Returns a DatabaseAdminConnection object that can be used for interacting
357 * with Cloud Spanner's admin APIs.
358 *
359 * The returned connection object should not be used directly, rather it should
360 * be given to a `DatabaseAdminClient` instance.
361 *
362 * @note Prefer using the `MakeDatabaseAdminConnection()` overload that accepts
363 * `google::cloud::Options`.
364 *
365 * @see `DatabaseAdminConnection`
366 *
367 * @param options configure the `DatabaseAdminConnection` created by this
368 * function.
369 */
370GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED("MakeDatabaseAdminConnection()")
372 ConnectionOptions const& options);
373
374/**
375 * Returns a DatabaseAdminConnection object that can be used for interacting
376 * with Cloud Spanner's admin APIs.
377 *
378 * The returned connection object should not be used directly, rather it should
379 * be given to a `DatabaseAdminClient` instance.
380 *
381 * @note Prefer using the `MakeDatabaseAdminConnection()` overload that accepts
382 * `google::cloud::Options`.
383 *
384 * @param options configure the `DatabaseAdminConnection` created by this
385 * function.
386 * @param retry_policy control for how long (or how many times) are retryable
387 * RPCs attempted
388 * @param backoff_policy controls the backoff behavior between retry attempts,
389 * typically some form of exponential backoff with jitter
390 * @param polling_policy controls for how often, and how quickly, are long
391 * running checked for completion
392 *
393 * @par Example
394 * @snippet samples.cc custom-database-admin-policies
395 */
396GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED("MakeDatabaseAdminConnection()")
398 ConnectionOptions const& options, std::unique_ptr<RetryPolicy> retry_policy,
399 std::unique_ptr<BackoffPolicy> backoff_policy,
400 std::unique_ptr<PollingPolicy> polling_policy);
401
402GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
403} // namespace spanner
404
405namespace spanner_internal {
406GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
407
408/// Internal-only factory that allows us to inject mock stubs for testing.
409std::shared_ptr<spanner::DatabaseAdminConnection>
410MakeDatabaseAdminConnectionForTesting(std::shared_ptr<DatabaseAdminStub> stub,
411 Options opts);
412
413GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
414} // namespace spanner_internal
415
416} // namespace cloud
417} // namespace google
418
419#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_DATABASE_ADMIN_CONNECTION_H
friend friend class future
A connection to the Cloud Spanner instance administration service.
Definition: database_admin_connection.h:105
virtual future< StatusOr< google::spanner::admin::database::v1::Backup > > CreateBackup(CreateBackupParams)
Define the interface for a google.spanner.v1.DatabaseAdmin.CreateBackup RPC.
virtual StatusOr< google::spanner::admin::database::v1::Backup > UpdateBackup(UpdateBackupParams)
Define the interface for a google.spanner.v1.DatabaseAdmin.UpdateBackup RPC.
virtual StatusOr< google::iam::v1::TestIamPermissionsResponse > TestIamPermissions(TestIamPermissionsParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.TestIamPermissions RPC.
virtual Status DropDatabase(DropDatabaseParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.DropDatabase RPC.
virtual ListDatabaseRange ListDatabases(ListDatabasesParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.DropDatabase RPC.
virtual StatusOr< google::spanner::admin::database::v1::Backup > GetBackup(GetBackupParams)
Define the interface for a google.spanner.v1.DatabaseAdmin.GetBackup RPC.
virtual ListBackupsRange ListBackups(ListBackupsParams)
Define the interface for a google.spanner.v1.DatabaseAdmin.ListBackups RPC.
virtual StatusOr< google::iam::v1::Policy > GetIamPolicy(GetIamPolicyParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.GetIamPolicy RPC.
virtual future< StatusOr< google::spanner::admin::database::v1::Database > > CreateDatabase(CreateDatabaseParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.CreateDatabase RPC.
virtual future< StatusOr< google::spanner::admin::database::v1::Database > > RestoreDatabase(RestoreDatabaseParams)
Define the interface for a google.spanner.v1.DatabaseAdmin.RestoreDatabase RPC.
virtual Options options()
Definition: database_admin_connection.h:247
virtual StatusOr< google::iam::v1::Policy > SetIamPolicy(SetIamPolicyParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.SetIamPolicy RPC.
virtual ListDatabaseOperationsRange ListDatabaseOperations(ListDatabaseOperationsParams)
Define the interface for a google.spanner.v1.DatabaseAdmin.ListDatabaseOperations RPC.
virtual ListBackupOperationsRange ListBackupOperations(ListBackupOperationsParams)
Define the interface for a google.spanner.v1.DatabaseAdmin.ListBackupOperations RPC.
virtual StatusOr< google::spanner::admin::database::v1::Database > GetDatabase(GetDatabaseParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.GetDatabase RPC.
virtual future< StatusOr< google::spanner::admin::database::v1::UpdateDatabaseDdlMetadata > > UpdateDatabase(UpdateDatabaseParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.UpdateDatabase RPC.
virtual Status DeleteBackup(DeleteBackupParams)
Define the interface for a google.spanner.v1.DatabaseAdmin.DeleteBackup RPC.
virtual StatusOr< google::spanner::admin::database::v1::GetDatabaseDdlResponse > GetDatabaseDdl(GetDatabaseDdlParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.GetDatabaseDdl RPC.
This class identifies a Cloud Spanner Database.
Definition: database.h:43
This class identifies a Cloud Spanner Instance.
Definition: instance.h:42
A representation of the Spanner TIMESTAMP type: An instant in time.
Definition: timestamp.h:54
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23
std::shared_ptr< DatabaseAdminConnection > MakeDatabaseAdminConnection(ConnectionOptions const &options, std::unique_ptr< RetryPolicy > retry_policy, std::unique_ptr< BackoffPolicy > backoff_policy, std::unique_ptr< PollingPolicy > polling_policy)
Returns a DatabaseAdminConnection object that can be used for interacting with Cloud Spanner's admin ...
std::shared_ptr< DatabaseAdminConnection > MakeDatabaseAdminConnection(ConnectionOptions const &options)
Returns a DatabaseAdminConnection object that can be used for interacting with Cloud Spanner's admin ...
std::shared_ptr< spanner::DatabaseAdminConnection > MakeDatabaseAdminConnection(Options opts={})
Returns a DatabaseAdminConnection object that can be used for interacting with Cloud Spanner's admin ...
Wrap the arguments for CreateBackup().
Definition: database_admin_connection.h:181
EncryptionConfig encryption_config
How to encrypt the backup.
Definition: database_admin_connection.h:195
Timestamp expire_timestamp
Definition: database_admin_connection.h:189
std::string backup_id
Definition: database_admin_connection.h:184
Database database
The name of the database.
Definition: database_admin_connection.h:183
absl::optional< Timestamp > version_time
The backup will contain an externally consistent copy of the database at version_time.
Definition: database_admin_connection.h:193
std::chrono::system_clock::time_point expire_time
Definition: database_admin_connection.h:188
Wrap the arguments for CreateDatabase().
Definition: database_admin_connection.h:119
Database database
The name of the database.
Definition: database_admin_connection.h:121
EncryptionConfig encryption_config
How to encrypt the database.
Definition: database_admin_connection.h:125
std::vector< std::string > extra_statements
Any additional statements to execute after creating the database.
Definition: database_admin_connection.h:123
Wrap the arguments for DeleteBackup().
Definition: database_admin_connection.h:205
std::string backup_full_name
The name of the backup.
Definition: database_admin_connection.h:207
Wrap the arguments for DropDatabase().
Definition: database_admin_connection.h:149
Database database
The name of the database.
Definition: database_admin_connection.h:151
Wrap the arguments for GetBackup().
Definition: database_admin_connection.h:199
std::string backup_full_name
The name of the backup.
Definition: database_admin_connection.h:201
Wrap the arguments for GetDatabaseDdl().
Definition: database_admin_connection.h:135
Database database
The name of the database.
Definition: database_admin_connection.h:137
Wrap the arguments for GetDatabase().
Definition: database_admin_connection.h:129
Database database
The name of the database.
Definition: database_admin_connection.h:131
Wrap the arguments for GetIamPolicy().
Definition: database_admin_connection.h:161
Database database
The name of the database.
Definition: database_admin_connection.h:163
Wrap the arguments for ListBackupOperations().
Definition: database_admin_connection.h:233
Instance instance
The name of the instance.
Definition: database_admin_connection.h:235
std::string filter
Definition: database_admin_connection.h:236
Wrap the arguments for ListBackups().
Definition: database_admin_connection.h:211
Instance instance
The name of the instance.
Definition: database_admin_connection.h:213
std::string filter
Definition: database_admin_connection.h:214
Wrap the arguments for ListDatabaseOperations().
Definition: database_admin_connection.h:240
Instance instance
The name of the instance.
Definition: database_admin_connection.h:242
std::string filter
Definition: database_admin_connection.h:243
Wrap the arguments for ListDatabases().
Definition: database_admin_connection.h:155
Instance instance
The name of the instance.
Definition: database_admin_connection.h:157
Wrap the arguments for RestoreDatabase().
Definition: database_admin_connection.h:218
std::string backup_full_name
The source backup for the restore.
Definition: database_admin_connection.h:222
Database database
The name of the database.
Definition: database_admin_connection.h:220
EncryptionConfig encryption_config
How to encrypt the database.
Definition: database_admin_connection.h:224
Wrap the arguments for SetIamPolicy().
Definition: database_admin_connection.h:167
Database database
The name of the database.
Definition: database_admin_connection.h:169
google::iam::v1::Policy policy
Definition: database_admin_connection.h:170
Wrap the arguments for TestIamPermissions().
Definition: database_admin_connection.h:174
std::vector< std::string > permissions
Definition: database_admin_connection.h:177
Database database
The name of the database.
Definition: database_admin_connection.h:176
Wrap the arguments for UpdateBackup().
Definition: database_admin_connection.h:228
google::spanner::admin::database::v1::UpdateBackupRequest request
Definition: database_admin_connection.h:229
Wrap the arguments for UpdateDatabase().
Definition: database_admin_connection.h:141
Database database
The name of the database.
Definition: database_admin_connection.h:143
std::vector< std::string > statements
The DDL statements updating the database schema.
Definition: database_admin_connection.h:145
#define GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED(name)
Definition: version.h:23