google-cloud-spanner 1.15.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +1 -1
  3. data/CHANGELOG.md +49 -0
  4. data/CONTRIBUTING.md +5 -5
  5. data/TROUBLESHOOTING.md +0 -6
  6. data/lib/google-cloud-spanner.rb +10 -13
  7. data/lib/google/cloud/spanner.rb +6 -8
  8. data/lib/google/cloud/spanner/admin/database/credentials.rb +2 -2
  9. data/lib/google/cloud/spanner/admin/instance/credentials.rb +2 -2
  10. data/lib/google/cloud/spanner/backup.rb +315 -0
  11. data/lib/google/cloud/spanner/backup/job.rb +274 -0
  12. data/lib/google/cloud/spanner/backup/job/list.rb +177 -0
  13. data/lib/google/cloud/spanner/backup/list.rb +169 -0
  14. data/lib/google/cloud/spanner/backup/restore/job.rb +246 -0
  15. data/lib/google/cloud/spanner/batch_client.rb +2 -2
  16. data/lib/google/cloud/spanner/batch_snapshot.rb +120 -23
  17. data/lib/google/cloud/spanner/batch_update.rb +1 -1
  18. data/lib/google/cloud/spanner/client.rb +189 -30
  19. data/lib/google/cloud/spanner/commit.rb +14 -14
  20. data/lib/google/cloud/spanner/convert.rb +7 -7
  21. data/lib/google/cloud/spanner/credentials.rb +2 -2
  22. data/lib/google/cloud/spanner/data.rb +2 -2
  23. data/lib/google/cloud/spanner/database.rb +275 -15
  24. data/lib/google/cloud/spanner/database/backup_info.rb +105 -0
  25. data/lib/google/cloud/spanner/database/job.rb +5 -2
  26. data/lib/google/cloud/spanner/database/job/list.rb +177 -0
  27. data/lib/google/cloud/spanner/database/list.rb +1 -1
  28. data/lib/google/cloud/spanner/database/restore_info.rb +63 -0
  29. data/lib/google/cloud/spanner/fields.rb +8 -8
  30. data/lib/google/cloud/spanner/instance.rb +401 -8
  31. data/lib/google/cloud/spanner/instance/config.rb +1 -1
  32. data/lib/google/cloud/spanner/instance/config/list.rb +1 -1
  33. data/lib/google/cloud/spanner/instance/job.rb +2 -2
  34. data/lib/google/cloud/spanner/instance/list.rb +1 -1
  35. data/lib/google/cloud/spanner/partition.rb +4 -4
  36. data/lib/google/cloud/spanner/policy.rb +2 -2
  37. data/lib/google/cloud/spanner/results.rb +9 -6
  38. data/lib/google/cloud/spanner/service.rb +392 -302
  39. data/lib/google/cloud/spanner/session.rb +186 -31
  40. data/lib/google/cloud/spanner/snapshot.rb +60 -6
  41. data/lib/google/cloud/spanner/transaction.rb +116 -10
  42. data/lib/google/cloud/spanner/version.rb +1 -1
  43. metadata +28 -109
  44. data/lib/google/cloud/spanner/admin/database.rb +0 -149
  45. data/lib/google/cloud/spanner/admin/database/v1.rb +0 -147
  46. data/lib/google/cloud/spanner/admin/database/v1/credentials.rb +0 -46
  47. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb +0 -1513
  48. data/lib/google/cloud/spanner/admin/database/v1/database_admin_client_config.json +0 -111
  49. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/iam_policy.rb +0 -64
  50. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/options.rb +0 -33
  51. data/lib/google/cloud/spanner/admin/database/v1/doc/google/iam/v1/policy.rb +0 -151
  52. data/lib/google/cloud/spanner/admin/database/v1/doc/google/longrunning/operations.rb +0 -51
  53. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/any.rb +0 -131
  54. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/empty.rb +0 -29
  55. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/field_mask.rb +0 -222
  56. data/lib/google/cloud/spanner/admin/database/v1/doc/google/protobuf/timestamp.rb +0 -113
  57. data/lib/google/cloud/spanner/admin/database/v1/doc/google/rpc/status.rb +0 -39
  58. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/backup.rb +0 -325
  59. data/lib/google/cloud/spanner/admin/database/v1/doc/google/spanner/admin/database/v1/spanner_database_admin.rb +0 -368
  60. data/lib/google/cloud/spanner/admin/database/v1/doc/google/type/expr.rb +0 -45
  61. data/lib/google/cloud/spanner/admin/instance.rb +0 -164
  62. data/lib/google/cloud/spanner/admin/instance/v1.rb +0 -162
  63. data/lib/google/cloud/spanner/admin/instance/v1/credentials.rb +0 -46
  64. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/iam_policy.rb +0 -64
  65. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/options.rb +0 -33
  66. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/iam/v1/policy.rb +0 -151
  67. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/longrunning/operations.rb +0 -51
  68. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/any.rb +0 -131
  69. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/empty.rb +0 -29
  70. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/protobuf/field_mask.rb +0 -222
  71. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/rpc/status.rb +0 -39
  72. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/spanner/admin/instance/v1/spanner_instance_admin.rb +0 -334
  73. data/lib/google/cloud/spanner/admin/instance/v1/doc/google/type/expr.rb +0 -45
  74. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb +0 -975
  75. data/lib/google/cloud/spanner/admin/instance/v1/instance_admin_client_config.json +0 -76
  76. data/lib/google/cloud/spanner/v1.rb +0 -16
  77. data/lib/google/cloud/spanner/v1/credentials.rb +0 -42
  78. data/lib/google/cloud/spanner/v1/doc/google/protobuf/any.rb +0 -131
  79. data/lib/google/cloud/spanner/v1/doc/google/protobuf/duration.rb +0 -91
  80. data/lib/google/cloud/spanner/v1/doc/google/protobuf/empty.rb +0 -29
  81. data/lib/google/cloud/spanner/v1/doc/google/protobuf/struct.rb +0 -74
  82. data/lib/google/cloud/spanner/v1/doc/google/protobuf/timestamp.rb +0 -113
  83. data/lib/google/cloud/spanner/v1/doc/google/rpc/status.rb +0 -39
  84. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/keys.rb +0 -150
  85. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/mutation.rb +0 -95
  86. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/query_plan.rb +0 -121
  87. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/result_set.rb +0 -190
  88. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/spanner.rb +0 -570
  89. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/transaction.rb +0 -432
  90. data/lib/google/cloud/spanner/v1/doc/google/spanner/v1/type.rb +0 -112
  91. data/lib/google/cloud/spanner/v1/spanner_client.rb +0 -1485
  92. data/lib/google/cloud/spanner/v1/spanner_client_config.json +0 -121
  93. data/lib/google/spanner/admin/database/v1/backup_pb.rb +0 -98
  94. data/lib/google/spanner/admin/database/v1/common_pb.rb +0 -28
  95. data/lib/google/spanner/admin/database/v1/spanner_database_admin_pb.rb +0 -141
  96. data/lib/google/spanner/admin/database/v1/spanner_database_admin_services_pb.rb +0 -169
  97. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_pb.rb +0 -125
  98. data/lib/google/spanner/admin/instance/v1/spanner_instance_admin_services_pb.rb +0 -181
  99. data/lib/google/spanner/v1/keys_pb.rb +0 -34
  100. data/lib/google/spanner/v1/mutation_pb.rb +0 -39
  101. data/lib/google/spanner/v1/query_plan_pb.rb +0 -48
  102. data/lib/google/spanner/v1/result_set_pb.rb +0 -48
  103. data/lib/google/spanner/v1/spanner_pb.rb +0 -179
  104. data/lib/google/spanner/v1/spanner_services_pb.rb +0 -179
  105. data/lib/google/spanner/v1/transaction_pb.rb +0 -56
  106. data/lib/google/spanner/v1/type_pb.rb +0 -44
@@ -14,6 +14,7 @@
14
14
 
15
15
 
16
16
  require "google/cloud/spanner/status"
17
+ require "google/cloud/spanner/database/job/list"
17
18
 
18
19
  module Google
19
20
  module Cloud
@@ -51,7 +52,7 @@ module Google
51
52
  #
52
53
  class Job
53
54
  ##
54
- # @private The Google::Gax::Operation gRPC object.
55
+ # @private The `Gapic::Operation` gRPC object.
55
56
  attr_accessor :grpc
56
57
 
57
58
  ##
@@ -87,6 +88,8 @@ module Google
87
88
  def database
88
89
  return nil unless done?
89
90
  return nil unless @grpc.grpc_op.result == :response
91
+ return nil unless @grpc.results.instance_of? \
92
+ Admin::Database::V1::Database
90
93
  Database.from_grpc @grpc.results, service
91
94
  end
92
95
 
@@ -198,7 +201,7 @@ module Google
198
201
  end
199
202
 
200
203
  ##
201
- # @private New Database::Job from a Google::Gax::Operation object.
204
+ # @private New Database::Job from a `Gapic::Operation` object.
202
205
  def self.from_grpc grpc, service
203
206
  new.tap do |job|
204
207
  job.instance_variable_set :@grpc, grpc
@@ -0,0 +1,177 @@
1
+ # Copyright 2020 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
+
16
+ require "delegate"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Spanner
21
+ class Database
22
+ class Job
23
+ ##
24
+ # # List
25
+ #
26
+ # List is a special case Array with additional values for database
27
+ # operations.
28
+ #
29
+ class List < DelegateClass(::Array)
30
+ # @private
31
+ # The gRPC Service object.
32
+ attr_accessor :service
33
+
34
+ # @private
35
+ # The gRPC page enumerable object.
36
+ attr_accessor :grpc
37
+
38
+ ##
39
+ # @private Create a new Database::Job::List with an array of
40
+ # Google::Lognrunning::Operation instances.
41
+ def initialize arr = []
42
+ super arr
43
+ end
44
+
45
+ ##
46
+ # Whether there is a next page of database jobs.
47
+ #
48
+ # @return [Boolean]
49
+ #
50
+ # @example
51
+ # require "google/cloud/spanner"
52
+ #
53
+ # spanner = Google::Cloud::Spanner.new
54
+ #
55
+ # instance = spanner.instance "my-instance"
56
+ #
57
+ # jobs = instance.database_operations
58
+ # if jobs.next?
59
+ # next_jobs = jobs.next
60
+ # end
61
+ #
62
+ def next?
63
+ grpc.next_page?
64
+ end
65
+
66
+ ##
67
+ # Retrieve the next page of database jobs.
68
+ #
69
+ # @return [Google::Cloud::Spanner::Database::Job::List]
70
+ #
71
+ # @example
72
+ # require "google/cloud/spanner"
73
+ #
74
+ # spanner = Google::Cloud::Spanner.new
75
+ #
76
+ # instance = spanner.instance "my-instance"
77
+ #
78
+ # jobs = instance.database_operations
79
+ # if jobs.next?
80
+ # next_jobs = jobs.next
81
+ # end
82
+ #
83
+ def next
84
+ ensure_service!
85
+
86
+ return nil unless next?
87
+ grpc.next_page
88
+ self.class.from_grpc grpc, service
89
+ end
90
+
91
+ ##
92
+ # Retrieves remaining results by repeatedly invoking {#next} until
93
+ # {#next?} returns `false`. Calls the given block once for each
94
+ # result, which is passed as the argument to the block.
95
+ #
96
+ # An Enumerator is returned if no block is given.
97
+ #
98
+ # This method will make repeated API calls until all remaining
99
+ # results are retrieved. (Unlike `#each`, for example, which merely
100
+ # iterates over the results returned by a single API call.) Use with
101
+ # caution.
102
+ #
103
+ # @yield [job] The block for accessing each database job.
104
+ # @yieldparam [Google::Cloud::Spanner::Database::Job] job The
105
+ # database job object.
106
+ #
107
+ # @return [Enumerator]
108
+ #
109
+ # @example Iterating each database job by passing a block:
110
+ # require "google/cloud/spanner"
111
+ #
112
+ # spanner = Google::Cloud::Spanner.new
113
+ #
114
+ # instance = spanner.instance "my-instance"
115
+ #
116
+ # jobs = instance.database_operations
117
+ # jobs.all do |job|
118
+ # puts job.database.database_id
119
+ # end
120
+ #
121
+ # @example Using the enumerator by not passing a block:
122
+ # require "google/cloud/spanner"
123
+ #
124
+ # spanner = Google::Cloud::Spanner.new
125
+ #
126
+ # instance = spanner.instance "my-instance"
127
+ #
128
+ # jobs = instance.database_operations
129
+ # all_database_ids = jobs.all.map do |job|
130
+ # job.database.database_id
131
+ # end
132
+ #
133
+ def all
134
+ return enum_for :all unless block_given?
135
+
136
+ results = self
137
+ loop do
138
+ results.each { |r| yield r }
139
+ break unless next?
140
+ grpc.next_page
141
+ results = self.class.from_grpc grpc, service
142
+ end
143
+ end
144
+
145
+ ##
146
+ # @private
147
+ #
148
+ # New Database::Job::List from a
149
+ # `Gapic::PagedEnumerable<Google::Longrunning::Operation>`
150
+ # object. Operation object is a database operation.
151
+ #
152
+ def self.from_grpc grpc, service
153
+ operations_client = \
154
+ service.databases.instance_variable_get "@operations_client"
155
+ jobs = new(Array(grpc.response.operations).map do |job_grpc|
156
+ Job.from_grpc \
157
+ Gapic::Operation.new(job_grpc, operations_client),
158
+ service
159
+ end)
160
+ jobs.grpc = grpc
161
+ jobs.service = service
162
+ jobs
163
+ end
164
+
165
+ protected
166
+
167
+ ##
168
+ # Raise an error unless an active service is available.
169
+ def ensure_service!
170
+ raise "Must have active connection" unless @service
171
+ end
172
+ end
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
@@ -142,7 +142,7 @@ module Google
142
142
 
143
143
  ##
144
144
  # @private New Database::List from a
145
- # Google::Spanner::Admin::Database::V1::ListDatabasesResponse
145
+ # `Google::Cloud::Spanner::Admin::Database::V1::ListDatabasesResponse`
146
146
  # object.
147
147
  def self.from_grpc grpc, service, instance_id, max = nil
148
148
  databases = List.new(Array(grpc.databases).map do |database|
@@ -0,0 +1,63 @@
1
+ # Copyright 2020 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
+
16
+ require "google/cloud/spanner/database/backup_info"
17
+
18
+ module Google
19
+ module Cloud
20
+ module Spanner
21
+ class Database
22
+ class RestoreInfo
23
+ ##
24
+ # @private Creates a new Database::RestoreInfo instance.
25
+ def initialize grpc
26
+ @grpc = grpc
27
+ end
28
+
29
+ ##
30
+ # The database restored from source type `:BACKUP`.
31
+ # @return [Symbol]
32
+ def source_type
33
+ @grpc.source_type
34
+ end
35
+
36
+ ##
37
+ # Database restored from backup.
38
+ #
39
+ # @return [Boolean]
40
+ def source_backup?
41
+ @grpc.source_type == :BACKUP
42
+ end
43
+
44
+ # Information about the backup used to restore the database.
45
+ # The backup may no longer exist.
46
+ #
47
+ # @return [Google::Cloud::Spanner::Database::BackupInfo, nil]
48
+ def backup_info
49
+ return nil unless @grpc.backup_info
50
+ BackupInfo.from_grpc @grpc.backup_info
51
+ end
52
+
53
+ ##
54
+ # @private Creates a new Database::RestoreInfo instance from a
55
+ # `Google::Cloud::Spanner::Admin::Database::V1::RestoreInfo`
56
+ def self.from_grpc grpc
57
+ new grpc
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -372,9 +372,9 @@ module Google
372
372
  ##
373
373
  # @private
374
374
  def to_grpc_type
375
- Google::Spanner::V1::Type.new(
375
+ V1::Type.new(
376
376
  code: :STRUCT,
377
- struct_type: Google::Spanner::V1::StructType.new(
377
+ struct_type: V1::StructType.new(
378
378
  fields: @grpc_fields
379
379
  )
380
380
  )
@@ -382,7 +382,7 @@ module Google
382
382
 
383
383
  ##
384
384
  # @private Creates a new Fields instance from a
385
- # Google::Spanner::V1::Metadata::Row_type::Fields.
385
+ # V1::Metadata::Row_type::Fields.
386
386
  def self.from_grpc fields
387
387
  new([]).tap do |f|
388
388
  f.instance_variable_set :@grpc_fields, Array(fields)
@@ -412,18 +412,18 @@ module Google
412
412
  if pair.is_a?(Array)
413
413
  if pair.count == 2
414
414
  if pair.first.is_a?(Integer)
415
- Google::Spanner::V1::StructType::Field.new(
415
+ V1::StructType::Field.new(
416
416
  type: Convert.grpc_type_for_field(pair.last)
417
417
  )
418
418
  else
419
- Google::Spanner::V1::StructType::Field.new(
419
+ V1::StructType::Field.new(
420
420
  name: String(pair.first),
421
421
  type: Convert.grpc_type_for_field(pair.last)
422
422
  )
423
423
  end
424
424
  else
425
- Google::Spanner::V1::StructType::Field.new(
426
- type: Google::Spanner::V1::Type.new(
425
+ V1::StructType::Field.new(
426
+ type: V1::Type.new(
427
427
  code: :ARRAY,
428
428
  array_element_type: Convert.grpc_type_for_field(pair.last)
429
429
  )
@@ -435,7 +435,7 @@ module Google
435
435
  unless pair.is_a?(Symbol)
436
436
  raise ArgumentError, "type must be a symbol"
437
437
  end
438
- Google::Spanner::V1::StructType::Field.new(
438
+ V1::StructType::Field.new(
439
439
  type: Convert.grpc_type_for_field(pair)
440
440
  )
441
441
  end
@@ -334,6 +334,406 @@ module Google
334
334
  Database::Job.from_grpc grpc, service
335
335
  end
336
336
 
337
+ ##
338
+ # Retrieves the list of database operations for the given instance.
339
+ #
340
+ # @param filter [String]
341
+ # A filter expression that filters what operations are returned in the
342
+ # response.
343
+ #
344
+ # The response returns a list of
345
+ # `Google::Longrunning::Operation` long-running operations whose names
346
+ # are prefixed by a database name within the specified instance.
347
+ # The long-running operation
348
+ # `Google::Longrunning::Operation#metadata` metadata field type
349
+ # `metadata.type_url` describes the type of the metadata.
350
+ #
351
+ # The filter expression must specify the field name,
352
+ # a comparison operator, and the value that you want to use for
353
+ # filtering. The value must be a string, a number, or a boolean.
354
+ # The comparison operator must be
355
+ # <, >, <=, >=, !=, =, or :. Colon ':' represents a HAS operator
356
+ # which is roughly synonymous with equality. Filter rules are case
357
+ # insensitive.
358
+ #
359
+ # The long-running operation fields eligible for filtering are:
360
+ # * `name` --> The name of the long-running operation
361
+ # * `done` --> False if the operation is in progress, else true.
362
+ # * `metadata.type_url` (using filter string `metadata.@type`) and
363
+ # fields in `metadata.value` (using filter string
364
+ # `metadata.<field_name>`, where <field_name> is a field in
365
+ # metadata.value) are eligible for filtering.
366
+ # * `error` --> Error associated with the long-running operation.
367
+ # * `response.type_url` (using filter string `response.@type`) and
368
+ # fields in `response.value` (using filter string
369
+ # `response.<field_name>`, where <field_name> is a field in
370
+ # response.value)are eligible for filtering.
371
+ #
372
+ # To filter on multiple expressions, provide each separate
373
+ # expression within parentheses. By default, each expression
374
+ # is an AND expression. However, you can include AND, OR, and NOT
375
+ # expressions explicitly.
376
+ #
377
+ # Some examples of using filters are:
378
+ #
379
+ # * `done:true` --> The operation is complete.
380
+ # * `(metadata.@type:type.googleapis.com/google.spanner.admin.\
381
+ # database.v1.RestoreDatabaseMetadata)
382
+ # AND (metadata.source_type:BACKUP)
383
+ # AND (metadata.backup_info.backup:backup_howl)
384
+ # AND (metadata.name:restored_howl)
385
+ # AND (metadata.progress.start_time < \"2018-03-28T14:50:00Z\")
386
+ # AND (error:*)`
387
+ # --> Return RestoreDatabase operations from backups whose name
388
+ # contains "backup_howl", where the created database name
389
+ # contains the string "restored_howl", the start_time of the
390
+ # restore operation is before 2018-03-28T14:50:00Z,
391
+ # and the operation returned an error.
392
+ # @param page_size [Integer]
393
+ # The maximum number of resources contained in the underlying API
394
+ # response. If page streaming is performed per-resource, this
395
+ # parameter does not affect the return value. If page streaming is
396
+ # performed per-page, this determines the maximum number of
397
+ # resources in a page.
398
+ #
399
+ # @return [Array<Google::Cloud::Spanner::Database::Job>] List
400
+ # representing the long-running, asynchronous processing
401
+ # of a database operations.
402
+ # (See {Google::Cloud::Spanner::Database::Job::List})
403
+ #
404
+ # @example
405
+ # require "google/cloud/spanner"
406
+ #
407
+ # spanner = Google::Cloud::Spanner.new
408
+ #
409
+ # instance = spanner.instance "my-instance"
410
+ #
411
+ # jobs = instance.database_operations
412
+ # jobs.each do |job|
413
+ # if job.error?
414
+ # p job.error
415
+ # else
416
+ # p job.database.database_id
417
+ # end
418
+ # end
419
+ #
420
+ # @example Retrieve all
421
+ # require "google/cloud/spanner"
422
+ #
423
+ # spanner = Google::Cloud::Spanner.new
424
+ #
425
+ # instance = spanner.instance "my-instance"
426
+ #
427
+ # jobs = instance.database_operations
428
+ # jobs.all do |job|
429
+ # if job.error?
430
+ # p job.error
431
+ # else
432
+ # puts job.database.database_id
433
+ # end
434
+ # end
435
+ #
436
+ # @example List by page size
437
+ # require "google/cloud/spanner"
438
+ #
439
+ # spanner = Google::Cloud::Spanner.new
440
+ # instance = spanner.instance "my-instance"
441
+ #
442
+ # jobs = instance.database_operations page_size: 10
443
+ # jobs.each do |job|
444
+ # if job.error?
445
+ # p job.error
446
+ # else
447
+ # puts job.database.database_id
448
+ # end
449
+ # end
450
+ #
451
+ # @example Filter and list
452
+ # require "google/cloud/spanner"
453
+ #
454
+ # spanner = Google::Cloud::Spanner.new
455
+ #
456
+ # instance = spanner.instance "my-instance"
457
+ #
458
+ # filter = "metadata.@type:CreateDatabaseMetadata"
459
+ # jobs = instance.database_operations filter: filter
460
+ # jobs.each do |job|
461
+ # if job.error?
462
+ # p job.error
463
+ # else
464
+ # puts job.database.database_id
465
+ # end
466
+ # end
467
+ #
468
+ def database_operations filter: nil, page_size: nil
469
+ grpc = service.list_database_operations \
470
+ instance_id,
471
+ filter: filter,
472
+ page_size: page_size
473
+ Database::Job::List.from_grpc grpc, service
474
+ end
475
+
476
+ ##
477
+ # Retrieves backups belonging to the instance.
478
+ #
479
+ # @param [String] filter Optional. A filter expression that filters
480
+ # backups listed in the response. The expression must specify the
481
+ # field name, a comparison operator, and the value that you want to
482
+ # use for filtering. The value must be a string, a number, or a
483
+ # boolean. The comparison operator must be
484
+ # <, >, <=, >=, !=, =, or :. Colon ':' represents a HAS operator
485
+ # which is roughly synonymous with equality.
486
+ # Filter rules are case insensitive.
487
+ #
488
+ # The fields eligible for filtering are:
489
+ # * `name`
490
+ # * `database`
491
+ # * `state`
492
+ # * `create_time`(and values are of the format YYYY-MM-DDTHH:MM:SSZ)
493
+ # * `expire_time`(and values are of the format YYYY-MM-DDTHH:MM:SSZ)
494
+ # * `size_bytes`
495
+ #
496
+ # To filter on multiple expressions, provide each separate expression
497
+ # within parentheses. By default, each expression is an AND
498
+ # expression. However, you can include AND, OR, and NOT expressions
499
+ # explicitly.
500
+ #
501
+ # Some examples of using filters are:
502
+ #
503
+ # * `name:Howl` --> The backup's name contains the string "howl".
504
+ # * `database:prod`
505
+ # --> The database's name contains the string "prod".
506
+ # * `state:CREATING` --> The backup is pending creation.
507
+ # * `state:READY` --> The backup is fully created and ready for use.
508
+ # * `(name:howl) AND (create_time < \"2018-03-28T14:50:00Z\")`
509
+ # --> The backup name contains the string "howl" and
510
+ # `create_time` of the backup is before
511
+ # 2018-03-28T14:50:00Z.
512
+ # * `expire_time < \"2018-03-28T14:50:00Z\"`
513
+ # --> The backup `expire_time` is before 2018-03-28T14:50:00Z.
514
+ # * `size_bytes > 10000000000` -->
515
+ # The backup's size is greater than 10GB
516
+ # @param [Integer] page_size Optional. Number of backups to be returned
517
+ # in the response. If 0 or less, defaults to the server's maximum
518
+ # allowed page size.
519
+ # @return [Array<Google::Cloud::Spanner::Backup>] Enumerable list of
520
+ # backups. (See {Google::Cloud::Spanner::Backup::List})
521
+ #
522
+ # @example
523
+ # require "google/cloud/spanner"
524
+ #
525
+ # spanner = Google::Cloud::Spanner.new
526
+ # instance = spanner.instance "my-instance"
527
+ #
528
+ # instance.backups.all.each do |backup|
529
+ # puts backup.backup_id
530
+ # end
531
+ #
532
+ # @example List backups by page size
533
+ # require "google/cloud/spanner"
534
+ #
535
+ # spanner = Google::Cloud::Spanner.new
536
+ # instance = spanner.instance "my-instance"
537
+ #
538
+ # instance.backups(page_size: 5).all.each do |backup|
539
+ # puts backup.backup_id
540
+ # end
541
+ #
542
+ # @example Filter and list backups
543
+ # require "google/cloud/spanner"
544
+ #
545
+ # spanner = Google::Cloud::Spanner.new
546
+ # instance = spanner.instance "my-instance"
547
+ #
548
+ # # filter backups by name.
549
+ # instance.backups(filter: "name:my-backup").all.each do |backup|
550
+ # puts backup.backup_id
551
+ # end
552
+ #
553
+ # # filter backups by database name.
554
+ # instance.backups(filter: "database:prod-db").all.each do |backup|
555
+ # puts backup.backup_id
556
+ # end
557
+ #
558
+ def backups filter: nil, page_size: nil
559
+ ensure_service!
560
+ grpc = service.list_backups \
561
+ instance_id,
562
+ filter: filter,
563
+ page_size: page_size
564
+ Backup::List.from_grpc grpc, service
565
+ end
566
+
567
+ ##
568
+ # Retrieves a backup belonging to the instance by identifier.
569
+ #
570
+ # @param [String] backup_id The unique identifier for the backup.
571
+ #
572
+ # @return [Google::Cloud::Spanner::Backup, nil] Returns `nil`
573
+ # if database does not exist.
574
+ #
575
+ # @example
576
+ # require "google/cloud/spanner"
577
+ #
578
+ # spanner = Google::Cloud::Spanner.new
579
+ # instance = spanner.instance "my-instance"
580
+ # backup = instance.backup "my-backup"
581
+ #
582
+ # @example Will return `nil` if backup does not exist.
583
+ # require "google/cloud/spanner"
584
+ #
585
+ # spanner = Google::Cloud::Spanner.new
586
+ # instance = spanner.instance "my-instance"
587
+ # backup = instance.backup "non-existing-backup" # nil
588
+ #
589
+ def backup backup_id
590
+ ensure_service!
591
+ grpc = service.get_backup instance_id, backup_id
592
+ Backup.from_grpc grpc, service
593
+ rescue Google::Cloud::NotFoundError
594
+ nil
595
+ end
596
+
597
+ ##
598
+ # Retrieves the list of database backup operations for the given
599
+ # instance.
600
+ #
601
+ # @param filter [String]
602
+ # A filter expression that filters what operations are returned in the
603
+ # response.
604
+ #
605
+ # The response returns a list of
606
+ # `Google::Longrunning::Operation` long-running operations whose names
607
+ # are prefixed by a backup name within the specified instance.
608
+ # The long-running operation
609
+ # `Google::Longrunning::Operation#metadata` metadata field type
610
+ # `metadata.type_url` describes the type of the metadata.
611
+ #
612
+ # The filter expression must specify the field name of an operation, a
613
+ # comparison operator, and the value that you want to use for
614
+ # filtering.
615
+ # The value must be a string, a number, or a boolean. The comparison
616
+ # operator must be
617
+ # <, >, <=, >=, !=, =, or :. Colon ':'' represents a HAS operator
618
+ # which is roughly synonymous with equality. Filter rules are case
619
+ # insensitive.
620
+ #
621
+ # The long-running operation fields eligible for filtering are:
622
+ # * `name` --> The name of the long-running operation
623
+ # * `done` --> False if the operation is in progress, else true.
624
+ # * `metadata.type_url` (using filter string `metadata.@type`) and
625
+ # fields in `metadata.value` (using filter string
626
+ # `metadata.<field_name>`, where <field_name> is a field in
627
+ # metadata.value) are eligible for filtering.
628
+ # * `error` --> Error associated with the long-running operation.
629
+ # * `response.type_url` (using filter string `response.@type`) and
630
+ # fields in `response.value` (using filter string
631
+ # `response.<field_name>`, where <field_name> is a field in
632
+ # response.value) are eligible for filtering.
633
+ #
634
+ # To filter on multiple expressions, provide each separate
635
+ # expression within parentheses. By default, each expression is an
636
+ # AND expression. However, you can include AND, OR, and NOT
637
+ # expressions explicitly.
638
+ #
639
+ # Some examples of using filters are:
640
+ #
641
+ # * `done:true` --> The operation is complete.
642
+ # * `metadata.database:prod`
643
+ # --> The database the backup was taken from has a name containing
644
+ # the string "prod".
645
+ # * `(metadata.@type:type.googleapis.com/google.spanner.admin.\
646
+ # database.v1.CreateBackupMetadata)
647
+ # AND (metadata.name:howl)
648
+ # AND (metadata.progress.start_time < \"2018-03-28T14:50:00Z\")
649
+ # AND (error:*)`
650
+ # --> Return CreateBackup operations where the created backup name
651
+ # contains the string "howl", the progress.start_time of the
652
+ # backup operation is before 2018-03-28T14:50:00Z, and the
653
+ # operation returned an error.
654
+ # @param page_size [Integer]
655
+ # The maximum number of resources contained in the underlying API
656
+ # response. If page streaming is performed per-resource, this
657
+ # parameter does not affect the return value. If page streaming is
658
+ # performed per-page, this determines the maximum number of
659
+ # resources in a page.
660
+ #
661
+ # @return [Array<Google::Cloud::Spanner::Backup::Job>] List representing
662
+ # the long-running, asynchronous processing of a backup operations.
663
+ # (See {Google::Cloud::Spanner::Backup::Job::List})
664
+ #
665
+ # @example
666
+ # require "google/cloud/spanner"
667
+ #
668
+ # spanner = Google::Cloud::Spanner.new
669
+ #
670
+ # instance = spanner.instance "my-instance"
671
+ #
672
+ # jobs = instance.backup_operations
673
+ # jobs.each do |job|
674
+ # if job.error?
675
+ # p job.error
676
+ # else
677
+ # p job.backup.backup_id
678
+ # end
679
+ # end
680
+ #
681
+ # @example Retrieve all
682
+ # require "google/cloud/spanner"
683
+ #
684
+ # spanner = Google::Cloud::Spanner.new
685
+ #
686
+ # instance = spanner.instance "my-instance"
687
+ #
688
+ # jobs = instance.backup_operations
689
+ # jobs.all do |job|
690
+ # if job.error?
691
+ # p job.error
692
+ # else
693
+ # p job.backup.backup_id
694
+ # end
695
+ # end
696
+ #
697
+ # @example List by page size
698
+ # require "google/cloud/spanner"
699
+ #
700
+ # spanner = Google::Cloud::Spanner.new
701
+ # instance = spanner.instance "my-instance"
702
+ #
703
+ # jobs = instance.backup_operations page_size: 10
704
+ # jobs.each do |job|
705
+ # if job.error?
706
+ # p job.error
707
+ # else
708
+ # puts job.backup.backup_id
709
+ # end
710
+ # end
711
+ #
712
+ # @example Filter and list
713
+ # require "google/cloud/spanner"
714
+ #
715
+ # spanner = Google::Cloud::Spanner.new
716
+ #
717
+ # instance = spanner.instance "my-instance"
718
+ #
719
+ # filter = "metadata.@type:CreateBackupMetadata"
720
+ # jobs = instance.backup_operations filter: filter
721
+ # jobs.each do |job|
722
+ # if job.error?
723
+ # p job.error
724
+ # else
725
+ # puts job.backup.backup_id
726
+ # end
727
+ # end
728
+ #
729
+ def backup_operations filter: nil, page_size: nil
730
+ grpc = service.list_backup_operations \
731
+ instance_id,
732
+ filter: filter,
733
+ page_size: page_size
734
+ Backup::Job::List.from_grpc grpc, service
735
+ end
736
+
337
737
  ##
338
738
  # Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
339
739
  # policy for this instance.
@@ -456,7 +856,7 @@ module Google
456
856
 
457
857
  ##
458
858
  # @private Creates a new Instance instance from a
459
- # Google::Spanner::Admin::Instance::V1::Instance.
859
+ # `Google::Cloud::Spanner::Admin::Instance::V1::Instance`.
460
860
  def self.from_grpc grpc, service
461
861
  new grpc, service
462
862
  end
@@ -469,13 +869,6 @@ module Google
469
869
  def ensure_service!
470
870
  raise "Must have active connection to service" unless service
471
871
  end
472
-
473
- def instance_config_path name
474
- return name if name.to_s.include? "/"
475
- Admin::Instance::V1::InstanceAdminClient.instance_config_path(
476
- project, name.to_s
477
- )
478
- end
479
872
  end
480
873
  end
481
874
  end