google-cloud-spanner 1.13.1 → 1.16.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/CONTRIBUTING.md +5 -5
  4. data/TROUBLESHOOTING.md +0 -6
  5. data/lib/google-cloud-spanner.rb +52 -4
  6. data/lib/google/cloud/spanner.rb +29 -5
  7. data/lib/google/cloud/spanner/admin/database.rb +3 -2
  8. data/lib/google/cloud/spanner/admin/database/v1.rb +3 -2
  9. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +742 -20
  10. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +43 -3
  11. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/field_mask.rb +222 -0
  12. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/timestamp.rb +113 -0
  13. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/backup.rb +325 -0
  14. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +197 -30
  15. data/lib/google/cloud/spanner/admin/instance.rb +1 -1
  16. data/lib/google/cloud/spanner/admin/instance/v1.rb +1 -1
  17. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +6 -13
  18. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +8 -5
  19. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +7 -7
  20. data/lib/google/cloud/spanner/backup.rb +315 -0
  21. data/lib/google/cloud/spanner/backup/job.rb +274 -0
  22. data/lib/google/cloud/spanner/backup/job/list.rb +177 -0
  23. data/lib/google/cloud/spanner/backup/list.rb +170 -0
  24. data/lib/google/cloud/spanner/backup/restore/job.rb +246 -0
  25. data/lib/google/cloud/spanner/batch_client.rb +5 -3
  26. data/lib/google/cloud/spanner/batch_snapshot.rb +43 -8
  27. data/lib/google/cloud/spanner/client.rb +57 -8
  28. data/lib/google/cloud/spanner/database.rb +260 -0
  29. data/lib/google/cloud/spanner/database/backup_info.rb +105 -0
  30. data/lib/google/cloud/spanner/database/job.rb +3 -0
  31. data/lib/google/cloud/spanner/database/job/list.rb +177 -0
  32. data/lib/google/cloud/spanner/database/restore_info.rb +63 -0
  33. data/lib/google/cloud/spanner/instance.rb +400 -0
  34. data/lib/google/cloud/spanner/project.rb +31 -6
  35. data/lib/google/cloud/spanner/results.rb +4 -2
  36. data/lib/google/cloud/spanner/service.rb +96 -6
  37. data/lib/google/cloud/spanner/session.rb +37 -6
  38. data/lib/google/cloud/spanner/snapshot.rb +26 -3
  39. data/lib/google/cloud/spanner/transaction.rb +49 -5
  40. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +8 -1
  41. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +91 -102
  42. data/lib/google/cloud/spanner/v1/spanner_client.rb +112 -136
  43. data/lib/google/cloud/spanner/version.rb +1 -1
  44. data/lib/google/spanner/admin/database/v1/backup_pb.rb +98 -0
  45. data/lib/google/spanner/admin/database/v1/common_pb.rb +28 -0
  46. data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +53 -0
  47. data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +82 -12
  48. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +1 -2
  49. data/lib/google/spanner/v1/spanner_pb.rb +5 -0
  50. data/lib/google/spanner/v1/spanner_services_pb.rb +31 -40
  51. metadata +17 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7bba4c8dab3ed8067ad0e2d59049021c7a5fce7d87fd1ed0f20226314fd8a214
4
- data.tar.gz: '08033542e0725a4eb7424291a02ae6f1cc1495d1a407d91d84d95d8b23fe02a1'
3
+ metadata.gz: e20c16755d63cea713e0e2b48f0ad0d470e24da1429e8aa1cb62945ee6388ddd
4
+ data.tar.gz: 347112cc47df35de0d4cbdb24b39447860ba4c6c5f477e46d9bdbb45ab464796
5
5
  SHA512:
6
- metadata.gz: 5a839007b3e28db0b4d206af5249410d506ada44956bce6ff899ed1c6e18cd9445a5b7e6930e80fc6ee7c7d930d87ddb4d3375b3a213371a2f42bd857788ac41
7
- data.tar.gz: 410e358dd4451e98f3527ee027f19b14e5b8306924176a2fe6bdb2469f116c1b0110ecde7280abbc7ae35368ed57253113f27b64ac2b88053bc5abd4bb270d0c
6
+ metadata.gz: 14ddd7286340c3520e2b1e0bedc018b48ceef0025fe78043f92c91af5af795e7f7eed027f61659fb232135cf45d6f249d083831bb95d960c622f2cf38dbf582e
7
+ data.tar.gz: 126b39a51fdd3a1673a1a8acd93548ad54ef29938b6dfc793bfd24f728eae6844ade5ca0e6780c3cfeae9aa22a31b307259585b14ec8da65e7e199c7c04393ee
@@ -1,5 +1,43 @@
1
1
  # Release History
2
2
 
3
+ ### 1.16.2 / 2020-05-28
4
+
5
+ #### Documentation
6
+
7
+ * Fix a few broken links
8
+
9
+ ### 1.16.1 / 2020-05-21
10
+
11
+ #### Bug Fixes
12
+
13
+ * Increased default timeouts to match clients in other languages
14
+ * Run system tests against the emulator, skipping those not supported by the emulator
15
+ * Do not require a key file when running against the emulator
16
+
17
+ ### 1.16.0 / 2020-03-20
18
+
19
+ #### Features
20
+
21
+ * Added support for backing up and restoring databases ([#5053](https://www.github.com/googleapis/google-cloud-ruby/issues/5053))
22
+
23
+ ### 1.15.0 / 2020-03-15
24
+
25
+ #### Features
26
+
27
+ * Added support for query options ([#4907](https://www.github.com/googleapis/google-cloud-ruby/issues/4907))
28
+ * Added support for specifying the query optimizer version.
29
+ * Support separate project setting for quota/billing
30
+
31
+ ### 1.14.0 / 2020-02-18
32
+
33
+ #### Features
34
+
35
+ * allow custom lib name and version for telemetry purpose ([#4762](https://www.github.com/googleapis/google-cloud-ruby/issues/4762))
36
+ * allow custom lib name and version for telemetry purpose
37
+ * format docs
38
+ * added custom lib name and version prefix
39
+ * update test cases for lib name and version
40
+
3
41
  ### 1.13.1 / 2020-01-22
4
42
 
5
43
  #### Documentation
@@ -53,7 +53,7 @@ there is a small amount of setup:
53
53
  In order to run code interactively, you can automatically load
54
54
  google-cloud-spanner and its dependencies in IRB. This requires that your
55
55
  developer environment has already been configured by following the steps
56
- described in the [Authentication Guide](AUTHENTICATION.md). An IRB console
56
+ described in the {file:AUTHENTICATION.md Authentication Guide}. An IRB console
57
57
  can be created with:
58
58
 
59
59
  ```sh
@@ -119,7 +119,7 @@ If you alter an example's title, you may encounter breaking tests.
119
119
  ### Spanner Acceptance Tests
120
120
 
121
121
  The Spanner acceptance tests interact with the live service API. Follow the
122
- instructions in the [Authentication Guide](AUTHENTICATION.md) for enabling
122
+ instructions in the {file:AUTHENTICATION.md Authentication Guide} for enabling
123
123
  the Spanner API. Occasionally, some API features may not yet be generally
124
124
  available, making it difficult for some contributors to successfully run the
125
125
  entire acceptance test suite. However, please ensure that you do successfully
@@ -127,7 +127,7 @@ run acceptance tests for any code areas covered by your pull request.
127
127
 
128
128
  To run the acceptance tests, first create and configure a project in the Google
129
129
  Developers Console, as described in the
130
- [Authentication Guide](AUTHENTICATION.md). Be sure to download the JSON KEY
130
+ {file:AUTHENTICATION.md Authentication Guide}. Be sure to download the JSON KEY
131
131
  file. Make note of the PROJECT_ID and the KEYFILE location on your system.
132
132
 
133
133
  Before you can run the Spanner acceptance tests, you must first create indexes
@@ -184,5 +184,5 @@ $ bundle exec rake rubocop
184
184
  ## Code of Conduct
185
185
 
186
186
  Please note that this project is released with a Contributor Code of Conduct. By
187
- participating in this project you agree to abide by its terms. See
188
- [Code of Conduct](CODE_OF_CONDUCT.md) for more information.
187
+ participating in this project you agree to abide by its terms. See the
188
+ {file:CODE_OF_CONDUCT.md Code of Conduct} for more information.
@@ -24,14 +24,8 @@ improved, *please* create a new issue on GitHub so we can talk about it.
24
24
 
25
25
  - [New issue][gh-ruby]
26
26
 
27
- Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
28
- can use the "ruby" channel for general Ruby questions, or use the
29
- "google-cloud-ruby" channel if you have questions about this gem in particular.
30
-
31
27
  [so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+spanner
32
28
 
33
29
  [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+spanner%22
34
30
 
35
31
  [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
36
-
37
- [slack-ruby]: https://gcp-slack.appspot.com/
@@ -45,6 +45,20 @@ module Google
45
45
  # @param [Integer] timeout Default timeout to use in requests. Optional.
46
46
  # @param [Hash] client_config A hash of values to override the default
47
47
  # behavior of the API client. Optional.
48
+ # @param [String] lib_name Library name. This will be added as a prefix
49
+ # to the API call tracking header `x-goog-api-client` with provided
50
+ # lib version for telemetry. Optional. For example prefix looks like
51
+ # `spanner-activerecord/0.0.1 gccl/1.13.1`. Here,
52
+ # `spanner-activerecord/0.0.1` is provided custom library name and
53
+ # version and `gccl/1.13.1` represents the Cloud Spanner Ruby library
54
+ # with version.
55
+ # @param [String] lib_version Library version. This will be added as a
56
+ # prefix to the API call tracking header `x-goog-api-client` with
57
+ # provided lib name for telemetry. Optional. For example prefix look like
58
+ # `spanner-activerecord/0.0.1 gccl/1.13.1`. Here,
59
+ # `spanner-activerecord/0.0.1` is provided custom library name and
60
+ # version and `gccl/1.13.1` represents the Cloud Spanner Ruby library
61
+ # with version.
48
62
  #
49
63
  # @return [Google::Cloud::Spanner::Project]
50
64
  #
@@ -61,10 +75,13 @@ module Google
61
75
  # platform_scope = "https://www.googleapis.com/auth/cloud-platform"
62
76
  # spanner = gcloud.spanner scope: platform_scope
63
77
  #
64
- def spanner scope: nil, timeout: nil, client_config: nil
78
+ def spanner scope: nil, timeout: nil, client_config: nil, lib_name: nil,
79
+ lib_version: nil
65
80
  Google::Cloud.spanner @project, @keyfile, scope: scope,
66
81
  timeout: (timeout || @timeout),
67
- client_config: client_config
82
+ client_config: client_config,
83
+ lib_name: lib_name,
84
+ lib_version: lib_version
68
85
  end
69
86
 
70
87
  ##
@@ -92,6 +109,20 @@ module Google
92
109
  # @param [Integer] timeout Default timeout to use in requests. Optional.
93
110
  # @param [Hash] client_config A hash of values to override the default
94
111
  # behavior of the API client. Optional.
112
+ # @param [String] lib_name Library name. This will be added as a prefix
113
+ # to the API call tracking header `x-goog-api-client` with provided
114
+ # lib version for telemetry. Optional. For example prefix looks like
115
+ # `spanner-activerecord/0.0.1 gccl/1.13.1`. Here,
116
+ # `spanner-activerecord/0.0.1` is provided custom library name and
117
+ # version and `gccl/1.13.1` represents the Cloud Spanner Ruby library
118
+ # with version.
119
+ # @param [String] lib_version Library version. This will be added as a
120
+ # prefix to the API call tracking header `x-goog-api-client` with
121
+ # provided lib name for telemetry. Optional. For example prefix look like
122
+ # `spanner-activerecord/0.0.1 gccl/1.13.1`. Here,
123
+ # `spanner-activerecord/0.0.1` is provided custom library name and
124
+ # version and `gccl/1.13.1` represents the Cloud Spanner Ruby library
125
+ # with version.
95
126
  #
96
127
  # @return [Google::Cloud::Spanner::Project]
97
128
  #
@@ -101,16 +132,20 @@ module Google
101
132
  # spanner = Google::Cloud.spanner
102
133
  #
103
134
  def self.spanner project_id = nil, credentials = nil, scope: nil,
104
- timeout: nil, client_config: nil
135
+ timeout: nil, client_config: nil, lib_name: nil,
136
+ lib_version: nil
105
137
  require "google/cloud/spanner"
106
138
  Google::Cloud::Spanner.new project_id: project_id,
107
139
  credentials: credentials,
108
140
  scope: scope, timeout: timeout,
109
- client_config: client_config
141
+ client_config: client_config,
142
+ lib_name: lib_name, lib_version: lib_version
110
143
  end
111
144
  end
112
145
  end
113
146
 
147
+ # rubocop:disable Metrics/BlockLength
148
+
114
149
  # Set the default spanner configuration
115
150
  Google::Cloud.configure.add_config! :spanner do |config|
116
151
  default_project = Google::Cloud::Config.deferred do
@@ -126,6 +161,14 @@ Google::Cloud.configure.add_config! :spanner do |config|
126
161
  ENV["SPANNER_EMULATOR_HOST"]
127
162
  end
128
163
 
164
+ default_query_options = Google::Cloud::Config.deferred do
165
+ query_options = {}
166
+ optimizer_version = ENV["SPANNER_OPTIMIZER_VERSION"]
167
+ query_options[:optimizer_version] = optimizer_version if optimizer_version
168
+ query_options = nil if query_options.empty?
169
+ query_options
170
+ end
171
+
129
172
  config.add_field! :project_id, default_project, match: String, allow_nil: true
130
173
  config.add_alias! :project, :project_id
131
174
  config.add_field! :credentials, default_creds,
@@ -137,4 +180,9 @@ Google::Cloud.configure.add_config! :spanner do |config|
137
180
  config.add_field! :client_config, nil, match: Hash
138
181
  config.add_field! :endpoint, nil, match: String
139
182
  config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
183
+ config.add_field! :lib_name, nil, match: String, allow_nil: true
184
+ config.add_field! :lib_version, nil, match: String, allow_nil: true
185
+ config.add_field! :query_options, default_query_options, match: Hash, allow_nil: true
140
186
  end
187
+
188
+ # rubocop:enable Metrics/BlockLength
@@ -34,7 +34,7 @@ module Google
34
34
  # See {file:OVERVIEW.md Spanner Overview}.
35
35
  #
36
36
  module Spanner
37
- # rubocop:disable Metrics/MethodLength
37
+ # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
38
38
 
39
39
  ##
40
40
  # Creates a new object for connecting to the Spanner service.
@@ -68,6 +68,20 @@ module Google
68
68
  # Deprecated.
69
69
  # @param [String] emulator_host Spanner emulator host. Optional.
70
70
  # If the param is nil, uses the value of the `emulator_host` config.
71
+ # @param [String] lib_name Library name. This will be added as a prefix
72
+ # to the API call tracking header `x-goog-api-client` with provided
73
+ # lib version for telemetry. Optional. For example prefix looks like
74
+ # `spanner-activerecord/0.0.1 gccl/1.13.1`. Here,
75
+ # `spanner-activerecord/0.0.1` is provided custom library name and
76
+ # version and `gccl/1.13.1` represents the Cloud Spanner Ruby library
77
+ # with version.
78
+ # @param [String] lib_version Library version. This will be added as a
79
+ # prefix to the API call tracking header `x-goog-api-client` with
80
+ # provided lib name for telemetry. Optional. For example prefix look like
81
+ # `spanner-activerecord/0.0.1 gccl/1.13.1`. Here,
82
+ # `spanner-activerecord/0.0.1` is provided custom library name and
83
+ # version and `gccl/1.13.1` represents the Cloud Spanner Ruby library
84
+ # with version.
71
85
  #
72
86
  # @return [Google::Cloud::Spanner::Project]
73
87
  #
@@ -78,7 +92,7 @@ module Google
78
92
  #
79
93
  def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
80
94
  client_config: nil, endpoint: nil, project: nil, keyfile: nil,
81
- emulator_host: nil
95
+ emulator_host: nil, lib_name: nil, lib_version: nil
82
96
  project_id ||= (project || default_project_id)
83
97
  scope ||= configure.scope
84
98
  timeout ||= configure.timeout
@@ -86,6 +100,8 @@ module Google
86
100
  endpoint ||= configure.endpoint
87
101
  credentials ||= (keyfile || default_credentials(scope: scope))
88
102
  emulator_host ||= configure.emulator_host
103
+ lib_name ||= configure.lib_name
104
+ lib_version ||= configure.lib_version
89
105
 
90
106
  if emulator_host
91
107
  credentials = :this_channel_is_insecure
@@ -106,12 +122,14 @@ module Google
106
122
  Spanner::Project.new(
107
123
  Spanner::Service.new(
108
124
  project_id, credentials,
109
- host: endpoint, timeout: timeout, client_config: client_config
110
- )
125
+ host: endpoint, timeout: timeout, client_config: client_config,
126
+ lib_name: lib_name, lib_version: lib_version
127
+ ),
128
+ query_options: configure.query_options
111
129
  )
112
130
  end
113
131
 
114
- # rubocop:enable Metrics/MethodLength
132
+ # rubocop:enable Metrics/MethodLength,Metrics/AbcSize
115
133
 
116
134
  ##
117
135
  # Configure the Google Cloud Spanner library.
@@ -133,6 +151,12 @@ module Google
133
151
  # to use the default endpoint.
134
152
  # * `emulator_host` - (String) Host name of the emulator. Defaults to
135
153
  # `ENV["SPANNER_EMULATOR_HOST"]`.
154
+ # * `lib_name` - (String) Override the lib name , or `nil`
155
+ # to use the default lib name without prefix in agent tracking
156
+ # header.
157
+ # * `lib_version` - (String) Override the lib version , or `nil`
158
+ # to use the default version lib name without prefix in agent
159
+ # tracking header.
136
160
  #
137
161
  # @return [Google::Cloud::Config] The configuration object the
138
162
  # Google::Cloud::Spanner library uses.
@@ -23,7 +23,7 @@ module Google
23
23
  # rubocop:disable LineLength
24
24
 
25
25
  ##
26
- # # Ruby Client for Cloud Spanner Database Admin API ([Alpha](https://github.com/googleapis/google-cloud-ruby#versioning))
26
+ # # Ruby Client for Cloud Spanner Database Admin API
27
27
  #
28
28
  # [Cloud Spanner Database Admin API][Product Documentation]:
29
29
  #
@@ -93,7 +93,8 @@ module Google
93
93
  #
94
94
  # The Cloud Spanner Database Admin API can be used to create, drop, and
95
95
  # list databases. It also enables updating the schema of pre-existing
96
- # databases.
96
+ # databases. It can be also used to create, delete and list backups for a
97
+ # database and to restore from an existing backup.
97
98
  #
98
99
  # @param version [Symbol, String]
99
100
  # The major version of the service to be used. By default :v1
@@ -24,7 +24,7 @@ module Google
24
24
  # rubocop:disable LineLength
25
25
 
26
26
  ##
27
- # # Ruby Client for Cloud Spanner Database Admin API ([Alpha](https://github.com/googleapis/google-cloud-ruby#versioning))
27
+ # # Ruby Client for Cloud Spanner Database Admin API
28
28
  #
29
29
  # [Cloud Spanner Database Admin API][Product Documentation]:
30
30
  #
@@ -86,7 +86,8 @@ module Google
86
86
  #
87
87
  # The Cloud Spanner Database Admin API can be used to create, drop, and
88
88
  # list databases. It also enables updating the schema of pre-existing
89
- # databases.
89
+ # databases. It can be also used to create, delete and list backups for a
90
+ # database and to restore from an existing backup.
90
91
  #
91
92
  # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
92
93
  # Provides the means for authenticating requests made by the client. This parameter can
@@ -41,7 +41,8 @@ module Google
41
41
  #
42
42
  # The Cloud Spanner Database Admin API can be used to create, drop, and
43
43
  # list databases. It also enables updating the schema of pre-existing
44
- # databases.
44
+ # databases. It can be also used to create, delete and list backups for a
45
+ # database and to restore from an existing backup.
45
46
  #
46
47
  # @!attribute [r] database_admin_stub
47
48
  # @return [Google::Spanner::Admin::Database::V1::DatabaseAdmin::Stub]
@@ -64,7 +65,19 @@ module Google
64
65
  "list_databases" => Google::Gax::PageDescriptor.new(
65
66
  "page_token",
66
67
  "next_page_token",
67
- "databases")
68
+ "databases"),
69
+ "list_backups" => Google::Gax::PageDescriptor.new(
70
+ "page_token",
71
+ "next_page_token",
72
+ "backups"),
73
+ "list_database_operations" => Google::Gax::PageDescriptor.new(
74
+ "page_token",
75
+ "next_page_token",
76
+ "operations"),
77
+ "list_backup_operations" => Google::Gax::PageDescriptor.new(
78
+ "page_token",
79
+ "next_page_token",
80
+ "operations")
68
81
  }.freeze
69
82
 
70
83
  private_constant :PAGE_DESCRIPTORS
@@ -82,6 +95,12 @@ module Google
82
95
  self::GRPC_INTERCEPTORS = DatabaseAdminClient::GRPC_INTERCEPTORS
83
96
  end
84
97
 
98
+ BACKUP_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
99
+ "projects/{project}/instances/{instance}/backups/{backup}"
100
+ )
101
+
102
+ private_constant :BACKUP_PATH_TEMPLATE
103
+
85
104
  DATABASE_PATH_TEMPLATE = Google::Gax::PathTemplate.new(
86
105
  "projects/{project}/instances/{instance}/databases/{database}"
87
106
  )
@@ -94,6 +113,19 @@ module Google
94
113
 
95
114
  private_constant :INSTANCE_PATH_TEMPLATE
96
115
 
116
+ # Returns a fully-qualified backup resource name string.
117
+ # @param project [String]
118
+ # @param instance [String]
119
+ # @param backup [String]
120
+ # @return [String]
121
+ def self.backup_path project, instance, backup
122
+ BACKUP_PATH_TEMPLATE.render(
123
+ :"project" => project,
124
+ :"instance" => instance,
125
+ :"backup" => backup
126
+ )
127
+ end
128
+
97
129
  # Returns a fully-qualified database resource name string.
98
130
  # @param project [String]
99
131
  # @param instance [String]
@@ -207,6 +239,9 @@ module Google
207
239
  google_api_client.freeze
208
240
 
209
241
  headers = { :"x-goog-api-client" => google_api_client }
242
+ if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id
243
+ headers[:"x-goog-user-project"] = credentials.quota_project_id
244
+ end
210
245
  headers.merge!(metadata) unless metadata.nil?
211
246
  client_config_file = Pathname.new(__dir__).join(
212
247
  "database_admin_client_config.json"
@@ -311,6 +346,70 @@ module Google
311
346
  {'resource' => request.resource}
312
347
  end
313
348
  )
349
+ @create_backup = Google::Gax.create_api_call(
350
+ @database_admin_stub.method(:create_backup),
351
+ defaults["create_backup"],
352
+ exception_transformer: exception_transformer,
353
+ params_extractor: proc do |request|
354
+ {'parent' => request.parent}
355
+ end
356
+ )
357
+ @get_backup = Google::Gax.create_api_call(
358
+ @database_admin_stub.method(:get_backup),
359
+ defaults["get_backup"],
360
+ exception_transformer: exception_transformer,
361
+ params_extractor: proc do |request|
362
+ {'name' => request.name}
363
+ end
364
+ )
365
+ @update_backup = Google::Gax.create_api_call(
366
+ @database_admin_stub.method(:update_backup),
367
+ defaults["update_backup"],
368
+ exception_transformer: exception_transformer,
369
+ params_extractor: proc do |request|
370
+ {'backup.name' => request.backup.name}
371
+ end
372
+ )
373
+ @delete_backup = Google::Gax.create_api_call(
374
+ @database_admin_stub.method(:delete_backup),
375
+ defaults["delete_backup"],
376
+ exception_transformer: exception_transformer,
377
+ params_extractor: proc do |request|
378
+ {'name' => request.name}
379
+ end
380
+ )
381
+ @list_backups = Google::Gax.create_api_call(
382
+ @database_admin_stub.method(:list_backups),
383
+ defaults["list_backups"],
384
+ exception_transformer: exception_transformer,
385
+ params_extractor: proc do |request|
386
+ {'parent' => request.parent}
387
+ end
388
+ )
389
+ @restore_database = Google::Gax.create_api_call(
390
+ @database_admin_stub.method(:restore_database),
391
+ defaults["restore_database"],
392
+ exception_transformer: exception_transformer,
393
+ params_extractor: proc do |request|
394
+ {'parent' => request.parent}
395
+ end
396
+ )
397
+ @list_database_operations = Google::Gax.create_api_call(
398
+ @database_admin_stub.method(:list_database_operations),
399
+ defaults["list_database_operations"],
400
+ exception_transformer: exception_transformer,
401
+ params_extractor: proc do |request|
402
+ {'parent' => request.parent}
403
+ end
404
+ )
405
+ @list_backup_operations = Google::Gax.create_api_call(
406
+ @database_admin_stub.method(:list_backup_operations),
407
+ defaults["list_backup_operations"],
408
+ exception_transformer: exception_transformer,
409
+ params_extractor: proc do |request|
410
+ {'parent' => request.parent}
411
+ end
412
+ )
314
413
  end
315
414
 
316
415
  # Service calls
@@ -375,8 +474,8 @@ module Google
375
474
  # have a name of the format `<database_name>/operations/<operation_id>` and
376
475
  # can be used to track preparation of the database. The
377
476
  # {Google::Longrunning::Operation#metadata metadata} field type is
378
- # {Google::Spanner::Admin::Database::V1::CreateDatabaseMetadata CreateDatabaseMetadata}.
379
- # The {Google::Longrunning::Operation#response response} field type is
477
+ # {Google::Spanner::Admin::Database::V1::CreateDatabaseMetadata CreateDatabaseMetadata}. The
478
+ # {Google::Longrunning::Operation#response response} field type is
380
479
  # {Google::Spanner::Admin::Database::V1::Database Database}, if successful.
381
480
  #
382
481
  # @param parent [String]
@@ -389,7 +488,7 @@ module Google
389
488
  # If the database ID is a reserved word or if it contains a hyphen, the
390
489
  # database ID must be enclosed in backticks (`` ` ``).
391
490
  # @param extra_statements [Array<String>]
392
- # An optional list of DDL statements to run inside the newly created
491
+ # Optional. A list of DDL statements to run inside the newly created
393
492
  # database. Statements can create tables, indexes, etc. These
394
493
  # statements execute atomically with the creation of the database:
395
494
  # if there is an error in any statement, the database is not created.
@@ -493,8 +592,7 @@ module Google
493
592
  # the format `<database_name>/operations/<operation_id>` and can be used to
494
593
  # track execution of the schema change(s). The
495
594
  # {Google::Longrunning::Operation#metadata metadata} field type is
496
- # {Google::Spanner::Admin::Database::V1::UpdateDatabaseDdlMetadata UpdateDatabaseDdlMetadata}.
497
- # The operation has no response.
595
+ # {Google::Spanner::Admin::Database::V1::UpdateDatabaseDdlMetadata UpdateDatabaseDdlMetadata}. The operation has no response.
498
596
  #
499
597
  # @param database [String]
500
598
  # Required. The database to update.
@@ -508,20 +606,18 @@ module Google
508
606
  #
509
607
  # Specifying an explicit operation ID simplifies determining
510
608
  # whether the statements were executed in the event that the
511
- # {Google::Spanner::Admin::Database::V1::DatabaseAdmin::UpdateDatabaseDdl UpdateDatabaseDdl}
512
- # call is replayed, or the return value is otherwise lost: the
513
- # {Google::Spanner::Admin::Database::V1::UpdateDatabaseDdlRequest#database database}
514
- # and `operation_id` fields can be combined to form the
609
+ # {Google::Spanner::Admin::Database::V1::DatabaseAdmin::UpdateDatabaseDdl UpdateDatabaseDdl} call is replayed,
610
+ # or the return value is otherwise lost: the {Google::Spanner::Admin::Database::V1::UpdateDatabaseDdlRequest#database database} and
611
+ # `operation_id` fields can be combined to form the
515
612
  # {Google::Longrunning::Operation#name name} of the resulting
516
- # {Google::Longrunning::Operation longrunning::Operation}:
517
- # `<database>/operations/<operation_id>`.
613
+ # {Google::Longrunning::Operation longrunning::Operation}: `<database>/operations/<operation_id>`.
518
614
  #
519
615
  # `operation_id` should be unique within the database, and must be
520
616
  # a valid identifier: `[a-z][a-z0-9_]*`. Note that
521
617
  # automatically-generated operation IDs always begin with an
522
618
  # underscore. If the named operation already exists,
523
- # {Google::Spanner::Admin::Database::V1::DatabaseAdmin::UpdateDatabaseDdl UpdateDatabaseDdl}
524
- # returns `ALREADY_EXISTS`.
619
+ # {Google::Spanner::Admin::Database::V1::DatabaseAdmin::UpdateDatabaseDdl UpdateDatabaseDdl} returns
620
+ # `ALREADY_EXISTS`.
525
621
  # @param options [Google::Gax::CallOptions]
526
622
  # Overrides the default settings for this call, e.g, timeout,
527
623
  # retries, etc.
@@ -586,6 +682,8 @@ module Google
586
682
  end
587
683
 
588
684
  # Drops (aka deletes) a Cloud Spanner database.
685
+ # Completed backups for the database will be retained according to their
686
+ # `expire_time`.
589
687
  #
590
688
  # @param database [String]
591
689
  # Required. The database to be dropped.
@@ -647,11 +745,13 @@ module Google
647
745
  @get_database_ddl.call(req, options, &block)
648
746
  end
649
747
 
650
- # Sets the access control policy on a database resource.
748
+ # Sets the access control policy on a database or backup resource.
651
749
  # Replaces any existing policy.
652
750
  #
653
751
  # Authorization requires `spanner.databases.setIamPolicy`
654
752
  # permission on {Google::Iam::V1::SetIamPolicyRequest#resource resource}.
753
+ # For backups, authorization requires `spanner.backups.setIamPolicy`
754
+ # permission on {Google::Iam::V1::SetIamPolicyRequest#resource resource}.
655
755
  #
656
756
  # @param resource [String]
657
757
  # REQUIRED: The resource for which the policy is being specified.
@@ -694,12 +794,14 @@ module Google
694
794
  @set_iam_policy.call(req, options, &block)
695
795
  end
696
796
 
697
- # Gets the access control policy for a database resource.
698
- # Returns an empty policy if a database exists but does
699
- # not have a policy set.
797
+ # Gets the access control policy for a database or backup resource.
798
+ # Returns an empty policy if a database or backup exists but does not have a
799
+ # policy set.
700
800
  #
701
801
  # Authorization requires `spanner.databases.getIamPolicy` permission on
702
802
  # {Google::Iam::V1::GetIamPolicyRequest#resource resource}.
803
+ # For backups, authorization requires `spanner.backups.getIamPolicy`
804
+ # permission on {Google::Iam::V1::GetIamPolicyRequest#resource resource}.
703
805
  #
704
806
  # @param resource [String]
705
807
  # REQUIRED: The resource for which the policy is being requested.
@@ -737,12 +839,16 @@ module Google
737
839
  @get_iam_policy.call(req, options, &block)
738
840
  end
739
841
 
740
- # Returns permissions that the caller has on the specified database resource.
842
+ # Returns permissions that the caller has on the specified database or backup
843
+ # resource.
741
844
  #
742
845
  # Attempting this RPC on a non-existent Cloud Spanner database will
743
846
  # result in a NOT_FOUND error if the user has
744
847
  # `spanner.databases.list` permission on the containing Cloud
745
848
  # Spanner instance. Otherwise returns an empty set of permissions.
849
+ # Calling this method on a backup that does not exist will
850
+ # result in a NOT_FOUND error if the user has
851
+ # `spanner.backups.list` permission on the containing instance.
746
852
  #
747
853
  # @param resource [String]
748
854
  # REQUIRED: The resource for which the policy detail is being requested.
@@ -782,6 +888,622 @@ module Google
782
888
  req = Google::Gax::to_proto(req, Google::Iam::V1::TestIamPermissionsRequest)
783
889
  @test_iam_permissions.call(req, options, &block)
784
890
  end
891
+
892
+ # Starts creating a new Cloud Spanner Backup.
893
+ # The returned backup {Google::Longrunning::Operation long-running operation}
894
+ # will have a name of the format
895
+ # `projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>`
896
+ # and can be used to track creation of the backup. The
897
+ # {Google::Longrunning::Operation#metadata metadata} field type is
898
+ # {Google::Spanner::Admin::Database::V1::CreateBackupMetadata CreateBackupMetadata}. The
899
+ # {Google::Longrunning::Operation#response response} field type is
900
+ # {Google::Spanner::Admin::Database::V1::Backup Backup}, if successful. Cancelling the returned operation will stop the
901
+ # creation and delete the backup.
902
+ # There can be only one pending backup creation per database. Backup creation
903
+ # of different databases can run concurrently.
904
+ #
905
+ # @param parent [String]
906
+ # Required. The name of the instance in which the backup will be
907
+ # created. This must be the same instance that contains the database the
908
+ # backup will be created from. The backup will be stored in the
909
+ # location(s) specified in the instance configuration of this
910
+ # instance. Values are of the form
911
+ # `projects/<project>/instances/<instance>`.
912
+ # @param backup_id [String]
913
+ # Required. The id of the backup to be created. The `backup_id` appended to
914
+ # `parent` forms the full backup name of the form
915
+ # `projects/<project>/instances/<instance>/backups/<backup_id>`.
916
+ # @param backup [Google::Spanner::Admin::Database::V1::Backup | Hash]
917
+ # Required. The backup to create.
918
+ # A hash of the same form as `Google::Spanner::Admin::Database::V1::Backup`
919
+ # can also be provided.
920
+ # @param options [Google::Gax::CallOptions]
921
+ # Overrides the default settings for this call, e.g, timeout,
922
+ # retries, etc.
923
+ # @return [Google::Gax::Operation]
924
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
925
+ # @example
926
+ # require "google/cloud/spanner/admin/database"
927
+ #
928
+ # database_admin_client = Google::Cloud::Spanner::Admin::Database.new(version: :v1)
929
+ # formatted_parent = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient.instance_path("[PROJECT]", "[INSTANCE]")
930
+ #
931
+ # # TODO: Initialize `backup_id`:
932
+ # backup_id = ''
933
+ #
934
+ # # TODO: Initialize `backup`:
935
+ # backup = {}
936
+ #
937
+ # # Register a callback during the method call.
938
+ # operation = database_admin_client.create_backup(formatted_parent, backup_id, backup) do |op|
939
+ # raise op.results.message if op.error?
940
+ # op_results = op.results
941
+ # # Process the results.
942
+ #
943
+ # metadata = op.metadata
944
+ # # Process the metadata.
945
+ # end
946
+ #
947
+ # # Or use the return value to register a callback.
948
+ # operation.on_done do |op|
949
+ # raise op.results.message if op.error?
950
+ # op_results = op.results
951
+ # # Process the results.
952
+ #
953
+ # metadata = op.metadata
954
+ # # Process the metadata.
955
+ # end
956
+ #
957
+ # # Manually reload the operation.
958
+ # operation.reload!
959
+ #
960
+ # # Or block until the operation completes, triggering callbacks on
961
+ # # completion.
962
+ # operation.wait_until_done!
963
+
964
+ def create_backup \
965
+ parent,
966
+ backup_id,
967
+ backup,
968
+ options: nil
969
+ req = {
970
+ parent: parent,
971
+ backup_id: backup_id,
972
+ backup: backup
973
+ }.delete_if { |_, v| v.nil? }
974
+ req = Google::Gax::to_proto(req, Google::Spanner::Admin::Database::V1::CreateBackupRequest)
975
+ operation = Google::Gax::Operation.new(
976
+ @create_backup.call(req, options),
977
+ @operations_client,
978
+ Google::Spanner::Admin::Database::V1::Backup,
979
+ Google::Spanner::Admin::Database::V1::CreateBackupMetadata,
980
+ call_options: options
981
+ )
982
+ operation.on_done { |operation| yield(operation) } if block_given?
983
+ operation
984
+ end
985
+
986
+ # Gets metadata on a pending or completed {Google::Spanner::Admin::Database::V1::Backup Backup}.
987
+ #
988
+ # @param name [String]
989
+ # Required. Name of the backup.
990
+ # Values are of the form
991
+ # `projects/<project>/instances/<instance>/backups/<backup>`.
992
+ # @param options [Google::Gax::CallOptions]
993
+ # Overrides the default settings for this call, e.g, timeout,
994
+ # retries, etc.
995
+ # @yield [result, operation] Access the result along with the RPC operation
996
+ # @yieldparam result [Google::Spanner::Admin::Database::V1::Backup]
997
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
998
+ # @return [Google::Spanner::Admin::Database::V1::Backup]
999
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
1000
+ # @example
1001
+ # require "google/cloud/spanner/admin/database"
1002
+ #
1003
+ # database_admin_client = Google::Cloud::Spanner::Admin::Database.new(version: :v1)
1004
+ # formatted_name = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient.backup_path("[PROJECT]", "[INSTANCE]", "[BACKUP]")
1005
+ # response = database_admin_client.get_backup(formatted_name)
1006
+
1007
+ def get_backup \
1008
+ name,
1009
+ options: nil,
1010
+ &block
1011
+ req = {
1012
+ name: name
1013
+ }.delete_if { |_, v| v.nil? }
1014
+ req = Google::Gax::to_proto(req, Google::Spanner::Admin::Database::V1::GetBackupRequest)
1015
+ @get_backup.call(req, options, &block)
1016
+ end
1017
+
1018
+ # Updates a pending or completed {Google::Spanner::Admin::Database::V1::Backup Backup}.
1019
+ #
1020
+ # @param backup [Google::Spanner::Admin::Database::V1::Backup | Hash]
1021
+ # Required. The backup to update. `backup.name`, and the fields to be updated
1022
+ # as specified by `update_mask` are required. Other fields are ignored.
1023
+ # Update is only supported for the following fields:
1024
+ # * `backup.expire_time`.
1025
+ # A hash of the same form as `Google::Spanner::Admin::Database::V1::Backup`
1026
+ # can also be provided.
1027
+ # @param update_mask [Google::Protobuf::FieldMask | Hash]
1028
+ # Required. A mask specifying which fields (e.g. `expire_time`) in the
1029
+ # Backup resource should be updated. This mask is relative to the Backup
1030
+ # resource, not to the request message. The field mask must always be
1031
+ # specified; this prevents any future fields from being erased accidentally
1032
+ # by clients that do not know about them.
1033
+ # A hash of the same form as `Google::Protobuf::FieldMask`
1034
+ # can also be provided.
1035
+ # @param options [Google::Gax::CallOptions]
1036
+ # Overrides the default settings for this call, e.g, timeout,
1037
+ # retries, etc.
1038
+ # @yield [result, operation] Access the result along with the RPC operation
1039
+ # @yieldparam result [Google::Spanner::Admin::Database::V1::Backup]
1040
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
1041
+ # @return [Google::Spanner::Admin::Database::V1::Backup]
1042
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
1043
+ # @example
1044
+ # require "google/cloud/spanner/admin/database"
1045
+ #
1046
+ # database_admin_client = Google::Cloud::Spanner::Admin::Database.new(version: :v1)
1047
+ #
1048
+ # # TODO: Initialize `backup`:
1049
+ # backup = {}
1050
+ #
1051
+ # # TODO: Initialize `update_mask`:
1052
+ # update_mask = {}
1053
+ # response = database_admin_client.update_backup(backup, update_mask)
1054
+
1055
+ def update_backup \
1056
+ backup,
1057
+ update_mask,
1058
+ options: nil,
1059
+ &block
1060
+ req = {
1061
+ backup: backup,
1062
+ update_mask: update_mask
1063
+ }.delete_if { |_, v| v.nil? }
1064
+ req = Google::Gax::to_proto(req, Google::Spanner::Admin::Database::V1::UpdateBackupRequest)
1065
+ @update_backup.call(req, options, &block)
1066
+ end
1067
+
1068
+ # Deletes a pending or completed {Google::Spanner::Admin::Database::V1::Backup Backup}.
1069
+ #
1070
+ # @param name [String]
1071
+ # Required. Name of the backup to delete.
1072
+ # Values are of the form
1073
+ # `projects/<project>/instances/<instance>/backups/<backup>`.
1074
+ # @param options [Google::Gax::CallOptions]
1075
+ # Overrides the default settings for this call, e.g, timeout,
1076
+ # retries, etc.
1077
+ # @yield [result, operation] Access the result along with the RPC operation
1078
+ # @yieldparam result []
1079
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
1080
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
1081
+ # @example
1082
+ # require "google/cloud/spanner/admin/database"
1083
+ #
1084
+ # database_admin_client = Google::Cloud::Spanner::Admin::Database.new(version: :v1)
1085
+ # formatted_name = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient.backup_path("[PROJECT]", "[INSTANCE]", "[BACKUP]")
1086
+ # database_admin_client.delete_backup(formatted_name)
1087
+
1088
+ def delete_backup \
1089
+ name,
1090
+ options: nil,
1091
+ &block
1092
+ req = {
1093
+ name: name
1094
+ }.delete_if { |_, v| v.nil? }
1095
+ req = Google::Gax::to_proto(req, Google::Spanner::Admin::Database::V1::DeleteBackupRequest)
1096
+ @delete_backup.call(req, options, &block)
1097
+ nil
1098
+ end
1099
+
1100
+ # Lists completed and pending backups.
1101
+ # Backups returned are ordered by `create_time` in descending order,
1102
+ # starting from the most recent `create_time`.
1103
+ #
1104
+ # @param parent [String]
1105
+ # Required. The instance to list backups from. Values are of the
1106
+ # form `projects/<project>/instances/<instance>`.
1107
+ # @param filter [String]
1108
+ # An expression that filters the list of returned backups.
1109
+ #
1110
+ # A filter expression consists of a field name, a comparison operator, and a
1111
+ # value for filtering.
1112
+ # The value must be a string, a number, or a boolean. The comparison operator
1113
+ # must be one of: `<`, `>`, `<=`, `>=`, `!=`, `=`, or `:`.
1114
+ # Colon `:` is the contains operator. Filter rules are not case sensitive.
1115
+ #
1116
+ # The following fields in the {Google::Spanner::Admin::Database::V1::Backup Backup} are eligible for filtering:
1117
+ #
1118
+ # * `name`
1119
+ # * `database`
1120
+ # * `state`
1121
+ # * `create_time` (and values are of the format YYYY-MM-DDTHH:MM:SSZ)
1122
+ # * `expire_time` (and values are of the format YYYY-MM-DDTHH:MM:SSZ)
1123
+ # * `size_bytes`
1124
+ #
1125
+ # You can combine multiple expressions by enclosing each expression in
1126
+ # parentheses. By default, expressions are combined with AND logic, but
1127
+ # you can specify AND, OR, and NOT logic explicitly.
1128
+ #
1129
+ # Here are a few examples:
1130
+ #
1131
+ # * `name:Howl` - The backup's name contains the string "howl".
1132
+ # * `database:prod`
1133
+ # * The database's name contains the string "prod".
1134
+ # * `state:CREATING` - The backup is pending creation.
1135
+ # * `state:READY` - The backup is fully created and ready for use.
1136
+ # * `(name:howl) AND (create_time < \"2018-03-28T14:50:00Z\")`
1137
+ # * The backup name contains the string "howl" and `create_time`
1138
+ # of the backup is before 2018-03-28T14:50:00Z.
1139
+ # * `expire_time < \"2018-03-28T14:50:00Z\"`
1140
+ # * The backup `expire_time` is before 2018-03-28T14:50:00Z.
1141
+ # * `size_bytes > 10000000000` - The backup's size is greater than 10GB
1142
+ # @param page_size [Integer]
1143
+ # The maximum number of resources contained in the underlying API
1144
+ # response. If page streaming is performed per-resource, this
1145
+ # parameter does not affect the return value. If page streaming is
1146
+ # performed per-page, this determines the maximum number of
1147
+ # resources in a page.
1148
+ # @param options [Google::Gax::CallOptions]
1149
+ # Overrides the default settings for this call, e.g, timeout,
1150
+ # retries, etc.
1151
+ # @yield [result, operation] Access the result along with the RPC operation
1152
+ # @yieldparam result [Google::Gax::PagedEnumerable<Google::Spanner::Admin::Database::V1::Backup>]
1153
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
1154
+ # @return [Google::Gax::PagedEnumerable<Google::Spanner::Admin::Database::V1::Backup>]
1155
+ # An enumerable of Google::Spanner::Admin::Database::V1::Backup instances.
1156
+ # See Google::Gax::PagedEnumerable documentation for other
1157
+ # operations such as per-page iteration or access to the response
1158
+ # object.
1159
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
1160
+ # @example
1161
+ # require "google/cloud/spanner/admin/database"
1162
+ #
1163
+ # database_admin_client = Google::Cloud::Spanner::Admin::Database.new(version: :v1)
1164
+ # formatted_parent = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient.instance_path("[PROJECT]", "[INSTANCE]")
1165
+ #
1166
+ # # TODO: Initialize `filter`:
1167
+ # filter = ''
1168
+ #
1169
+ # # Iterate over all results.
1170
+ # database_admin_client.list_backups(formatted_parent, filter).each do |element|
1171
+ # # Process element.
1172
+ # end
1173
+ #
1174
+ # # Or iterate over results one page at a time.
1175
+ # database_admin_client.list_backups(formatted_parent, filter).each_page do |page|
1176
+ # # Process each page at a time.
1177
+ # page.each do |element|
1178
+ # # Process element.
1179
+ # end
1180
+ # end
1181
+
1182
+ def list_backups \
1183
+ parent,
1184
+ filter,
1185
+ page_size: nil,
1186
+ options: nil,
1187
+ &block
1188
+ req = {
1189
+ parent: parent,
1190
+ filter: filter,
1191
+ page_size: page_size
1192
+ }.delete_if { |_, v| v.nil? }
1193
+ req = Google::Gax::to_proto(req, Google::Spanner::Admin::Database::V1::ListBackupsRequest)
1194
+ @list_backups.call(req, options, &block)
1195
+ end
1196
+
1197
+ # Create a new database by restoring from a completed backup. The new
1198
+ # database must be in the same project and in an instance with the same
1199
+ # instance configuration as the instance containing
1200
+ # the backup. The returned database [long-running
1201
+ # operation][google.longrunning.Operation] has a name of the format
1202
+ # `projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>`,
1203
+ # and can be used to track the progress of the operation, and to cancel it.
1204
+ # The {Google::Longrunning::Operation#metadata metadata} field type is
1205
+ # {Google::Spanner::Admin::Database::V1::RestoreDatabaseMetadata RestoreDatabaseMetadata}.
1206
+ # The {Google::Longrunning::Operation#response response} type
1207
+ # is {Google::Spanner::Admin::Database::V1::Database Database}, if
1208
+ # successful. Cancelling the returned operation will stop the restore and
1209
+ # delete the database.
1210
+ # There can be only one database being restored into an instance at a time.
1211
+ # Once the restore operation completes, a new restore operation can be
1212
+ # initiated, without waiting for the optimize operation associated with the
1213
+ # first restore to complete.
1214
+ #
1215
+ # @param parent [String]
1216
+ # Required. The name of the instance in which to create the
1217
+ # restored database. This instance must be in the same project and
1218
+ # have the same instance configuration as the instance containing
1219
+ # the source backup. Values are of the form
1220
+ # `projects/<project>/instances/<instance>`.
1221
+ # @param database_id [String]
1222
+ # Required. The id of the database to create and restore to. This
1223
+ # database must not already exist. The `database_id` appended to
1224
+ # `parent` forms the full database name of the form
1225
+ # `projects/<project>/instances/<instance>/databases/<database_id>`.
1226
+ # @param backup [String]
1227
+ # Name of the backup from which to restore. Values are of the form
1228
+ # `projects/<project>/instances/<instance>/backups/<backup>`.
1229
+ # @param options [Google::Gax::CallOptions]
1230
+ # Overrides the default settings for this call, e.g, timeout,
1231
+ # retries, etc.
1232
+ # @return [Google::Gax::Operation]
1233
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
1234
+ # @example
1235
+ # require "google/cloud/spanner/admin/database"
1236
+ #
1237
+ # database_admin_client = Google::Cloud::Spanner::Admin::Database.new(version: :v1)
1238
+ # formatted_parent = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient.instance_path("[PROJECT]", "[INSTANCE]")
1239
+ #
1240
+ # # TODO: Initialize `database_id`:
1241
+ # database_id = ''
1242
+ #
1243
+ # # Register a callback during the method call.
1244
+ # operation = database_admin_client.restore_database(formatted_parent, database_id) do |op|
1245
+ # raise op.results.message if op.error?
1246
+ # op_results = op.results
1247
+ # # Process the results.
1248
+ #
1249
+ # metadata = op.metadata
1250
+ # # Process the metadata.
1251
+ # end
1252
+ #
1253
+ # # Or use the return value to register a callback.
1254
+ # operation.on_done do |op|
1255
+ # raise op.results.message if op.error?
1256
+ # op_results = op.results
1257
+ # # Process the results.
1258
+ #
1259
+ # metadata = op.metadata
1260
+ # # Process the metadata.
1261
+ # end
1262
+ #
1263
+ # # Manually reload the operation.
1264
+ # operation.reload!
1265
+ #
1266
+ # # Or block until the operation completes, triggering callbacks on
1267
+ # # completion.
1268
+ # operation.wait_until_done!
1269
+
1270
+ def restore_database \
1271
+ parent,
1272
+ database_id,
1273
+ backup: nil,
1274
+ options: nil
1275
+ req = {
1276
+ parent: parent,
1277
+ database_id: database_id,
1278
+ backup: backup
1279
+ }.delete_if { |_, v| v.nil? }
1280
+ req = Google::Gax::to_proto(req, Google::Spanner::Admin::Database::V1::RestoreDatabaseRequest)
1281
+ operation = Google::Gax::Operation.new(
1282
+ @restore_database.call(req, options),
1283
+ @operations_client,
1284
+ Google::Spanner::Admin::Database::V1::Database,
1285
+ Google::Spanner::Admin::Database::V1::RestoreDatabaseMetadata,
1286
+ call_options: options
1287
+ )
1288
+ operation.on_done { |operation| yield(operation) } if block_given?
1289
+ operation
1290
+ end
1291
+
1292
+ # Lists database {Google::Longrunning::Operation longrunning-operations}.
1293
+ # A database operation has a name of the form
1294
+ # `projects/<project>/instances/<instance>/databases/<database>/operations/<operation>`.
1295
+ # The long-running operation
1296
+ # {Google::Longrunning::Operation#metadata metadata} field type
1297
+ # `metadata.type_url` describes the type of the metadata. Operations returned
1298
+ # include those that have completed/failed/canceled within the last 7 days,
1299
+ # and pending operations.
1300
+ #
1301
+ # @param parent [String]
1302
+ # Required. The instance of the database operations.
1303
+ # Values are of the form `projects/<project>/instances/<instance>`.
1304
+ # @param filter [String]
1305
+ # An expression that filters the list of returned operations.
1306
+ #
1307
+ # A filter expression consists of a field name, a
1308
+ # comparison operator, and a value for filtering.
1309
+ # The value must be a string, a number, or a boolean. The comparison operator
1310
+ # must be one of: `<`, `>`, `<=`, `>=`, `!=`, `=`, or `:`.
1311
+ # Colon `:` is the contains operator. Filter rules are not case sensitive.
1312
+ #
1313
+ # The following fields in the {Google::Longrunning::Operation Operation}
1314
+ # are eligible for filtering:
1315
+ #
1316
+ # * `name` - The name of the long-running operation
1317
+ # * `done` - False if the operation is in progress, else true.
1318
+ # * `metadata.@type` - the type of metadata. For example, the type string
1319
+ # for {Google::Spanner::Admin::Database::V1::RestoreDatabaseMetadata RestoreDatabaseMetadata} is
1320
+ # `type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata`.
1321
+ # * `metadata.<field_name>` - any field in metadata.value.
1322
+ # * `error` - Error associated with the long-running operation.
1323
+ # * `response.@type` - the type of response.
1324
+ # * `response.<field_name>` - any field in response.value.
1325
+ #
1326
+ # You can combine multiple expressions by enclosing each expression in
1327
+ # parentheses. By default, expressions are combined with AND logic. However,
1328
+ # you can specify AND, OR, and NOT logic explicitly.
1329
+ #
1330
+ # Here are a few examples:
1331
+ #
1332
+ # * `done:true` - The operation is complete.
1333
+ # * `(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.RestoreDatabaseMetadata) AND` <br/>
1334
+ # `(metadata.source_type:BACKUP) AND` <br/>
1335
+ # `(metadata.backup_info.backup:backup_howl) AND` <br/>
1336
+ # `(metadata.name:restored_howl) AND` <br/>
1337
+ # `(metadata.progress.start_time < \"2018-03-28T14:50:00Z\") AND` <br/>
1338
+ # `(error:*)` - Return operations where:
1339
+ # * The operation's metadata type is {Google::Spanner::Admin::Database::V1::RestoreDatabaseMetadata RestoreDatabaseMetadata}.
1340
+ # * The database is restored from a backup.
1341
+ # * The backup name contains "backup_howl".
1342
+ # * The restored database's name contains "restored_howl".
1343
+ # * The operation started before 2018-03-28T14:50:00Z.
1344
+ # * The operation resulted in an error.
1345
+ # @param page_size [Integer]
1346
+ # The maximum number of resources contained in the underlying API
1347
+ # response. If page streaming is performed per-resource, this
1348
+ # parameter does not affect the return value. If page streaming is
1349
+ # performed per-page, this determines the maximum number of
1350
+ # resources in a page.
1351
+ # @param options [Google::Gax::CallOptions]
1352
+ # Overrides the default settings for this call, e.g, timeout,
1353
+ # retries, etc.
1354
+ # @yield [result, operation] Access the result along with the RPC operation
1355
+ # @yieldparam result [Google::Gax::PagedEnumerable<Google::Longrunning::Operation>]
1356
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
1357
+ # @return [Google::Gax::PagedEnumerable<Google::Longrunning::Operation>]
1358
+ # An enumerable of Google::Longrunning::Operation instances.
1359
+ # See Google::Gax::PagedEnumerable documentation for other
1360
+ # operations such as per-page iteration or access to the response
1361
+ # object.
1362
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
1363
+ # @example
1364
+ # require "google/cloud/spanner/admin/database"
1365
+ #
1366
+ # database_admin_client = Google::Cloud::Spanner::Admin::Database.new(version: :v1)
1367
+ # formatted_parent = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient.instance_path("[PROJECT]", "[INSTANCE]")
1368
+ #
1369
+ # # TODO: Initialize `filter`:
1370
+ # filter = ''
1371
+ #
1372
+ # # Iterate over all results.
1373
+ # database_admin_client.list_database_operations(formatted_parent, filter).each do |element|
1374
+ # # Process element.
1375
+ # end
1376
+ #
1377
+ # # Or iterate over results one page at a time.
1378
+ # database_admin_client.list_database_operations(formatted_parent, filter).each_page do |page|
1379
+ # # Process each page at a time.
1380
+ # page.each do |element|
1381
+ # # Process element.
1382
+ # end
1383
+ # end
1384
+
1385
+ def list_database_operations \
1386
+ parent,
1387
+ filter,
1388
+ page_size: nil,
1389
+ options: nil,
1390
+ &block
1391
+ req = {
1392
+ parent: parent,
1393
+ filter: filter,
1394
+ page_size: page_size
1395
+ }.delete_if { |_, v| v.nil? }
1396
+ req = Google::Gax::to_proto(req, Google::Spanner::Admin::Database::V1::ListDatabaseOperationsRequest)
1397
+ @list_database_operations.call(req, options, &block)
1398
+ end
1399
+
1400
+ # Lists the backup {Google::Longrunning::Operation long-running operations} in
1401
+ # the given instance. A backup operation has a name of the form
1402
+ # `projects/<project>/instances/<instance>/backups/<backup>/operations/<operation>`.
1403
+ # The long-running operation
1404
+ # {Google::Longrunning::Operation#metadata metadata} field type
1405
+ # `metadata.type_url` describes the type of the metadata. Operations returned
1406
+ # include those that have completed/failed/canceled within the last 7 days,
1407
+ # and pending operations. Operations returned are ordered by
1408
+ # `operation.metadata.value.progress.start_time` in descending order starting
1409
+ # from the most recently started operation.
1410
+ #
1411
+ # @param parent [String]
1412
+ # Required. The instance of the backup operations. Values are of
1413
+ # the form `projects/<project>/instances/<instance>`.
1414
+ # @param filter [String]
1415
+ # An expression that filters the list of returned backup operations.
1416
+ #
1417
+ # A filter expression consists of a field name, a
1418
+ # comparison operator, and a value for filtering.
1419
+ # The value must be a string, a number, or a boolean. The comparison operator
1420
+ # must be one of: `<`, `>`, `<=`, `>=`, `!=`, `=`, or `:`.
1421
+ # Colon `:` is the contains operator. Filter rules are not case sensitive.
1422
+ #
1423
+ # The following fields in the {Google::Longrunning::Operation operation}
1424
+ # are eligible for filtering:
1425
+ #
1426
+ # * `name` - The name of the long-running operation
1427
+ # * `done` - False if the operation is in progress, else true.
1428
+ # * `metadata.@type` - the type of metadata. For example, the type string
1429
+ # for {Google::Spanner::Admin::Database::V1::CreateBackupMetadata CreateBackupMetadata} is
1430
+ # `type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata`.
1431
+ # * `metadata.<field_name>` - any field in metadata.value.
1432
+ # * `error` - Error associated with the long-running operation.
1433
+ # * `response.@type` - the type of response.
1434
+ # * `response.<field_name>` - any field in response.value.
1435
+ #
1436
+ # You can combine multiple expressions by enclosing each expression in
1437
+ # parentheses. By default, expressions are combined with AND logic, but
1438
+ # you can specify AND, OR, and NOT logic explicitly.
1439
+ #
1440
+ # Here are a few examples:
1441
+ #
1442
+ # * `done:true` - The operation is complete.
1443
+ # * `metadata.database:prod` - The database the backup was taken from has
1444
+ # a name containing the string "prod".
1445
+ # * `(metadata.@type=type.googleapis.com/google.spanner.admin.database.v1.CreateBackupMetadata) AND` <br/>
1446
+ # `(metadata.name:howl) AND` <br/>
1447
+ # `(metadata.progress.start_time < \"2018-03-28T14:50:00Z\") AND` <br/>
1448
+ # `(error:*)` - Returns operations where:
1449
+ # * The operation's metadata type is {Google::Spanner::Admin::Database::V1::CreateBackupMetadata CreateBackupMetadata}.
1450
+ # * The backup name contains the string "howl".
1451
+ # * The operation started before 2018-03-28T14:50:00Z.
1452
+ # * The operation resulted in an error.
1453
+ # @param page_size [Integer]
1454
+ # The maximum number of resources contained in the underlying API
1455
+ # response. If page streaming is performed per-resource, this
1456
+ # parameter does not affect the return value. If page streaming is
1457
+ # performed per-page, this determines the maximum number of
1458
+ # resources in a page.
1459
+ # @param options [Google::Gax::CallOptions]
1460
+ # Overrides the default settings for this call, e.g, timeout,
1461
+ # retries, etc.
1462
+ # @yield [result, operation] Access the result along with the RPC operation
1463
+ # @yieldparam result [Google::Gax::PagedEnumerable<Google::Longrunning::Operation>]
1464
+ # @yieldparam operation [GRPC::ActiveCall::Operation]
1465
+ # @return [Google::Gax::PagedEnumerable<Google::Longrunning::Operation>]
1466
+ # An enumerable of Google::Longrunning::Operation instances.
1467
+ # See Google::Gax::PagedEnumerable documentation for other
1468
+ # operations such as per-page iteration or access to the response
1469
+ # object.
1470
+ # @raise [Google::Gax::GaxError] if the RPC is aborted.
1471
+ # @example
1472
+ # require "google/cloud/spanner/admin/database"
1473
+ #
1474
+ # database_admin_client = Google::Cloud::Spanner::Admin::Database.new(version: :v1)
1475
+ # formatted_parent = Google::Cloud::Spanner::Admin::Database::V1::DatabaseAdminClient.instance_path("[PROJECT]", "[INSTANCE]")
1476
+ #
1477
+ # # TODO: Initialize `filter`:
1478
+ # filter = ''
1479
+ #
1480
+ # # Iterate over all results.
1481
+ # database_admin_client.list_backup_operations(formatted_parent, filter).each do |element|
1482
+ # # Process element.
1483
+ # end
1484
+ #
1485
+ # # Or iterate over results one page at a time.
1486
+ # database_admin_client.list_backup_operations(formatted_parent, filter).each_page do |page|
1487
+ # # Process each page at a time.
1488
+ # page.each do |element|
1489
+ # # Process element.
1490
+ # end
1491
+ # end
1492
+
1493
+ def list_backup_operations \
1494
+ parent,
1495
+ filter,
1496
+ page_size: nil,
1497
+ options: nil,
1498
+ &block
1499
+ req = {
1500
+ parent: parent,
1501
+ filter: filter,
1502
+ page_size: page_size
1503
+ }.delete_if { |_, v| v.nil? }
1504
+ req = Google::Gax::to_proto(req, Google::Spanner::Admin::Database::V1::ListBackupOperationsRequest)
1505
+ @list_backup_operations.call(req, options, &block)
1506
+ end
785
1507
  end
786
1508
  end
787
1509
  end