google-cloud-bigtable 1.0.2 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/TROUBLESHOOTING.md +2 -8
  4. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +27 -24
  5. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +60 -57
  6. data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +90 -23
  7. data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +125 -98
  8. data/lib/google/bigtable/admin/v2/common_pb.rb +9 -4
  9. data/lib/google/bigtable/admin/v2/instance_pb.rb +12 -11
  10. data/lib/google/bigtable/admin/v2/table_pb.rb +52 -14
  11. data/lib/google/bigtable/v2/bigtable_pb.rb +17 -17
  12. data/lib/google/bigtable/v2/bigtable_services_pb.rb +39 -39
  13. data/lib/google/bigtable/v2/data_pb.rb +21 -21
  14. data/lib/google/cloud/bigtable/admin.rb +3 -3
  15. data/lib/google/cloud/bigtable/admin/v2.rb +4 -3
  16. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +60 -50
  17. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +1 -1
  18. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +547 -58
  19. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +31 -1
  20. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +46 -39
  21. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +281 -53
  22. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +15 -17
  23. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +119 -26
  24. data/lib/google/cloud/bigtable/app_profile/list.rb +2 -2
  25. data/lib/google/cloud/bigtable/backup.rb +324 -0
  26. data/lib/google/cloud/bigtable/backup/job.rb +87 -0
  27. data/lib/google/cloud/bigtable/backup/list.rb +167 -0
  28. data/lib/google/cloud/bigtable/cluster.rb +99 -0
  29. data/lib/google/cloud/bigtable/cluster/list.rb +1 -1
  30. data/lib/google/cloud/bigtable/column_family_map.rb +1 -1
  31. data/lib/google/cloud/bigtable/instance.rb +4 -7
  32. data/lib/google/cloud/bigtable/instance/list.rb +1 -1
  33. data/lib/google/cloud/bigtable/longrunning_job.rb +11 -0
  34. data/lib/google/cloud/bigtable/policy.rb +1 -1
  35. data/lib/google/cloud/bigtable/service.rb +131 -0
  36. data/lib/google/cloud/bigtable/table.rb +112 -0
  37. data/lib/google/cloud/bigtable/table/cluster_state.rb +25 -4
  38. data/lib/google/cloud/bigtable/table/list.rb +1 -1
  39. data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
  40. data/lib/google/cloud/bigtable/v2.rb +1 -1
  41. data/lib/google/cloud/bigtable/v2/bigtable_client.rb +3 -0
  42. data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +7 -7
  43. data/lib/google/cloud/bigtable/version.rb +1 -1
  44. metadata +9 -5
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+
18
+ module Google
19
+ module Cloud
20
+ module Bigtable
21
+ class Backup
22
+ ##
23
+ # # Job
24
+ #
25
+ # A resource representing the long-running, asynchronous processing of an backup create operation. The job can
26
+ # be refreshed to retrieve the backup object once the operation has been completed.
27
+ #
28
+ # See {Cluster#create_backup}.
29
+ #
30
+ # @see https://cloud.google.com/bigtable/docs/reference/admin/rpc/google.longrunning#google.longrunning.Operation
31
+ # Long-running Operation
32
+ #
33
+ # @example
34
+ # require "google/cloud/bigtable"
35
+ #
36
+ # bigtable = Google::Cloud::Bigtable.new
37
+ # instance = bigtable.instance("my-instance")
38
+ # cluster = instance.cluster("my-cluster")
39
+ # table = instance.table("my-table")
40
+ #
41
+ # expire_time = Time.now + 60 * 60 * 7
42
+ # job = cluster.create_backup(table, "my-backup", expire_time)
43
+ #
44
+ # job.wait_until_done!
45
+ # job.done? #=> true
46
+ #
47
+ # if job.error?
48
+ # status = job.error
49
+ # else
50
+ # backup = job.backup
51
+ # end
52
+ #
53
+ class Job < LongrunningJob
54
+ ##
55
+ # Get the backup object from operation results.
56
+ #
57
+ # @return [Google::Cloud::Bigtable::Backup, nil] The backup instance, or `nil` if the operation is not
58
+ # complete.
59
+ #
60
+ # @example
61
+ # require "google/cloud/bigtable"
62
+ #
63
+ # bigtable = Google::Cloud::Bigtable.new
64
+ # instance = bigtable.instance("my-instance")
65
+ # cluster = instance.cluster("my-cluster")
66
+ # table = instance.table("my-table")
67
+ #
68
+ # expire_time = Time.now + 60 * 60 * 7
69
+ # job = cluster.create_backup(table, "my-backup", expire_time)
70
+ #
71
+ # job.wait_until_done!
72
+ # job.done? #=> true
73
+ #
74
+ # if job.error?
75
+ # status = job.error
76
+ # else
77
+ # backup = job.backup
78
+ # end
79
+ #
80
+ def backup
81
+ Backup.from_grpc results, service if results
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,167 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2020 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+
18
+ module Google
19
+ module Cloud
20
+ module Bigtable
21
+ class Backup
22
+ ##
23
+ # Backup::List is a special-case array with additional values.
24
+ class List < DelegateClass(::Array)
25
+ # @private
26
+ # The gRPC Service object.
27
+ attr_accessor :service
28
+
29
+ # @private
30
+ # The gRPC page enumerable object.
31
+ attr_accessor :grpc
32
+
33
+ # @private
34
+ # Creates a new Backup::List with an array of backups.
35
+ def initialize arr = []
36
+ super arr
37
+ end
38
+
39
+ ##
40
+ # Whether there is a next page of backups.
41
+ #
42
+ # @return [Boolean]
43
+ #
44
+ # @example
45
+ # require "google/cloud/bigtable"
46
+ #
47
+ # bigtable = Google::Cloud::Bigtable.new
48
+ #
49
+ # instance = bigtable.instance("my-instance")
50
+ # cluster = instance.cluster("my-cluster")
51
+ #
52
+ # backups = cluster.backups
53
+ #
54
+ # if backups.next?
55
+ # next_backups = backups.next
56
+ # end
57
+ #
58
+ def next?
59
+ grpc.next_page?
60
+ end
61
+
62
+ ##
63
+ # Retrieves the next page of backups.
64
+ #
65
+ # @return [Backup::List] The list of backups.
66
+ #
67
+ # @example
68
+ # require "google/cloud/bigtable"
69
+ #
70
+ # bigtable = Google::Cloud::Bigtable.new
71
+ #
72
+ # instance = bigtable.instance("my-instance")
73
+ # cluster = instance.cluster("my-cluster")
74
+ #
75
+ # backups = cluster.backups
76
+ #
77
+ # if backups.next?
78
+ # next_backups = backups.next
79
+ # end
80
+ #
81
+ def next
82
+ ensure_grpc!
83
+
84
+ return nil unless next?
85
+ grpc.next_page
86
+ self.class.from_grpc grpc, service
87
+ end
88
+
89
+ ##
90
+ # Retrieves remaining results by repeatedly invoking {#next} until {#next?} returns `false`. Calls the given
91
+ # block once for each result, which is passed as the argument to the block.
92
+ #
93
+ # An enumerator is returned if no block is given.
94
+ #
95
+ # This method will make repeated API calls until all remaining results are retrieved (unlike `#each`, for
96
+ # example, which merely iterates over the results returned by a single API call). Use with caution.
97
+ #
98
+ # @yield [backup] The block for accessing each backup.
99
+ # @yieldparam [Backup] backup The backup object.
100
+ #
101
+ # @return [Enumerator,nil] An enumerator is returned if no block is given, otherwise `nil`.
102
+ #
103
+ # @example Iterating each backup by passing a block:
104
+ # require "google/cloud/bigtable"
105
+ #
106
+ # bigtable = Google::Cloud::Bigtable.new
107
+ #
108
+ # instance = bigtable.instance("my-instance")
109
+ # cluster = instance.cluster("my-cluster")
110
+ #
111
+ # cluster.backups.all do |backup|
112
+ # puts backup.backup_id
113
+ # end
114
+ #
115
+ # @example Using the enumerator by not passing a block:
116
+ # require "google/cloud/bigtable"
117
+ #
118
+ # bigtable = Google::Cloud::Bigtable.new
119
+ #
120
+ # instance = bigtable.instance("my-instance")
121
+ # cluster = instance.cluster("my-cluster")
122
+ #
123
+ # all_backup_ids = cluster.backups.all.map do |backup|
124
+ # backup.backup_id
125
+ # end
126
+ #
127
+ def all
128
+ return enum_for :all unless block_given?
129
+
130
+ results = self
131
+ loop do
132
+ results.each { |r| yield r }
133
+ break unless next?
134
+ grpc.next_page
135
+ results = self.class.from_grpc grpc, service
136
+ end
137
+ end
138
+
139
+ # @private
140
+ # New Snapshot::List from a Google::Gax::PagedEnumerable<Google::Bigtable::Admin::V2::Backup> object.
141
+ # @param grpc [Google::Gax::PagedEnumerable<Google::Bigtable::Admin::V2::Backup> ]
142
+ # @param service [Google::Cloud::Bigtable::Service]
143
+ # @return [Array<Google::Cloud::Bigtable::Backup>]
144
+ def self.from_grpc grpc, service
145
+ backups = List.new(
146
+ Array(grpc.response.backups).map do |backup|
147
+ Backup.from_grpc backup, service
148
+ end
149
+ )
150
+ backups.grpc = grpc
151
+ backups.service = service
152
+ backups
153
+ end
154
+
155
+ protected
156
+
157
+ # @private
158
+ #
159
+ # Raises an error if an active gRPC call is not available.
160
+ def ensure_grpc!
161
+ raise "Must have active gRPC call" unless grpc
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
167
+ end
@@ -15,6 +15,7 @@
15
15
  # limitations under the License.
16
16
 
17
17
 
18
+ require "google/cloud/bigtable/backup"
18
19
  require "google/cloud/bigtable/cluster/list"
19
20
  require "google/cloud/bigtable/cluster/job"
20
21
 
@@ -196,6 +197,104 @@ module Google
196
197
  @grpc.location
197
198
  end
198
199
 
200
+ ##
201
+ # Creates a new Cloud Bigtable Backup.
202
+ #
203
+ # @param source_table [Table, String] The table object, or the name of the table,
204
+ # from which the backup is to be created. The table needs to be in the same
205
+ # instance as the backup. Required.
206
+ # @param backup_id [String] The id of the backup to be created. This string must
207
+ # be between 1 and 50 characters in length and match the regex
208
+ # `[_a-zA-Z0-9][-_.a-zA-Z0-9]*`. Required.
209
+ # @param expire_time [Time] The expiration time of the backup, with microseconds
210
+ # granularity that must be at least 6 hours and at most 30 days
211
+ # from the time the request is received. Once the `expire_time`
212
+ # has passed, Cloud Bigtable will delete the backup and free the
213
+ # resources used by the backup. Required.
214
+ # @return [Google::Cloud::Bigtable::Backup::Job]
215
+ # The job representing the long-running, asynchronous processing of
216
+ # a backup create operation.
217
+ #
218
+ # @example
219
+ # require "google/cloud/bigtable"
220
+ #
221
+ # bigtable = Google::Cloud::Bigtable.new
222
+ # instance = bigtable.instance("my-instance")
223
+ # cluster = instance.cluster("my-cluster")
224
+ # table = instance.table("my-table")
225
+ #
226
+ # expire_time = Time.now + 60 * 60 * 7
227
+ # job = cluster.create_backup(table, "my-backup", expire_time)
228
+ #
229
+ # job.wait_until_done!
230
+ # job.done? #=> true
231
+ #
232
+ # if job.error?
233
+ # status = job.error
234
+ # else
235
+ # backup = job.backup
236
+ # end
237
+ #
238
+ def create_backup source_table, backup_id, expire_time
239
+ source_table_id = source_table.respond_to?(:name) ? source_table.name : source_table
240
+ grpc = service.create_backup instance_id: instance_id,
241
+ cluster_id: cluster_id,
242
+ backup_id: backup_id,
243
+ source_table_id: source_table_id,
244
+ expire_time: expire_time
245
+ Backup::Job.from_grpc grpc, service
246
+ end
247
+
248
+ ##
249
+ # Gets a backup in the cluster.
250
+ #
251
+ # @param backup_id [String] The unique ID of the requested backup.
252
+ #
253
+ # @return [Google::Cloud::Bigtable::Backup, nil] The backup object, or `nil` if not found in the service.
254
+ #
255
+ # @example
256
+ # require "google/cloud/bigtable"
257
+ #
258
+ # bigtable = Google::Cloud::Bigtable.new
259
+ #
260
+ # instance = bigtable.instance("my-instance")
261
+ # cluster = instance.cluster("my-cluster")
262
+ #
263
+ # backup = cluster.backup("my-backup")
264
+ #
265
+ # if backup
266
+ # puts backup.backup_id
267
+ # end
268
+ #
269
+ def backup backup_id
270
+ grpc = service.get_backup instance_id, cluster_id, backup_id
271
+ Backup.from_grpc grpc, service
272
+ rescue Google::Cloud::NotFoundError
273
+ nil
274
+ end
275
+
276
+ ##
277
+ # Lists all backups in the cluster.
278
+ #
279
+ # @return [Array<Google::Cloud::Bigtable::Backup>] (See {Google::Cloud::Bigtable::Backup::List})
280
+ #
281
+ # @example
282
+ # require "google/cloud/bigtable"
283
+ #
284
+ # bigtable = Google::Cloud::Bigtable.new
285
+ #
286
+ # instance = bigtable.instance("my-instance")
287
+ # cluster = instance.cluster("my-cluster")
288
+ #
289
+ # cluster.backups.all do |backup|
290
+ # puts backup.backup_id
291
+ # end
292
+ #
293
+ def backups
294
+ grpc = service.list_backups instance_id, cluster_id
295
+ Backup::List.from_grpc grpc, service
296
+ end
297
+
199
298
  ##
200
299
  # Updates the cluster.
201
300
  #
@@ -109,7 +109,7 @@ module Google
109
109
  # @yield [cluster] The block for accessing each cluster.
110
110
  # @yieldparam [Cluster] cluster The cluster object.
111
111
  #
112
- # @return [Enumerator]
112
+ # @return [Enumerator,nil] An enumerator is returned if no block is given, otherwise `nil`.
113
113
  #
114
114
  # @example Iterating each cluster by passing a block:
115
115
  # require "google/cloud/bigtable"
@@ -117,7 +117,7 @@ module Google
117
117
  # @yieldparam [String] name the column family name.
118
118
  # @yieldparam [ColumnFamily] column_family the column family object.
119
119
  #
120
- # @return [Enumerator]
120
+ # @return [Enumerator,nil] An enumerator is returned if no block is given, otherwise `nil`.
121
121
  #
122
122
  def each
123
123
  return enum_for :each unless block_given?
@@ -854,7 +854,7 @@ module Google
854
854
  # policy.add("roles/owner", "user:owner@example.com")
855
855
  # updated_policy = instance.update_policy(policy)
856
856
  #
857
- # puts update_policy.roles
857
+ # puts updated_policy.roles
858
858
  #
859
859
  def update_policy new_policy
860
860
  ensure_service!
@@ -884,7 +884,7 @@ module Google
884
884
  # * bigtable.tables.get
885
885
  # * bigtable.tables.list
886
886
  #
887
- # @return [Array<Strings>] The permissions that have access.
887
+ # @return [Array<String>] The permissions that are configured for the policy.
888
888
  #
889
889
  # @example
890
890
  # require "google/cloud/bigtable"
@@ -902,11 +902,8 @@ module Google
902
902
  #
903
903
  def test_iam_permissions *permissions
904
904
  ensure_service!
905
- grpc = service.test_instance_permissions(
906
- instance_id,
907
- Array(permissions).flatten
908
- )
909
- grpc.permissions
905
+ grpc = service.test_instance_permissions instance_id, permissions.flatten
906
+ grpc.permissions.to_a
910
907
  end
911
908
 
912
909
  # @private
@@ -106,7 +106,7 @@ module Google
106
106
  # @yield [instance] The block for accessing each instance.
107
107
  # @yieldparam [Instance] instance The instance object.
108
108
  #
109
- # @return [Enumerator]
109
+ # @return [Enumerator,nil] An enumerator is returned if no block is given, otherwise `nil`.
110
110
  #
111
111
  # @example Iterating each instance by passing a block:
112
112
  # require "google/cloud/bigtable"
@@ -97,6 +97,17 @@ module Google
97
97
  @grpc.wait_until_done!
98
98
  end
99
99
 
100
+ ##
101
+ # @private Gets the metadata object of the operation.
102
+ #
103
+ # @return [Object, nil] `nil` if the operation is not complete.
104
+ #
105
+ def metadata
106
+ return nil unless done?
107
+ return nil unless @grpc.grpc_op.result == :response
108
+ @grpc.metadata
109
+ end
110
+
100
111
  # @private
101
112
  # New BasicJob from a Google::Gax::Operation object.
102
113
  def self.from_grpc grpc, service
@@ -19,7 +19,7 @@ module Google
19
19
  ##
20
20
  # # Policy
21
21
  #
22
- # Represents a Cloud IAM Policy for Bigtable instance resources.
22
+ # Represents a Cloud IAM Policy for Bigtable resources.
23
23
  #
24
24
  # A common pattern for updating a resource's metadata, such as its policy,
25
25
  # is to read the current data from the service, update the data locally,