google-cloud-bigtable 0.6.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +4 -26
  3. data/CHANGELOG.md +85 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/OVERVIEW.md +388 -19
  6. data/lib/google-cloud-bigtable.rb +19 -22
  7. data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +1 -1
  8. data/lib/google/bigtable/v2/bigtable_pb.rb +3 -0
  9. data/lib/google/bigtable/v2/bigtable_services_pb.rb +1 -1
  10. data/lib/google/cloud/bigtable.rb +11 -17
  11. data/lib/google/cloud/bigtable/admin.rb +1 -1
  12. data/lib/google/cloud/bigtable/admin/v2.rb +1 -1
  13. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1 -1
  14. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +42 -21
  15. data/lib/google/cloud/bigtable/app_profile.rb +162 -96
  16. data/lib/google/cloud/bigtable/app_profile/job.rb +5 -8
  17. data/lib/google/cloud/bigtable/app_profile/list.rb +18 -12
  18. data/lib/google/cloud/bigtable/chunk_processor.rb +24 -36
  19. data/lib/google/cloud/bigtable/cluster.rb +45 -18
  20. data/lib/google/cloud/bigtable/cluster/job.rb +3 -7
  21. data/lib/google/cloud/bigtable/cluster/list.rb +22 -20
  22. data/lib/google/cloud/bigtable/column_family.rb +18 -231
  23. data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
  24. data/lib/google/cloud/bigtable/column_range.rb +15 -7
  25. data/lib/google/cloud/bigtable/convert.rb +12 -4
  26. data/lib/google/cloud/bigtable/errors.rb +4 -1
  27. data/lib/google/cloud/bigtable/gc_rule.rb +188 -69
  28. data/lib/google/cloud/bigtable/instance.rb +209 -189
  29. data/lib/google/cloud/bigtable/instance/cluster_map.rb +17 -13
  30. data/lib/google/cloud/bigtable/instance/job.rb +6 -5
  31. data/lib/google/cloud/bigtable/instance/list.rb +18 -13
  32. data/lib/google/cloud/bigtable/longrunning_job.rb +7 -1
  33. data/lib/google/cloud/bigtable/mutation_entry.rb +36 -39
  34. data/lib/google/cloud/bigtable/mutation_operations.rb +90 -73
  35. data/lib/google/cloud/bigtable/policy.rb +9 -5
  36. data/lib/google/cloud/bigtable/project.rb +87 -196
  37. data/lib/google/cloud/bigtable/read_modify_write_rule.rb +15 -10
  38. data/lib/google/cloud/bigtable/read_operations.rb +42 -59
  39. data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
  40. data/lib/google/cloud/bigtable/row.rb +32 -21
  41. data/lib/google/cloud/bigtable/row_filter.rb +80 -35
  42. data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +119 -68
  43. data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +8 -2
  44. data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +117 -66
  45. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +24 -9
  46. data/lib/google/cloud/bigtable/row_range.rb +5 -0
  47. data/lib/google/cloud/bigtable/rows_mutator.rb +14 -21
  48. data/lib/google/cloud/bigtable/rows_reader.rb +23 -18
  49. data/lib/google/cloud/bigtable/sample_row_key.rb +6 -3
  50. data/lib/google/cloud/bigtable/service.rb +200 -253
  51. data/lib/google/cloud/bigtable/status.rb +76 -0
  52. data/lib/google/cloud/bigtable/table.rb +158 -262
  53. data/lib/google/cloud/bigtable/table/cluster_state.rb +17 -6
  54. data/lib/google/cloud/bigtable/table/list.rb +16 -9
  55. data/lib/google/cloud/bigtable/v2.rb +1 -1
  56. data/lib/google/cloud/bigtable/v2/bigtable_client.rb +12 -12
  57. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +16 -13
  58. data/lib/google/cloud/bigtable/value_range.rb +19 -13
  59. data/lib/google/cloud/bigtable/version.rb +1 -1
  60. metadata +67 -25
  61. data/lib/google/cloud/bigtable/table/column_family_map.rb +0 -70
@@ -20,14 +20,16 @@ require "google/cloud/bigtable/instance/list"
20
20
  require "google/cloud/bigtable/instance/cluster_map"
21
21
  require "google/cloud/bigtable/app_profile"
22
22
  require "google/cloud/bigtable/policy"
23
+ require "google/cloud/bigtable/routing_policy"
23
24
 
24
25
  module Google
25
26
  module Cloud
26
27
  module Bigtable
28
+ ##
27
29
  # # Instance
28
30
  #
29
31
  # Represents a Bigtable instance. Instances are dedicated Bigtable
30
- # storage resources that Bigtable tables.
32
+ # storage resources that contain Bigtable tables.
31
33
  #
32
34
  # See {Google::Cloud::Bigtable::Project#instances},
33
35
  # {Google::Cloud::Bigtable::Project#instance}, and
@@ -40,11 +42,11 @@ module Google
40
42
  #
41
43
  # job = bigtable.create_instance(
42
44
  # "my-instance",
43
- # "Instance for user data",
45
+ # display_name: "Instance for user data",
44
46
  # type: :DEVELOPMENT,
45
47
  # labels: { "env" => "dev"}
46
48
  # ) do |clusters|
47
- # clusters.add("test-cluster", "us-east1-b", nodes: 1)
49
+ # clusters.add("test-cluster", "us-east1-b") # nodes not allowed
48
50
  # end
49
51
  #
50
52
  # job.done? #=> false
@@ -72,124 +74,148 @@ module Google
72
74
  @service = service
73
75
  end
74
76
 
75
- # The unique identifier for the project.
77
+ ##
78
+ # The unique identifier for the project to which the instance belongs.
76
79
  #
77
80
  # @return [String]
78
-
81
+ #
79
82
  def project_id
80
83
  @grpc.name.split("/")[1]
81
84
  end
82
85
 
86
+ ##
83
87
  # The unique identifier for the instance.
84
88
  #
85
89
  # @return [String]
86
-
90
+ #
87
91
  def instance_id
88
92
  @grpc.name.split("/")[3]
89
93
  end
90
94
 
91
- # The descriptive name for this instance as it appears in UIs. Must be
95
+ ##
96
+ # The descriptive name for the instance as it appears in UIs. Must be
92
97
  # unique per project and between 4 and 30 characters long.
93
98
  #
94
99
  # @return [String]
95
-
100
+ #
96
101
  def display_name
97
102
  @grpc.display_name
98
103
  end
99
104
 
100
- # Updates the descriptive name for this instance as it appears in UIs.
105
+ ##
106
+ # Updates the descriptive name for the instance as it appears in UIs.
101
107
  # Can be changed at any time, but should be kept globally unique
102
108
  # to avoid confusion.
103
109
  #
104
- # @param value [String] The descriptive name for this instance.
105
-
110
+ # @param value [String] The descriptive name for the instance.
111
+ #
106
112
  def display_name= value
107
113
  @grpc.display_name = value
108
114
  end
109
115
 
116
+ ##
110
117
  # The full path for the instance resource. Values are of the form
111
118
  # `projects/<project_id>/instances/<instance_id>`.
112
119
  #
113
120
  # @return [String]
114
-
121
+ #
115
122
  def path
116
123
  @grpc.name
117
124
  end
118
125
 
126
+ ##
119
127
  # The current instance state. Possible values are `:CREATING`,
120
128
  # `:READY`, `:STATE_NOT_KNOWN`.
121
129
  #
122
130
  # @return [Symbol]
123
-
131
+ #
124
132
  def state
125
133
  @grpc.state
126
134
  end
127
135
 
136
+ ##
128
137
  # The instance has been successfully created and can serve requests
129
138
  # to its tables.
130
139
  #
131
140
  # @return [Boolean]
132
-
141
+ #
133
142
  def ready?
134
143
  state == :READY
135
144
  end
136
145
 
146
+ ##
137
147
  # The instance is currently being created and may be destroyed if the
138
148
  # creation process encounters an error.
139
149
  #
140
150
  # @return [Boolean]
141
-
151
+ #
142
152
  def creating?
143
153
  state == :CREATING
144
154
  end
145
155
 
146
- # Instance type. Possible values are `:DEVELOPMENT`, `:PRODUCTION`,
147
- # `:TYPE_UNSPECIFIED`
156
+ ##
157
+ # Instance type. Possible values include `:DEVELOPMENT` and `:PRODUCTION`.
148
158
  #
149
159
  # @return [Symbol]
150
-
160
+ #
151
161
  def type
152
162
  @grpc.type
153
163
  end
154
164
 
165
+ ##
155
166
  # The instance is meant for development and testing purposes only; it has
156
167
  # no performance or uptime guarantees and is not covered by SLA.
157
168
  # After a development instance is created, it can be upgraded by
158
- # updating the instance to type `PRODUCTION`. An instance created
169
+ # updating the instance to type `:PRODUCTION`. An instance created
159
170
  # as a production instance cannot be changed to a development instance.
160
- # When creating a development instance, `serve_nodes` on the cluster must
161
- # not be set.
171
+ # When creating a development instance, `nodes` on the cluster must
172
+ # not be set. (See {#create_cluster}.)
162
173
  #
163
174
  # @return [Boolean]
164
-
175
+ #
165
176
  def development?
166
177
  type == :DEVELOPMENT
167
178
  end
168
179
 
169
- # An instance meant for production use. `serve_nodes` must be set
170
- # on the cluster.
180
+ ##
181
+ # An instance meant for production use. Requires that `nodes` must be set
182
+ # on the cluster. (See {#create_cluster}.)
171
183
  #
172
184
  # @return [Boolean]
173
-
185
+ #
174
186
  def production?
175
187
  type == :PRODUCTION
176
188
  end
177
189
 
178
- # Set instance type.
190
+ ##
191
+ # Sets the instance type.
179
192
  #
180
- # Valid values are `:DEVELOPMENT`, `:PRODUCTION`.
193
+ # Valid values are `:DEVELOPMENT` and `:PRODUCTION`.
181
194
  # After a development instance is created, it can be upgraded
182
- # by updating the instance to type `PRODUCTION`.
195
+ # by updating the instance to type `:PRODUCTION`.
183
196
  # An instance created as a production instance cannot be changed to a
184
197
  # development instance.
185
198
  #
186
199
  # @param instance_type [Symbol]
187
-
200
+ #
201
+ # @example
202
+ # require "google/cloud/bigtable"
203
+ #
204
+ # bigtable = Google::Cloud::Bigtable.new
205
+ #
206
+ # instance = bigtable.instance("my-instance")
207
+ #
208
+ # instance.development? # true
209
+ # instance.type = :PRODUCTION
210
+ # instance.development? # false
211
+ # instance.production? # true
212
+ #
188
213
  def type= instance_type
189
214
  @grpc.type = instance_type
190
215
  end
191
216
 
192
- # Get instance labels.
217
+ ##
218
+ # Gets the Cloud Labels for the instance.
193
219
  #
194
220
  # Cloud Labels are a flexible and lightweight mechanism for organizing
195
221
  # cloud resources into groups that reflect a customer's organizational
@@ -205,15 +231,16 @@ module Google
205
231
  # * No more than 64 labels can be associated with a given resource.
206
232
  #
207
233
  # @return [Hash{String=>String}] The label keys and values in a hash.
208
-
234
+ #
209
235
  def labels
210
236
  @grpc.labels
211
237
  end
212
238
 
213
- # Set the Cloud Labels.
239
+ ##
240
+ # Sets the Cloud Labels for the instance.
214
241
  #
215
242
  # @param labels [Hash{String=>String}] The Cloud Labels.
216
-
243
+ #
217
244
  def labels= labels
218
245
  labels ||= {}
219
246
  @grpc.labels = Google::Protobuf::Map.new(
@@ -222,10 +249,11 @@ module Google
222
249
  )
223
250
  end
224
251
 
225
- # Update instance.
252
+ ##
253
+ # Updates the instance.
226
254
  #
227
- # Updatable attributes are :
228
- # * `display_name` - The descriptive name for this instance.
255
+ # Updatable attributes are:
256
+ # * `display_name` - The descriptive name for the instance.
229
257
  # * `type` - `:DEVELOPMENT` type instance can be upgraded to `:PRODUCTION` instance.
230
258
  # An instance created as a production instance cannot be changed to a development instance.
231
259
  # * `labels` - Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources.
@@ -233,6 +261,7 @@ module Google
233
261
  # @return [Google::Cloud::Bigtable::Instance::Job]
234
262
  # The job representing the long-running, asynchronous processing of
235
263
  # an instance update operation.
264
+ #
236
265
  # @example
237
266
  # require "google/cloud/bigtable"
238
267
  #
@@ -256,27 +285,27 @@ module Google
256
285
  # puts instance.name
257
286
  # puts instance.labels
258
287
  # end
259
-
288
+ #
260
289
  def save
261
290
  ensure_service!
262
- update_mask = Google::Protobuf::FieldMask.new(
263
- paths: %w[labels display_name type]
264
- )
265
- grpc = service.partial_update_instance(@grpc, update_mask)
266
- Instance::Job.from_grpc(grpc, service)
291
+ update_mask = Google::Protobuf::FieldMask.new paths: ["labels", "display_name", "type"]
292
+ grpc = service.partial_update_instance @grpc, update_mask
293
+ Instance::Job.from_grpc grpc, service
267
294
  end
268
295
  alias update save
269
296
 
270
- # Reload instance information.
297
+ ##
298
+ # Reloads instance data.
271
299
  #
272
300
  # @return [Google::Cloud::Bigtable::Instance]
273
-
301
+ #
274
302
  def reload!
275
- @grpc = service.get_instance(instance_id)
303
+ @grpc = service.get_instance instance_id
276
304
  self
277
305
  end
278
306
 
279
- # Permanently deletes the instance from a project.
307
+ ##
308
+ # Permanently deletes the instance from the project.
280
309
  #
281
310
  # @return [Boolean] Returns `true` if the instance was deleted.
282
311
  #
@@ -287,23 +316,24 @@ module Google
287
316
  #
288
317
  # instance = bigtable.instance("my-instance")
289
318
  # instance.delete
290
-
319
+ #
291
320
  def delete
292
321
  ensure_service!
293
- service.delete_instance(instance_id)
322
+ service.delete_instance instance_id
294
323
  true
295
324
  end
296
325
 
297
- # Lists information about clusters in an instance.
326
+ ##
327
+ # Lists the clusters in the instance.
298
328
  #
299
- # See to delete {Google::Cloud::Bigtable::Cluster#delete} and update
300
- # cluster {Google::Cloud::Bigtable::Cluster#save}.
329
+ # See {Google::Cloud::Bigtable::Cluster#delete} and
330
+ # {Google::Cloud::Bigtable::Cluster#save}.
301
331
  #
302
332
  # @param token [String] The `token` value returned by the last call to
303
333
  # `clusters`; indicates that this is a continuation of a call
304
334
  # and that the system should return the next page of data.
305
335
  # @return [Array<Google::Cloud::Bigtable::Cluster>]
306
- # See({Google::Cloud::Bigtable::Cluster::List})
336
+ # See({Google::Cloud::Bigtable::Cluster::List})
307
337
  #
308
338
  # @example
309
339
  # require "google/cloud/bigtable"
@@ -315,17 +345,18 @@ module Google
315
345
  # instance.clusters.all do |cluster|
316
346
  # puts cluster.cluster_id
317
347
  # end
318
-
348
+ #
319
349
  def clusters token: nil
320
350
  ensure_service!
321
- grpc = service.list_clusters(instance_id, token: token)
322
- Cluster::List.from_grpc(grpc, service, instance_id: instance_id)
351
+ grpc = service.list_clusters instance_id, token: token
352
+ Cluster::List.from_grpc grpc, service, instance_id: instance_id
323
353
  end
324
354
 
325
- # Gets cluster information.
355
+ ##
356
+ # Gets a cluster in the instance.
326
357
  #
327
- # See to delete {Google::Cloud::Bigtable::Cluster#delete} and update
328
- # cluster {Google::Cloud::Bigtable::Cluster#save}.
358
+ # See {Google::Cloud::Bigtable::Cluster#delete} and
359
+ # {Google::Cloud::Bigtable::Cluster#save}.
329
360
  #
330
361
  # @param cluster_id [String] The unique ID of the requested cluster.
331
362
  # @return [Google::Cloud::Bigtable::Cluster, nil]
@@ -339,20 +370,20 @@ module Google
339
370
  #
340
371
  # cluster = instance.cluster("my-instance-cluster")
341
372
  # puts cluster.cluster_id
342
-
373
+ #
343
374
  def cluster cluster_id
344
375
  ensure_service!
345
- grpc = service.get_cluster(instance_id, cluster_id)
346
- Cluster.from_grpc(grpc, service)
376
+ grpc = service.get_cluster instance_id, cluster_id
377
+ Cluster.from_grpc grpc, service
347
378
  rescue Google::Cloud::NotFoundError
348
379
  nil
349
380
  end
350
381
 
351
- # Creates a cluster within an instance.
382
+ ##
383
+ # Creates a cluster in the instance.
352
384
  #
353
385
  # @param cluster_id [String]
354
- # The ID to be used when referring to the new cluster within its instance,
355
- # e.g., just `mycluster`
386
+ # The ID to be used when referring to the new cluster within its instance.
356
387
  # @param location [String]
357
388
  # The location where this cluster's nodes and storage reside. For best
358
389
  # performance, clients should be located as close as possible to this
@@ -391,24 +422,25 @@ module Google
391
422
  # else
392
423
  # cluster = job.cluster
393
424
  # end
394
-
425
+ #
395
426
  def create_cluster cluster_id, location, nodes: nil, storage_type: nil
396
427
  ensure_service!
397
428
  attrs = {
398
- serve_nodes: nodes,
429
+ serve_nodes: nodes,
399
430
  default_storage_type: storage_type,
400
- location: location
431
+ location: location
401
432
  }.delete_if { |_, v| v.nil? }
402
433
 
403
- cluster = Google::Bigtable::Admin::V2::Cluster.new(attrs)
404
- grpc = service.create_cluster(instance_id, cluster_id, cluster)
405
- Cluster::Job.from_grpc(grpc, service)
434
+ cluster = Google::Bigtable::Admin::V2::Cluster.new attrs
435
+ grpc = service.create_cluster instance_id, cluster_id, cluster
436
+ Cluster::Job.from_grpc grpc, service
406
437
  end
407
438
 
408
- # List all tables.
439
+ ##
440
+ # Lists all tables in the instance.
409
441
  #
410
- # See to delete table {Google::Cloud::Bigtable::Table#delete} and update
411
- # table {Google::Cloud::Bigtable::Table#save}.
442
+ # See {Google::Cloud::Bigtable::Table#delete} and
443
+ # {Google::Cloud::Bigtable::Table#save}.
412
444
  #
413
445
  # @return [Array<Google::Cloud::Bigtable::Table>]
414
446
  # (See {Google::Cloud::Bigtable::Table::List})
@@ -425,22 +457,17 @@ module Google
425
457
  # puts table.name
426
458
  # end
427
459
  #
428
- # # Full view
429
- # instance.tables(view: :FULL).all do |table|
430
- # puts table.name
431
- # puts table.column_families
432
- # end
433
- #
434
460
  def tables
435
461
  ensure_service!
436
- grpc = service.list_tables(instance_id)
437
- Table::List.from_grpc(grpc, service)
462
+ grpc = service.list_tables instance_id
463
+ Table::List.from_grpc grpc, service
438
464
  end
439
465
 
440
- # Get metadata information of table.
466
+ ##
467
+ # Gets metadata information of a table in the instance.
441
468
  #
442
469
  # @param view [Symbol]
443
- # The view to be applied to the returned tables' fields
470
+ # The view to be applied to the returned tables' fields.
444
471
  # Defaults to `SCHEMA_VIEW` if unspecified.
445
472
  # Valid view types are.
446
473
  # * `:NAME_ONLY` - Only populates `name`
@@ -465,7 +492,6 @@ module Google
465
492
  #
466
493
  # instance = bigtable.instance("my-instance")
467
494
  #
468
- # # Default view is full view
469
495
  # table = instance.table("my-table", perform_lookup: true)
470
496
  # puts table.name
471
497
  # puts table.column_families
@@ -474,7 +500,7 @@ module Google
474
500
  # table = instance.table("my-table", view: :NAME_ONLY, perform_lookup: true)
475
501
  # puts table.name
476
502
  #
477
- # @example Mutate rows
503
+ # @example Mutate rows.
478
504
  # require "google/cloud/bigtable"
479
505
  #
480
506
  # bigtable = Google::Cloud::Bigtable.new
@@ -495,13 +521,10 @@ module Google
495
521
  ensure_service!
496
522
 
497
523
  table = if perform_lookup
498
- grpc = service.get_table(instance_id, table_id, view: view)
499
- Table.from_grpc(grpc, service, view: view)
524
+ grpc = service.get_table instance_id, table_id, view: view
525
+ Table.from_grpc grpc, service, view: view
500
526
  else
501
- Table.from_path(
502
- service.table_path(instance_id, table_id),
503
- service
504
- )
527
+ Table.from_path service.table_path(instance_id, table_id), service
505
528
  end
506
529
 
507
530
  table.app_profile_id = app_profile_id
@@ -510,17 +533,18 @@ module Google
510
533
  nil
511
534
  end
512
535
 
513
- # Create table
536
+ ##
537
+ # Creates a new table in the instance.
514
538
  #
515
539
  # The table can be created with a full set of initial column families,
516
540
  # specified in the request.
517
541
  #
518
542
  # @param name [String]
519
543
  # The name by which the new table should be referred to within the parent
520
- # instance, e.g., `foobar`
521
- # @param column_families [Hash{String => Google::Cloud::Bigtable::ColumnFamily}]
522
- # (See {Google::Cloud::Bigtable::Table::ColumnFamilyMap})
523
- # If passed as an empty, use a code block to add column families.
544
+ # instance.
545
+ # @param column_families [Google::Cloud::Bigtable::ColumnFamilyMap]
546
+ # An object containing the column families for the table, mapped by
547
+ # column family name.
524
548
  # @param granularity [Symbol]
525
549
  # The granularity at which timestamps are stored in this table.
526
550
  # Timestamps not matching the granularity will be rejected.
@@ -544,15 +568,14 @@ module Google
544
568
  # * Tablet 5 : `[other, ) => {"other", "zz"}`
545
569
  # A hash in the form of `Google::Bigtable::Admin::V2::CreateTableRequest::Split`
546
570
  # can also be provided.
547
- # @yield [column_families] A block for adding column_families.
548
- # @yieldparam [Hash{String => Google::Cloud::Bigtable::ColumnFamily}]
549
- # Cluster map of cluster name and cluster object.
550
- # (See {Google::Cloud::Bigtable::Instance::ClusterMap})
551
- # See rules for column families at {Google::Cloud::Bigtable::GcRule})
571
+ # @yield [column_families] A block for adding column families.
572
+ # @yieldparam [Google::Cloud::Bigtable::ColumnFamilyMap] column_families
573
+ # A mutable object containing the column families for the table,
574
+ # mapped by column family name.
552
575
  #
553
576
  # @return [Google::Cloud::Bigtable::Table]
554
577
  #
555
- # @example Create table without column families.
578
+ # @example Create a table without column families.
556
579
  # require "google/cloud/bigtable"
557
580
  #
558
581
  # bigtable = Google::Cloud::Bigtable.new
@@ -562,64 +585,62 @@ module Google
562
585
  # table = instance.create_table("my-table")
563
586
  # puts table.name
564
587
  #
565
- # @example Create table with column families and initial splits.
588
+ # @example Create a table with initial splits and column families.
566
589
  # require "google/cloud/bigtable"
567
590
  #
568
591
  # bigtable = Google::Cloud::Bigtable.new
569
592
  #
570
593
  # instance = bigtable.instance("my-instance")
571
594
  #
572
- # table = instance.create_table(my-table") do |column_families|
573
- # column_families.add('cf1', Google::Cloud::Bigtable::GcRule.max_versions(3))
574
- # column_families.add('cf2', Google::Cloud::Bigtable::GcRule.max_age(100))
595
+ # initial_splits = ["user-00001", "user-100000", "others"]
596
+ # table = instance.create_table("my-table", initial_splits: initial_splits) do |cfm|
597
+ # cfm.add('cf1', gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
598
+ # cfm.add('cf2', gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
575
599
  #
576
- # gc_rule = Google::Cloud::Bigtable::GcRule.new
577
- # gc_rule.union = [
578
- # Google::Cloud::Bigtable::GcRule.max_versions(3),
600
+ # gc_rule = Google::Cloud::Bigtable::GcRule.union(
579
601
  # Google::Cloud::Bigtable::GcRule.max_age(1800),
580
- # ]
581
- # column_families.add('cf3', gc_rule)
602
+ # Google::Cloud::Bigtable::GcRule.max_versions(3)
603
+ # )
604
+ # cfm.add('cf3', gc_rule: gc_rule)
582
605
  # end
583
606
  #
584
607
  # puts table
585
-
586
- def create_table \
587
- name,
588
- column_families: nil,
589
- granularity: nil,
590
- initial_splits: nil,
591
- &block
608
+ #
609
+ def create_table name, column_families: nil, granularity: nil, initial_splits: nil, &block
592
610
  ensure_service!
593
611
  Table.create(
594
612
  service,
595
613
  instance_id,
596
614
  name,
597
615
  column_families: column_families,
598
- granularity: granularity,
599
- initial_splits: initial_splits,
616
+ granularity: granularity,
617
+ initial_splits: initial_splits,
600
618
  &block
601
619
  )
602
620
  end
603
621
 
604
- # Create app profile for an instance with a routing policy.
605
- # Only one routing policy can applied to app profile. The policy can be
622
+ ##
623
+ # Creates an app profile for the instance with a routing policy.
624
+ # Only one routing policy can applied to the app profile. The policy can be
606
625
  # multi-cluster routing or single cluster routing.
607
626
  #
608
- # @param name [String] Unique Id of the app profile
609
- # @param routing_policy [Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting | Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny]
610
- # The routing policy for all read/write requests that use this app profile.
611
- # A value must be explicitly set.
627
+ # @param name [String] Unique ID of the app profile.
628
+ # @param routing_policy [Google::Cloud::Bigtable::RoutingPolicy]
629
+ # The routing policy for all read/write requests that use this app
630
+ # profile. A value must be explicitly set.
612
631
  #
613
632
  # Routing Policies:
614
- # * `multi_cluster_routing` - Read/write requests may be routed to any
615
- # cluster in the instance and will fail over to another cluster in the event
616
- # of transient errors or delays. Choosing this option sacrifices
617
- # read-your-writes consistency to improve availability.
618
- # * `single_cluster_routing` - Unconditionally routes all read/write requests
619
- # to a specific cluster. This option preserves read-your-writes consistency
620
- # but does not improve availability.
621
- # Value contains `cluster_id` and optional field `allow_transactional_writes`.
622
- # @param description [String] Description of the use case for this app profile
633
+ # * {Google::Cloud::Bigtable::MultiClusterRoutingUseAny} - Read/write
634
+ # requests may be routed to any cluster in the instance and will
635
+ # fail over to another cluster in the event of transient errors or
636
+ # delays. Choosing this option sacrifices read-your-writes
637
+ # consistency to improve availability.
638
+ # * {Google::Cloud::Bigtable::SingleClusterRouting} - Unconditionally
639
+ # routes all read/write requests to a specific cluster. This option
640
+ # preserves read-your-writes consistency but does not improve
641
+ # availability. Value contains `cluster_id` and optional field
642
+ # `allow_transactional_writes`.
643
+ # @param description [String] Description of the use case for this app profile.
623
644
  # @param etag [String]
624
645
  # Strongly validated etag for optimistic concurrency control. Preserve the
625
646
  # value returned from `GetAppProfile` when calling `UpdateAppProfile` to
@@ -630,10 +651,10 @@ module Google
630
651
  # [RFC 7232](https://tools.ietf.org/html/rfc7232#section-2.3) for more details.
631
652
  # @param ignore_warnings [Boolean]
632
653
  # If true, ignore safety checks when creating the app profile.
633
- # Default value is `false`
654
+ # Default value is `false`.
634
655
  # @return [Google::Cloud::Bigtable::AppProfile]
635
656
  #
636
- # @example Create an app profile with a single cluster routing policy
657
+ # @example Create an app profile with a single cluster routing policy.
637
658
  # require "google/cloud/bigtable"
638
659
  #
639
660
  # bigtable = Google::Cloud::Bigtable.new
@@ -641,18 +662,18 @@ module Google
641
662
  # instance = bigtable.instance("my-instance")
642
663
  #
643
664
  # routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
644
- # "my-instance-cluster-1"
665
+ # "my-instance-cluster-1",
645
666
  # allow_transactional_writes: true
646
667
  # )
647
668
  #
648
669
  # app_profile = instance.create_app_profile(
649
670
  # "my-app-profile",
650
- # routing_policy: routing_policy,
671
+ # routing_policy,
651
672
  # description: "App profile for user data instance"
652
673
  # )
653
674
  # puts app_profile.name
654
675
  #
655
- # @example Create an app profile with multi-cluster routing policy
676
+ # @example Create an app profile with multi-cluster routing policy.
656
677
  # require "google/cloud/bigtable"
657
678
  #
658
679
  # bigtable = Google::Cloud::Bigtable.new
@@ -684,27 +705,21 @@ module Google
684
705
  # ignore_warnings: true
685
706
  # )
686
707
  # puts app_profile.name
687
-
688
- def create_app_profile \
689
- name,
690
- routing_policy,
691
- description: nil,
692
- etag: nil,
693
- ignore_warnings: false
708
+ #
709
+ def create_app_profile name, routing_policy, description: nil, etag: nil, ignore_warnings: false
694
710
  ensure_service!
695
-
696
- if routing_policy.is_a?(Google::Bigtable::Admin::V2::AppProfile:: \
697
- MultiClusterRoutingUseAny)
698
- multi_cluster_routing = routing_policy
711
+ routing_policy_grpc = routing_policy.to_grpc
712
+ if routing_policy_grpc.is_a? Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny
713
+ multi_cluster_routing = routing_policy_grpc
699
714
  else
700
- single_cluster_routing = routing_policy
715
+ single_cluster_routing = routing_policy_grpc
701
716
  end
702
717
 
703
718
  app_profile_attrs = {
704
719
  multi_cluster_routing_use_any: multi_cluster_routing,
705
- single_cluster_routing: single_cluster_routing,
706
- description: description,
707
- etag: etag
720
+ single_cluster_routing: single_cluster_routing,
721
+ description: description,
722
+ etag: etag
708
723
  }.delete_if { |_, v| v.nil? }
709
724
 
710
725
  grpc = service.create_app_profile(
@@ -713,13 +728,14 @@ module Google
713
728
  Google::Bigtable::Admin::V2::AppProfile.new(app_profile_attrs),
714
729
  ignore_warnings: ignore_warnings
715
730
  )
716
- AppProfile.from_grpc(grpc, service)
731
+ AppProfile.from_grpc grpc, service
717
732
  end
718
733
 
719
- # Get app profile.
734
+ ##
735
+ # Gets an app profile in the instance.
720
736
  #
721
- # See to delete app_profile {Google::Cloud::Bigtable::AppProfile#delete} and update
722
- # app_profile {Google::Cloud::Bigtable::AppProfile#save}.
737
+ # See {Google::Cloud::Bigtable::AppProfile#delete} and
738
+ # {Google::Cloud::Bigtable::AppProfile#save}.
723
739
  #
724
740
  # @param app_profile_id [String] The unique name of the requested app profile.
725
741
  # @return [Google::Cloud::Bigtable::AppProfile, nil]
@@ -736,22 +752,23 @@ module Google
736
752
  # if app_profile
737
753
  # puts app_profile.name
738
754
  # end
739
-
755
+ #
740
756
  def app_profile app_profile_id
741
757
  ensure_service!
742
- grpc = service.get_app_profile(instance_id, app_profile_id)
743
- AppProfile.from_grpc(grpc, service)
758
+ grpc = service.get_app_profile instance_id, app_profile_id
759
+ AppProfile.from_grpc grpc, service
744
760
  rescue Google::Cloud::NotFoundError
745
761
  nil
746
762
  end
747
763
 
748
- # List all app profiles
764
+ ##
765
+ # Lists all app profiles in the instance.
749
766
  #
750
- # See to delete app_profile {Google::Cloud::Bigtable::AppProfile#delete} and update
751
- # app_profile {Google::Cloud::Bigtable::AppProfile#save}.
767
+ # See {Google::Cloud::Bigtable::AppProfile#delete} and
768
+ # {Google::Cloud::Bigtable::AppProfile#save}.
752
769
  #
753
770
  # @return [Array<Google::Cloud::Bigtable::AppProfile>]
754
- # (See {Google::Cloud::Bigtable::AppProfile::List})
771
+ # (See {Google::Cloud::Bigtable::AppProfile::List})
755
772
  #
756
773
  # @example
757
774
  # require "google/cloud/bigtable"
@@ -763,15 +780,16 @@ module Google
763
780
  # instance.app_profiles.all do |app_profile|
764
781
  # puts app_profile.name
765
782
  # end
766
-
783
+ #
767
784
  def app_profiles
768
785
  ensure_service!
769
- grpc = service.list_app_profiles(instance_id)
770
- AppProfile::List.from_grpc(grpc, service)
786
+ grpc = service.list_app_profiles instance_id
787
+ AppProfile::List.from_grpc grpc, service
771
788
  end
772
789
 
790
+ ##
773
791
  # Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
774
- # policy for this instance.
792
+ # policy for the instance.
775
793
  #
776
794
  # @see https://cloud.google.com/bigtable/docs/access-control
777
795
  #
@@ -780,9 +798,9 @@ module Google
780
798
  # the block completes, the modified policy will be written to the
781
799
  # service.
782
800
  # @yieldparam [Policy] policy the current Cloud IAM Policy for this
783
- # instance
801
+ # instance.
784
802
  #
785
- # @return [Policy] The current Cloud IAM Policy for this instance.
803
+ # @return [Policy] The current Cloud IAM Policy for the instance.
786
804
  #
787
805
  # @example
788
806
  # require "google/cloud/bigtable"
@@ -792,8 +810,8 @@ module Google
792
810
  # instance = bigtable.instance("my-instance")
793
811
  # policy = instance.policy
794
812
  #
795
- # @example Update the policy by passing a block:
796
- # require "google/cloud/spanner"
813
+ # @example Update the policy by passing a block.
814
+ # require "google/cloud/bigtable"
797
815
  #
798
816
  # bigtable = Google::Cloud::Bigtable.new
799
817
  # instance = bigtable.instance("my-instance")
@@ -801,18 +819,19 @@ module Google
801
819
  # instance.policy do |p|
802
820
  # p.add("roles/owner", "user:owner@example.com")
803
821
  # end # 2 API calls
804
-
822
+ #
805
823
  def policy
806
824
  ensure_service!
807
- grpc = service.get_instance_policy(instance_id)
808
- policy = Policy.from_grpc(grpc)
825
+ grpc = service.get_instance_policy instance_id
826
+ policy = Policy.from_grpc grpc
809
827
  return policy unless block_given?
810
828
  yield policy
811
829
  update_policy policy
812
830
  end
813
831
 
832
+ ##
814
833
  # Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
815
- # policy for this instance. The policy should be read from {#policy}.
834
+ # policy for the instance. The policy should be read from {#policy}.
816
835
  # See {Google::Cloud::Bigtable::Policy} for an explanation of the policy
817
836
  # `etag` property and how to modify policies.
818
837
  #
@@ -836,24 +855,25 @@ module Google
836
855
  # updated_policy = instance.update_policy(policy)
837
856
  #
838
857
  # puts update_policy.roles
839
-
858
+ #
840
859
  def update_policy new_policy
841
860
  ensure_service!
842
- grpc = service.set_instance_policy(instance_id, new_policy.to_grpc)
843
- Policy.from_grpc(grpc)
861
+ grpc = service.set_instance_policy instance_id, new_policy.to_grpc
862
+ Policy.from_grpc grpc
844
863
  end
845
864
  alias policy= update_policy
846
865
 
866
+ ##
847
867
  # Tests the specified permissions against the [Cloud
848
868
  # IAM](https://cloud.google.com/iam/) access control policy.
849
869
  #
850
- # @see https://cloud.google.com/iam/docs/managing-policies Managing
851
- # Policies
870
+ # @see https://cloud.google.com/iam/docs/managing-policies Managing Policies
871
+ # @see https://cloud.google.com/bigtable/docs/access-control Access Control
852
872
  #
853
873
  # @param permissions [String, Array<String>] permissions The set of permissions to
854
874
  # check access for. Permissions with wildcards (such as `*` or
855
875
  # `bigtable.*`) are not allowed.
856
- # See (https://cloud.google.com/bigtable/docs/access-control)
876
+ # See [Access Control](https://cloud.google.com/bigtable/docs/access-control).
857
877
  #
858
878
  # Some of the permissions that can be checked on a instance are:
859
879
  # * bigtable.instances.create
@@ -873,13 +893,13 @@ module Google
873
893
  #
874
894
  # instance = bigtable.instance("my-instance")
875
895
  #
876
- # permissions = bigtable.test_permissions(
896
+ # permissions = instance.test_iam_permissions(
877
897
  # "bigtable.instances.get",
878
898
  # "bigtable.instances.update"
879
899
  # )
880
900
  # permissions.include? "bigtable.instances.get" #=> true
881
901
  # permissions.include? "bigtable.instances.update" #=> false
882
-
902
+ #
883
903
  def test_iam_permissions *permissions
884
904
  ensure_service!
885
905
  grpc = service.test_instance_permissions(
@@ -897,9 +917,9 @@ module Google
897
917
  # @param grpc [Google::Bigtable::Admin::V2::Instance]
898
918
  # @param service [Google::Cloud::Bigtable::Service]
899
919
  # @return [Google::Cloud::Bigtable::Instance]
900
-
920
+ #
901
921
  def self.from_grpc grpc, service
902
- new(grpc, service)
922
+ new grpc, service
903
923
  end
904
924
 
905
925
  protected
@@ -908,7 +928,7 @@ module Google
908
928
  #
909
929
  # Raise an error unless an active connection to the service is
910
930
  # available.
911
-
931
+ #
912
932
  def ensure_service!
913
933
  raise "Must have active connection to service" unless service
914
934
  end