google-cloud-bigtable 0.6.2 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/CONTRIBUTING.md +1 -1
- data/lib/google-cloud-bigtable.rb +19 -21
- data/lib/google/cloud/bigtable.rb +11 -17
- data/lib/google/cloud/bigtable/app_profile.rb +148 -82
- data/lib/google/cloud/bigtable/app_profile/job.rb +5 -8
- data/lib/google/cloud/bigtable/app_profile/list.rb +11 -5
- data/lib/google/cloud/bigtable/chunk_processor.rb +23 -35
- data/lib/google/cloud/bigtable/cluster.rb +38 -11
- data/lib/google/cloud/bigtable/cluster/job.rb +3 -7
- data/lib/google/cloud/bigtable/cluster/list.rb +20 -18
- data/lib/google/cloud/bigtable/column_family.rb +22 -229
- data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
- data/lib/google/cloud/bigtable/column_range.rb +9 -1
- data/lib/google/cloud/bigtable/convert.rb +12 -4
- data/lib/google/cloud/bigtable/errors.rb +4 -1
- data/lib/google/cloud/bigtable/gc_rule.rb +184 -65
- data/lib/google/cloud/bigtable/instance.rb +136 -126
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +9 -7
- data/lib/google/cloud/bigtable/instance/job.rb +4 -3
- data/lib/google/cloud/bigtable/instance/list.rb +14 -9
- data/lib/google/cloud/bigtable/longrunning_job.rb +6 -0
- data/lib/google/cloud/bigtable/mutation_entry.rb +19 -23
- data/lib/google/cloud/bigtable/mutation_operations.rb +82 -29
- data/lib/google/cloud/bigtable/policy.rb +9 -5
- data/lib/google/cloud/bigtable/project.rb +62 -140
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +9 -4
- data/lib/google/cloud/bigtable/read_operations.rb +28 -41
- data/lib/google/cloud/bigtable/routing_policy.rb +171 -0
- data/lib/google/cloud/bigtable/row.rb +18 -7
- data/lib/google/cloud/bigtable/row_filter.rb +49 -20
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +71 -43
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +4 -1
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +74 -43
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +22 -7
- data/lib/google/cloud/bigtable/row_range.rb +5 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +14 -17
- data/lib/google/cloud/bigtable/rows_reader.rb +18 -14
- data/lib/google/cloud/bigtable/sample_row_key.rb +5 -2
- data/lib/google/cloud/bigtable/service.rb +161 -242
- data/lib/google/cloud/bigtable/status.rb +76 -0
- data/lib/google/cloud/bigtable/table.rb +141 -236
- data/lib/google/cloud/bigtable/table/cluster_state.rb +7 -1
- data/lib/google/cloud/bigtable/table/list.rb +14 -7
- data/lib/google/cloud/bigtable/value_range.rb +5 -0
- data/lib/google/cloud/bigtable/version.rb +1 -1
- metadata +27 -25
- data/lib/google/cloud/bigtable/table/column_family_map.rb +0 -70
@@ -20,10 +20,12 @@ 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
|
@@ -40,7 +42,7 @@ 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|
|
@@ -72,86 +74,96 @@ module Google
|
|
72
74
|
@service = service
|
73
75
|
end
|
74
76
|
|
77
|
+
##
|
75
78
|
# The unique identifier for the project.
|
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
|
|
95
|
+
##
|
91
96
|
# The descriptive name for this 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
|
|
105
|
+
##
|
100
106
|
# Updates the descriptive name for this 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
110
|
# @param value [String] The descriptive name for this instance.
|
105
|
-
|
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
|
|
156
|
+
##
|
146
157
|
# Instance type. Possible values are `:DEVELOPMENT`, `:PRODUCTION`,
|
147
158
|
# `:TYPE_UNSPECIFIED`
|
148
159
|
#
|
149
160
|
# @return [Symbol]
|
150
|
-
|
161
|
+
#
|
151
162
|
def type
|
152
163
|
@grpc.type
|
153
164
|
end
|
154
165
|
|
166
|
+
##
|
155
167
|
# The instance is meant for development and testing purposes only; it has
|
156
168
|
# no performance or uptime guarantees and is not covered by SLA.
|
157
169
|
# After a development instance is created, it can be upgraded by
|
@@ -161,20 +173,22 @@ module Google
|
|
161
173
|
# not be set.
|
162
174
|
#
|
163
175
|
# @return [Boolean]
|
164
|
-
|
176
|
+
#
|
165
177
|
def development?
|
166
178
|
type == :DEVELOPMENT
|
167
179
|
end
|
168
180
|
|
181
|
+
##
|
169
182
|
# An instance meant for production use. `serve_nodes` must be set
|
170
183
|
# on the cluster.
|
171
184
|
#
|
172
185
|
# @return [Boolean]
|
173
|
-
|
186
|
+
#
|
174
187
|
def production?
|
175
188
|
type == :PRODUCTION
|
176
189
|
end
|
177
190
|
|
191
|
+
##
|
178
192
|
# Set instance type.
|
179
193
|
#
|
180
194
|
# Valid values are `:DEVELOPMENT`, `:PRODUCTION`.
|
@@ -184,11 +198,12 @@ module Google
|
|
184
198
|
# development instance.
|
185
199
|
#
|
186
200
|
# @param instance_type [Symbol]
|
187
|
-
|
201
|
+
#
|
188
202
|
def type= instance_type
|
189
203
|
@grpc.type = instance_type
|
190
204
|
end
|
191
205
|
|
206
|
+
##
|
192
207
|
# Get instance labels.
|
193
208
|
#
|
194
209
|
# Cloud Labels are a flexible and lightweight mechanism for organizing
|
@@ -205,15 +220,16 @@ module Google
|
|
205
220
|
# * No more than 64 labels can be associated with a given resource.
|
206
221
|
#
|
207
222
|
# @return [Hash{String=>String}] The label keys and values in a hash.
|
208
|
-
|
223
|
+
#
|
209
224
|
def labels
|
210
225
|
@grpc.labels
|
211
226
|
end
|
212
227
|
|
228
|
+
##
|
213
229
|
# Set the Cloud Labels.
|
214
230
|
#
|
215
231
|
# @param labels [Hash{String=>String}] The Cloud Labels.
|
216
|
-
|
232
|
+
#
|
217
233
|
def labels= labels
|
218
234
|
labels ||= {}
|
219
235
|
@grpc.labels = Google::Protobuf::Map.new(
|
@@ -222,6 +238,7 @@ module Google
|
|
222
238
|
)
|
223
239
|
end
|
224
240
|
|
241
|
+
##
|
225
242
|
# Update instance.
|
226
243
|
#
|
227
244
|
# Updatable attributes are :
|
@@ -256,26 +273,26 @@ module Google
|
|
256
273
|
# puts instance.name
|
257
274
|
# puts instance.labels
|
258
275
|
# end
|
259
|
-
|
276
|
+
#
|
260
277
|
def save
|
261
278
|
ensure_service!
|
262
|
-
update_mask = Google::Protobuf::FieldMask.new
|
263
|
-
|
264
|
-
|
265
|
-
grpc = service.partial_update_instance(@grpc, update_mask)
|
266
|
-
Instance::Job.from_grpc(grpc, service)
|
279
|
+
update_mask = Google::Protobuf::FieldMask.new paths: ["labels", "display_name", "type"]
|
280
|
+
grpc = service.partial_update_instance @grpc, update_mask
|
281
|
+
Instance::Job.from_grpc grpc, service
|
267
282
|
end
|
268
283
|
alias update save
|
269
284
|
|
285
|
+
##
|
270
286
|
# Reload instance information.
|
271
287
|
#
|
272
288
|
# @return [Google::Cloud::Bigtable::Instance]
|
273
|
-
|
289
|
+
#
|
274
290
|
def reload!
|
275
|
-
@grpc = service.get_instance
|
291
|
+
@grpc = service.get_instance instance_id
|
276
292
|
self
|
277
293
|
end
|
278
294
|
|
295
|
+
##
|
279
296
|
# Permanently deletes the instance from a project.
|
280
297
|
#
|
281
298
|
# @return [Boolean] Returns `true` if the instance was deleted.
|
@@ -287,13 +304,14 @@ module Google
|
|
287
304
|
#
|
288
305
|
# instance = bigtable.instance("my-instance")
|
289
306
|
# instance.delete
|
290
|
-
|
307
|
+
#
|
291
308
|
def delete
|
292
309
|
ensure_service!
|
293
|
-
service.delete_instance
|
310
|
+
service.delete_instance instance_id
|
294
311
|
true
|
295
312
|
end
|
296
313
|
|
314
|
+
##
|
297
315
|
# Lists information about clusters in an instance.
|
298
316
|
#
|
299
317
|
# See to delete {Google::Cloud::Bigtable::Cluster#delete} and update
|
@@ -315,13 +333,14 @@ module Google
|
|
315
333
|
# instance.clusters.all do |cluster|
|
316
334
|
# puts cluster.cluster_id
|
317
335
|
# end
|
318
|
-
|
336
|
+
#
|
319
337
|
def clusters token: nil
|
320
338
|
ensure_service!
|
321
|
-
grpc = service.list_clusters
|
322
|
-
Cluster::List.from_grpc
|
339
|
+
grpc = service.list_clusters instance_id, token: token
|
340
|
+
Cluster::List.from_grpc grpc, service, instance_id: instance_id
|
323
341
|
end
|
324
342
|
|
343
|
+
##
|
325
344
|
# Gets cluster information.
|
326
345
|
#
|
327
346
|
# See to delete {Google::Cloud::Bigtable::Cluster#delete} and update
|
@@ -339,15 +358,16 @@ module Google
|
|
339
358
|
#
|
340
359
|
# cluster = instance.cluster("my-instance-cluster")
|
341
360
|
# puts cluster.cluster_id
|
342
|
-
|
361
|
+
#
|
343
362
|
def cluster cluster_id
|
344
363
|
ensure_service!
|
345
|
-
grpc = service.get_cluster
|
346
|
-
Cluster.from_grpc
|
364
|
+
grpc = service.get_cluster instance_id, cluster_id
|
365
|
+
Cluster.from_grpc grpc, service
|
347
366
|
rescue Google::Cloud::NotFoundError
|
348
367
|
nil
|
349
368
|
end
|
350
369
|
|
370
|
+
##
|
351
371
|
# Creates a cluster within an instance.
|
352
372
|
#
|
353
373
|
# @param cluster_id [String]
|
@@ -391,20 +411,21 @@ module Google
|
|
391
411
|
# else
|
392
412
|
# cluster = job.cluster
|
393
413
|
# end
|
394
|
-
|
414
|
+
#
|
395
415
|
def create_cluster cluster_id, location, nodes: nil, storage_type: nil
|
396
416
|
ensure_service!
|
397
417
|
attrs = {
|
398
|
-
serve_nodes:
|
418
|
+
serve_nodes: nodes,
|
399
419
|
default_storage_type: storage_type,
|
400
|
-
location:
|
420
|
+
location: location
|
401
421
|
}.delete_if { |_, v| v.nil? }
|
402
422
|
|
403
|
-
cluster = Google::Bigtable::Admin::V2::Cluster.new
|
404
|
-
grpc = service.create_cluster
|
405
|
-
Cluster::Job.from_grpc
|
423
|
+
cluster = Google::Bigtable::Admin::V2::Cluster.new attrs
|
424
|
+
grpc = service.create_cluster instance_id, cluster_id, cluster
|
425
|
+
Cluster::Job.from_grpc grpc, service
|
406
426
|
end
|
407
427
|
|
428
|
+
##
|
408
429
|
# List all tables.
|
409
430
|
#
|
410
431
|
# See to delete table {Google::Cloud::Bigtable::Table#delete} and update
|
@@ -425,18 +446,13 @@ module Google
|
|
425
446
|
# puts table.name
|
426
447
|
# end
|
427
448
|
#
|
428
|
-
# # Full view
|
429
|
-
# instance.tables(view: :FULL).all do |table|
|
430
|
-
# puts table.name
|
431
|
-
# puts table.column_families
|
432
|
-
# end
|
433
|
-
#
|
434
449
|
def tables
|
435
450
|
ensure_service!
|
436
|
-
grpc = service.list_tables
|
437
|
-
Table::List.from_grpc
|
451
|
+
grpc = service.list_tables instance_id
|
452
|
+
Table::List.from_grpc grpc, service
|
438
453
|
end
|
439
454
|
|
455
|
+
##
|
440
456
|
# Get metadata information of table.
|
441
457
|
#
|
442
458
|
# @param view [Symbol]
|
@@ -495,13 +511,10 @@ module Google
|
|
495
511
|
ensure_service!
|
496
512
|
|
497
513
|
table = if perform_lookup
|
498
|
-
grpc = service.get_table
|
499
|
-
Table.from_grpc
|
514
|
+
grpc = service.get_table instance_id, table_id, view: view
|
515
|
+
Table.from_grpc grpc, service, view: view
|
500
516
|
else
|
501
|
-
Table.from_path(
|
502
|
-
service.table_path(instance_id, table_id),
|
503
|
-
service
|
504
|
-
)
|
517
|
+
Table.from_path service.table_path(instance_id, table_id), service
|
505
518
|
end
|
506
519
|
|
507
520
|
table.app_profile_id = app_profile_id
|
@@ -510,7 +523,8 @@ module Google
|
|
510
523
|
nil
|
511
524
|
end
|
512
525
|
|
513
|
-
|
526
|
+
##
|
527
|
+
# Creates a new table.
|
514
528
|
#
|
515
529
|
# The table can be created with a full set of initial column families,
|
516
530
|
# specified in the request.
|
@@ -518,9 +532,9 @@ module Google
|
|
518
532
|
# @param name [String]
|
519
533
|
# The name by which the new table should be referred to within the parent
|
520
534
|
# instance, e.g., `foobar`
|
521
|
-
# @param column_families [
|
522
|
-
#
|
523
|
-
#
|
535
|
+
# @param column_families [Google::Cloud::Bigtable::ColumnFamilyMap]
|
536
|
+
# An object containing the column families for the table, mapped by
|
537
|
+
# column family name.
|
524
538
|
# @param granularity [Symbol]
|
525
539
|
# The granularity at which timestamps are stored in this table.
|
526
540
|
# Timestamps not matching the granularity will be rejected.
|
@@ -544,15 +558,14 @@ module Google
|
|
544
558
|
# * Tablet 5 : `[other, ) => {"other", "zz"}`
|
545
559
|
# A hash in the form of `Google::Bigtable::Admin::V2::CreateTableRequest::Split`
|
546
560
|
# can also be provided.
|
547
|
-
# @yield [column_families] A block for adding
|
548
|
-
# @yieldparam [
|
549
|
-
#
|
550
|
-
#
|
551
|
-
# See rules for column families at {Google::Cloud::Bigtable::GcRule})
|
561
|
+
# @yield [column_families] A block for adding column families.
|
562
|
+
# @yieldparam [Google::Cloud::Bigtable::ColumnFamilyMap] column_families
|
563
|
+
# A mutable object containing the column families for the table,
|
564
|
+
# mapped by column family name.
|
552
565
|
#
|
553
566
|
# @return [Google::Cloud::Bigtable::Table]
|
554
567
|
#
|
555
|
-
# @example Create table without column families.
|
568
|
+
# @example Create a table without column families.
|
556
569
|
# require "google/cloud/bigtable"
|
557
570
|
#
|
558
571
|
# bigtable = Google::Cloud::Bigtable.new
|
@@ -562,63 +575,61 @@ module Google
|
|
562
575
|
# table = instance.create_table("my-table")
|
563
576
|
# puts table.name
|
564
577
|
#
|
565
|
-
# @example Create table with
|
578
|
+
# @example Create a table with initial splits and column families.
|
566
579
|
# require "google/cloud/bigtable"
|
567
580
|
#
|
568
581
|
# bigtable = Google::Cloud::Bigtable.new
|
569
582
|
#
|
570
583
|
# instance = bigtable.instance("my-instance")
|
571
584
|
#
|
572
|
-
#
|
573
|
-
#
|
574
|
-
#
|
585
|
+
# initial_splits = ["user-00001", "user-100000", "others"]
|
586
|
+
# table = instance.create_table("my-table", initial_splits: initial_splits) do |cfm|
|
587
|
+
# cfm.add('cf1', gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
|
588
|
+
# cfm.add('cf2', gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
|
575
589
|
#
|
576
|
-
# gc_rule = Google::Cloud::Bigtable::GcRule.
|
577
|
-
# gc_rule.union = [
|
578
|
-
# Google::Cloud::Bigtable::GcRule.max_versions(3),
|
590
|
+
# gc_rule = Google::Cloud::Bigtable::GcRule.union(
|
579
591
|
# Google::Cloud::Bigtable::GcRule.max_age(1800),
|
580
|
-
#
|
581
|
-
#
|
592
|
+
# Google::Cloud::Bigtable::GcRule.max_versions(3)
|
593
|
+
# )
|
594
|
+
# cfm.add('cf3', gc_rule: gc_rule)
|
582
595
|
# end
|
583
596
|
#
|
584
597
|
# puts table
|
585
|
-
|
586
|
-
def create_table
|
587
|
-
name,
|
588
|
-
column_families: nil,
|
589
|
-
granularity: nil,
|
590
|
-
initial_splits: nil,
|
591
|
-
&block
|
598
|
+
#
|
599
|
+
def create_table name, column_families: nil, granularity: nil, initial_splits: nil, &block
|
592
600
|
ensure_service!
|
593
601
|
Table.create(
|
594
602
|
service,
|
595
603
|
instance_id,
|
596
604
|
name,
|
597
605
|
column_families: column_families,
|
598
|
-
granularity:
|
599
|
-
initial_splits:
|
606
|
+
granularity: granularity,
|
607
|
+
initial_splits: initial_splits,
|
600
608
|
&block
|
601
609
|
)
|
602
610
|
end
|
603
611
|
|
612
|
+
##
|
604
613
|
# Create app profile for an instance with a routing policy.
|
605
614
|
# Only one routing policy can applied to app profile. The policy can be
|
606
615
|
# multi-cluster routing or single cluster routing.
|
607
616
|
#
|
608
617
|
# @param name [String] Unique Id of the app profile
|
609
|
-
# @param routing_policy [Google::
|
610
|
-
# The routing policy for all read/write requests that use this app
|
611
|
-
# A value must be explicitly set.
|
618
|
+
# @param routing_policy [Google::Cloud::Bigtable::RoutingPolicy]
|
619
|
+
# The routing policy for all read/write requests that use this app
|
620
|
+
# profile. A value must be explicitly set.
|
612
621
|
#
|
613
622
|
# Routing Policies:
|
614
|
-
# *
|
615
|
-
#
|
616
|
-
#
|
617
|
-
# read-your-writes
|
618
|
-
#
|
619
|
-
#
|
620
|
-
#
|
621
|
-
#
|
623
|
+
# * {Google::Cloud::Bigtable::MultiClusterRoutingUseAny} - Read/write
|
624
|
+
# requests may be routed to any cluster in the instance and will
|
625
|
+
# fail over to another cluster in the event of transient errors or
|
626
|
+
# delays. Choosing this option sacrifices read-your-writes
|
627
|
+
# consistency to improve availability.
|
628
|
+
# * {Google::Cloud::Bigtable::SingleClusterRouting} - Unconditionally
|
629
|
+
# routes all read/write requests to a specific cluster. This option
|
630
|
+
# preserves read-your-writes consistency but does not improve
|
631
|
+
# availability. Value contains `cluster_id` and optional field
|
632
|
+
# `allow_transactional_writes`.
|
622
633
|
# @param description [String] Description of the use case for this app profile
|
623
634
|
# @param etag [String]
|
624
635
|
# Strongly validated etag for optimistic concurrency control. Preserve the
|
@@ -641,13 +652,13 @@ module Google
|
|
641
652
|
# instance = bigtable.instance("my-instance")
|
642
653
|
#
|
643
654
|
# routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
|
644
|
-
# "my-instance-cluster-1"
|
655
|
+
# "my-instance-cluster-1",
|
645
656
|
# allow_transactional_writes: true
|
646
657
|
# )
|
647
658
|
#
|
648
659
|
# app_profile = instance.create_app_profile(
|
649
660
|
# "my-app-profile",
|
650
|
-
# routing_policy
|
661
|
+
# routing_policy,
|
651
662
|
# description: "App profile for user data instance"
|
652
663
|
# )
|
653
664
|
# puts app_profile.name
|
@@ -684,27 +695,21 @@ module Google
|
|
684
695
|
# ignore_warnings: true
|
685
696
|
# )
|
686
697
|
# 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
|
698
|
+
#
|
699
|
+
def create_app_profile name, routing_policy, description: nil, etag: nil, ignore_warnings: false
|
694
700
|
ensure_service!
|
695
|
-
|
696
|
-
if
|
697
|
-
|
698
|
-
multi_cluster_routing = routing_policy
|
701
|
+
routing_policy_grpc = routing_policy.to_grpc
|
702
|
+
if routing_policy_grpc.is_a? Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny
|
703
|
+
multi_cluster_routing = routing_policy_grpc
|
699
704
|
else
|
700
|
-
single_cluster_routing =
|
705
|
+
single_cluster_routing = routing_policy_grpc
|
701
706
|
end
|
702
707
|
|
703
708
|
app_profile_attrs = {
|
704
709
|
multi_cluster_routing_use_any: multi_cluster_routing,
|
705
|
-
single_cluster_routing:
|
706
|
-
description:
|
707
|
-
etag:
|
710
|
+
single_cluster_routing: single_cluster_routing,
|
711
|
+
description: description,
|
712
|
+
etag: etag
|
708
713
|
}.delete_if { |_, v| v.nil? }
|
709
714
|
|
710
715
|
grpc = service.create_app_profile(
|
@@ -713,9 +718,10 @@ module Google
|
|
713
718
|
Google::Bigtable::Admin::V2::AppProfile.new(app_profile_attrs),
|
714
719
|
ignore_warnings: ignore_warnings
|
715
720
|
)
|
716
|
-
AppProfile.from_grpc
|
721
|
+
AppProfile.from_grpc grpc, service
|
717
722
|
end
|
718
723
|
|
724
|
+
##
|
719
725
|
# Get app profile.
|
720
726
|
#
|
721
727
|
# See to delete app_profile {Google::Cloud::Bigtable::AppProfile#delete} and update
|
@@ -736,15 +742,16 @@ module Google
|
|
736
742
|
# if app_profile
|
737
743
|
# puts app_profile.name
|
738
744
|
# end
|
739
|
-
|
745
|
+
#
|
740
746
|
def app_profile app_profile_id
|
741
747
|
ensure_service!
|
742
|
-
grpc = service.get_app_profile
|
743
|
-
AppProfile.from_grpc
|
748
|
+
grpc = service.get_app_profile instance_id, app_profile_id
|
749
|
+
AppProfile.from_grpc grpc, service
|
744
750
|
rescue Google::Cloud::NotFoundError
|
745
751
|
nil
|
746
752
|
end
|
747
753
|
|
754
|
+
##
|
748
755
|
# List all app profiles
|
749
756
|
#
|
750
757
|
# See to delete app_profile {Google::Cloud::Bigtable::AppProfile#delete} and update
|
@@ -763,13 +770,14 @@ module Google
|
|
763
770
|
# instance.app_profiles.all do |app_profile|
|
764
771
|
# puts app_profile.name
|
765
772
|
# end
|
766
|
-
|
773
|
+
#
|
767
774
|
def app_profiles
|
768
775
|
ensure_service!
|
769
|
-
grpc = service.list_app_profiles
|
770
|
-
AppProfile::List.from_grpc
|
776
|
+
grpc = service.list_app_profiles instance_id
|
777
|
+
AppProfile::List.from_grpc grpc, service
|
771
778
|
end
|
772
779
|
|
780
|
+
##
|
773
781
|
# Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
|
774
782
|
# policy for this instance.
|
775
783
|
#
|
@@ -793,7 +801,7 @@ module Google
|
|
793
801
|
# policy = instance.policy
|
794
802
|
#
|
795
803
|
# @example Update the policy by passing a block:
|
796
|
-
# require "google/cloud/
|
804
|
+
# require "google/cloud/bigtable"
|
797
805
|
#
|
798
806
|
# bigtable = Google::Cloud::Bigtable.new
|
799
807
|
# instance = bigtable.instance("my-instance")
|
@@ -801,16 +809,17 @@ module Google
|
|
801
809
|
# instance.policy do |p|
|
802
810
|
# p.add("roles/owner", "user:owner@example.com")
|
803
811
|
# end # 2 API calls
|
804
|
-
|
812
|
+
#
|
805
813
|
def policy
|
806
814
|
ensure_service!
|
807
|
-
grpc = service.get_instance_policy
|
808
|
-
policy = Policy.from_grpc
|
815
|
+
grpc = service.get_instance_policy instance_id
|
816
|
+
policy = Policy.from_grpc grpc
|
809
817
|
return policy unless block_given?
|
810
818
|
yield policy
|
811
819
|
update_policy policy
|
812
820
|
end
|
813
821
|
|
822
|
+
##
|
814
823
|
# Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
|
815
824
|
# policy for this instance. The policy should be read from {#policy}.
|
816
825
|
# See {Google::Cloud::Bigtable::Policy} for an explanation of the policy
|
@@ -836,14 +845,15 @@ module Google
|
|
836
845
|
# updated_policy = instance.update_policy(policy)
|
837
846
|
#
|
838
847
|
# puts update_policy.roles
|
839
|
-
|
848
|
+
#
|
840
849
|
def update_policy new_policy
|
841
850
|
ensure_service!
|
842
|
-
grpc = service.set_instance_policy
|
843
|
-
Policy.from_grpc
|
851
|
+
grpc = service.set_instance_policy instance_id, new_policy.to_grpc
|
852
|
+
Policy.from_grpc grpc
|
844
853
|
end
|
845
854
|
alias policy= update_policy
|
846
855
|
|
856
|
+
##
|
847
857
|
# Tests the specified permissions against the [Cloud
|
848
858
|
# IAM](https://cloud.google.com/iam/) access control policy.
|
849
859
|
#
|
@@ -873,13 +883,13 @@ module Google
|
|
873
883
|
#
|
874
884
|
# instance = bigtable.instance("my-instance")
|
875
885
|
#
|
876
|
-
# permissions =
|
886
|
+
# permissions = instance.test_iam_permissions(
|
877
887
|
# "bigtable.instances.get",
|
878
888
|
# "bigtable.instances.update"
|
879
889
|
# )
|
880
890
|
# permissions.include? "bigtable.instances.get" #=> true
|
881
891
|
# permissions.include? "bigtable.instances.update" #=> false
|
882
|
-
|
892
|
+
#
|
883
893
|
def test_iam_permissions *permissions
|
884
894
|
ensure_service!
|
885
895
|
grpc = service.test_instance_permissions(
|
@@ -897,9 +907,9 @@ module Google
|
|
897
907
|
# @param grpc [Google::Bigtable::Admin::V2::Instance]
|
898
908
|
# @param service [Google::Cloud::Bigtable::Service]
|
899
909
|
# @return [Google::Cloud::Bigtable::Instance]
|
900
|
-
|
910
|
+
#
|
901
911
|
def self.from_grpc grpc, service
|
902
|
-
new
|
912
|
+
new grpc, service
|
903
913
|
end
|
904
914
|
|
905
915
|
protected
|
@@ -908,7 +918,7 @@ module Google
|
|
908
918
|
#
|
909
919
|
# Raise an error unless an active connection to the service is
|
910
920
|
# available.
|
911
|
-
|
921
|
+
#
|
912
922
|
def ensure_service!
|
913
923
|
raise "Must have active connection to service" unless service
|
914
924
|
end
|