google-cloud-bigtable 0.1.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.
- checksums.yaml +7 -0
- data/.yardopts +10 -0
- data/LICENSE +201 -0
- data/README.md +65 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +139 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +85 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +137 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +117 -0
- data/lib/google/bigtable/admin/v2/common_pb.rb +24 -0
- data/lib/google/bigtable/admin/v2/instance_pb.rb +72 -0
- data/lib/google/bigtable/admin/v2/table_pb.rb +88 -0
- data/lib/google/bigtable/v2/bigtable_pb.rb +109 -0
- data/lib/google/bigtable/v2/bigtable_services_pb.rb +67 -0
- data/lib/google/bigtable/v2/data_pb.rb +155 -0
- data/lib/google/cloud/bigtable/admin/credentials.rb +26 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +1417 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +123 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1079 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +109 -0
- data/lib/google/cloud/bigtable/admin/v2/credentials.rb +50 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +279 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +353 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +194 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +209 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +62 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +127 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +92 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +124 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +90 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +28 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +223 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +106 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/bigtable/admin/v2.rb +200 -0
- data/lib/google/cloud/bigtable/admin.rb +196 -0
- data/lib/google/cloud/bigtable/app_profile/job.rb +102 -0
- data/lib/google/cloud/bigtable/app_profile/list.rb +159 -0
- data/lib/google/cloud/bigtable/app_profile.rb +373 -0
- data/lib/google/cloud/bigtable/chunk_processor.rb +253 -0
- data/lib/google/cloud/bigtable/cluster/job.rb +92 -0
- data/lib/google/cloud/bigtable/cluster/list.rb +169 -0
- data/lib/google/cloud/bigtable/cluster.rb +264 -0
- data/lib/google/cloud/bigtable/column_family.rb +280 -0
- data/lib/google/cloud/bigtable/column_range.rb +186 -0
- data/lib/google/cloud/bigtable/convert.rb +75 -0
- data/lib/google/cloud/bigtable/credentials.rb +24 -0
- data/lib/google/cloud/bigtable/errors.rb +35 -0
- data/lib/google/cloud/bigtable/gc_rule.rb +215 -0
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +70 -0
- data/lib/google/cloud/bigtable/instance/job.rb +97 -0
- data/lib/google/cloud/bigtable/instance/list.rb +159 -0
- data/lib/google/cloud/bigtable/instance.rb +921 -0
- data/lib/google/cloud/bigtable/longrunning_job.rb +105 -0
- data/lib/google/cloud/bigtable/mutation_entry.rb +244 -0
- data/lib/google/cloud/bigtable/mutation_operations.rb +338 -0
- data/lib/google/cloud/bigtable/policy.rb +163 -0
- data/lib/google/cloud/bigtable/project.rb +580 -0
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +129 -0
- data/lib/google/cloud/bigtable/read_operations.rb +345 -0
- data/lib/google/cloud/bigtable/row.rb +125 -0
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +539 -0
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +108 -0
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +570 -0
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +273 -0
- data/lib/google/cloud/bigtable/row_filter.rb +593 -0
- data/lib/google/cloud/bigtable/row_range.rb +174 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +120 -0
- data/lib/google/cloud/bigtable/rows_reader.rb +196 -0
- data/lib/google/cloud/bigtable/sample_row_key.rb +82 -0
- data/lib/google/cloud/bigtable/service.rb +817 -0
- data/lib/google/cloud/bigtable/table/cluster_state.rb +93 -0
- data/lib/google/cloud/bigtable/table/column_family_map.rb +68 -0
- data/lib/google/cloud/bigtable/table/list.rb +147 -0
- data/lib/google/cloud/bigtable/table.rb +676 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client.rb +579 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +65 -0
- data/lib/google/cloud/bigtable/v2/credentials.rb +45 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +286 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +492 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +124 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +89 -0
- data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +83 -0
- data/lib/google/cloud/bigtable/v2.rb +132 -0
- data/lib/google/cloud/bigtable/value_range.rb +175 -0
- data/lib/google/cloud/bigtable/version.rb +22 -0
- data/lib/google/cloud/bigtable.rb +223 -0
- data/lib/google-cloud-bigtable.rb +167 -0
- metadata +283 -0
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2018 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
|
+
require "delegate"
|
|
19
|
+
|
|
20
|
+
module Google
|
|
21
|
+
module Cloud
|
|
22
|
+
module Bigtable
|
|
23
|
+
class Instance
|
|
24
|
+
# Instance::List is a special case Array with additional
|
|
25
|
+
# values and failed_locations
|
|
26
|
+
class List < DelegateClass(::Array)
|
|
27
|
+
# @private
|
|
28
|
+
# The gRPC Service object.
|
|
29
|
+
attr_accessor :service
|
|
30
|
+
|
|
31
|
+
# If not empty, indicates that there are more records that match
|
|
32
|
+
# the request and this value should be passed to continue.
|
|
33
|
+
attr_accessor :token
|
|
34
|
+
|
|
35
|
+
# Locations from which Instance information could not be retrieved,
|
|
36
|
+
# due to an outage or some other transient condition.
|
|
37
|
+
# Instances whose Clusters are all in one of the failed locations
|
|
38
|
+
# may be missing from `instances`, and Instances with at least one
|
|
39
|
+
# Cluster in a failed location may only have partial information returned.
|
|
40
|
+
attr_accessor :failed_locations
|
|
41
|
+
|
|
42
|
+
# @private
|
|
43
|
+
# Create a new Instance::List with an array of
|
|
44
|
+
# Instance instances.
|
|
45
|
+
def initialize arr = []
|
|
46
|
+
super(arr)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Whether there is a next page of instances.
|
|
50
|
+
#
|
|
51
|
+
# @return [Boolean]
|
|
52
|
+
#
|
|
53
|
+
# @example
|
|
54
|
+
# require "google/cloud/bigtable"
|
|
55
|
+
#
|
|
56
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
57
|
+
#
|
|
58
|
+
# instances = bigtable.instances
|
|
59
|
+
# if instances.next?
|
|
60
|
+
# next_instances = instances.next
|
|
61
|
+
# end
|
|
62
|
+
def next?
|
|
63
|
+
!token.nil?
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Retrieve the next page of instances.
|
|
67
|
+
#
|
|
68
|
+
# @return [Instance::List] The list of instances.
|
|
69
|
+
#
|
|
70
|
+
# @example
|
|
71
|
+
# require "google/cloud/bigtable"
|
|
72
|
+
#
|
|
73
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
74
|
+
#
|
|
75
|
+
# instances = bigtable.instances
|
|
76
|
+
# if instances.next?
|
|
77
|
+
# next_instances = instances.next
|
|
78
|
+
# end
|
|
79
|
+
#
|
|
80
|
+
def next
|
|
81
|
+
return nil unless next?
|
|
82
|
+
ensure_service!
|
|
83
|
+
grpc = service.list_instances(token: token)
|
|
84
|
+
next_list = self.class.from_grpc(grpc, service)
|
|
85
|
+
if failed_locations
|
|
86
|
+
next_list.failed_locations.concat(failed_locations.map(&:to_s))
|
|
87
|
+
end
|
|
88
|
+
next_list
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Retrieves remaining results by repeatedly invoking {#next} until
|
|
92
|
+
# {#next?} returns `false`. Calls the given block once for each
|
|
93
|
+
# result, which is passed as the argument to the block.
|
|
94
|
+
#
|
|
95
|
+
# An Enumerator is returned if no block is given.
|
|
96
|
+
#
|
|
97
|
+
# This method will make repeated API calls until all remaining results
|
|
98
|
+
# are retrieved. (Unlike `#each`, for example, which merely iterates
|
|
99
|
+
# over the results returned by a single API call.) Use with caution.
|
|
100
|
+
#
|
|
101
|
+
# @yield [instance] The block for accessing each instance.
|
|
102
|
+
# @yieldparam [Instance] instance The instance object.
|
|
103
|
+
#
|
|
104
|
+
# @return [Enumerator]
|
|
105
|
+
#
|
|
106
|
+
# @example Iterating each instance by passing a block:
|
|
107
|
+
# require "google/cloud/bigtable"
|
|
108
|
+
#
|
|
109
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
110
|
+
#
|
|
111
|
+
# bigtable.instances.all do |instance|
|
|
112
|
+
# puts instance.instance_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
|
+
# all_instance_ids = bigtable.instances.all.map do |instance|
|
|
121
|
+
# puts instance.instance_id
|
|
122
|
+
# end
|
|
123
|
+
#
|
|
124
|
+
def all
|
|
125
|
+
return enum_for(:all) unless block_given?
|
|
126
|
+
|
|
127
|
+
results = self
|
|
128
|
+
loop do
|
|
129
|
+
results.each { |r| yield r }
|
|
130
|
+
break unless results.next?
|
|
131
|
+
results = results.next
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# @private
|
|
136
|
+
# New Instance::List from a Google::Bigtable::Admin::V2::Instance object.
|
|
137
|
+
def self.from_grpc grpc, service
|
|
138
|
+
instances = List.new(Array(grpc.instances).map do |instance|
|
|
139
|
+
Instance.from_grpc(instance, service)
|
|
140
|
+
end)
|
|
141
|
+
token = grpc.next_page_token
|
|
142
|
+
token = nil if token == "".freeze
|
|
143
|
+
instances.token = token
|
|
144
|
+
instances.service = service
|
|
145
|
+
instances.failed_locations = grpc.failed_locations.map(&:to_s)
|
|
146
|
+
instances
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
protected
|
|
150
|
+
|
|
151
|
+
# Raise an error unless an active service is available.
|
|
152
|
+
def ensure_service!
|
|
153
|
+
raise "Must have active connection" unless service
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
end
|
|
@@ -0,0 +1,921 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2018 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
|
+
require "google/cloud/bigtable/instance/job"
|
|
19
|
+
require "google/cloud/bigtable/instance/list"
|
|
20
|
+
require "google/cloud/bigtable/instance/cluster_map"
|
|
21
|
+
require "google/cloud/bigtable/app_profile"
|
|
22
|
+
require "google/cloud/bigtable/policy"
|
|
23
|
+
|
|
24
|
+
module Google
|
|
25
|
+
module Cloud
|
|
26
|
+
module Bigtable
|
|
27
|
+
# # Instance
|
|
28
|
+
#
|
|
29
|
+
# Represents a Bigtable instance. Instances are dedicated Bigtable
|
|
30
|
+
# serving and storage resources to be used by Bigtable tables.
|
|
31
|
+
#
|
|
32
|
+
# See {Google::Cloud::Bigtable::Project#instances},
|
|
33
|
+
# {Google::Cloud::Bigtable::Project#instance}, and
|
|
34
|
+
# {Google::Cloud::Bigtable::Project#create_instance}.
|
|
35
|
+
#
|
|
36
|
+
# @example
|
|
37
|
+
# require "google/cloud/bigtable"
|
|
38
|
+
#
|
|
39
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
40
|
+
#
|
|
41
|
+
# job = bigtable.create_instance(
|
|
42
|
+
# "my-instance",
|
|
43
|
+
# "Instance for user data",
|
|
44
|
+
# type: :DEVELOPMENT,
|
|
45
|
+
# labels: { "env" => "dev"}
|
|
46
|
+
# ) do |clusters|
|
|
47
|
+
# clusters.add("test-cluster", "us-east1-b", nodes: 1)
|
|
48
|
+
# end
|
|
49
|
+
#
|
|
50
|
+
# job.done? #=> false
|
|
51
|
+
#
|
|
52
|
+
# # To block until the operation completes.
|
|
53
|
+
# job.wait_until_done!
|
|
54
|
+
# job.done? #=> true
|
|
55
|
+
#
|
|
56
|
+
# if job.error?
|
|
57
|
+
# status = job.error
|
|
58
|
+
# else
|
|
59
|
+
# instance = job.instance
|
|
60
|
+
# end
|
|
61
|
+
#
|
|
62
|
+
class Instance
|
|
63
|
+
# @private
|
|
64
|
+
# The gRPC Service object.
|
|
65
|
+
attr_accessor :service
|
|
66
|
+
|
|
67
|
+
# @private
|
|
68
|
+
#
|
|
69
|
+
# Creates a new Instance instance.
|
|
70
|
+
def initialize grpc, service
|
|
71
|
+
@grpc = grpc
|
|
72
|
+
@service = service
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# The unique identifier for the project.
|
|
76
|
+
#
|
|
77
|
+
# @return [String]
|
|
78
|
+
|
|
79
|
+
def project_id
|
|
80
|
+
@grpc.name.split("/")[1]
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# The unique identifier for the instance.
|
|
84
|
+
#
|
|
85
|
+
# @return [String]
|
|
86
|
+
|
|
87
|
+
def instance_id
|
|
88
|
+
@grpc.name.split("/")[3]
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# The descriptive name for this instance as it appears in UIs. Must be
|
|
92
|
+
# unique per project and between 4 and 30 characters in length.
|
|
93
|
+
#
|
|
94
|
+
# @return [String]
|
|
95
|
+
|
|
96
|
+
def display_name
|
|
97
|
+
@grpc.display_name
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Updates the descriptive name for this instance as it appears in UIs.
|
|
101
|
+
# Can be changed at any time, but should be kept globally unique
|
|
102
|
+
# to avoid confusion.
|
|
103
|
+
#
|
|
104
|
+
# @param value [String] The descriptive name for this instance.
|
|
105
|
+
|
|
106
|
+
def display_name= value
|
|
107
|
+
@grpc.display_name = value
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# The full path for the instance resource. Values are of the form
|
|
111
|
+
# `projects/<project_id>/instances/<instance_id>`.
|
|
112
|
+
#
|
|
113
|
+
# @return [String]
|
|
114
|
+
|
|
115
|
+
def path
|
|
116
|
+
@grpc.name
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
# The current instance state. Possible values are `:CREATING`,
|
|
120
|
+
# `:READY`, `:STATE_NOT_KNOWN`.
|
|
121
|
+
#
|
|
122
|
+
# @return [Symbol]
|
|
123
|
+
|
|
124
|
+
def state
|
|
125
|
+
@grpc.state
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# The instance has been successfully created and can serve requests
|
|
129
|
+
# to its tables
|
|
130
|
+
#
|
|
131
|
+
# @return [Boolean]
|
|
132
|
+
|
|
133
|
+
def ready?
|
|
134
|
+
state == :READY
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# The instance is currently being created, and may be destroyed if the
|
|
138
|
+
# creation process encounters an error.
|
|
139
|
+
#
|
|
140
|
+
# @return [Boolean]
|
|
141
|
+
|
|
142
|
+
def creating?
|
|
143
|
+
state == :CREATING
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Instance type. Possible values are `:DEVELOPMENT`, `:PRODUCTION`,
|
|
147
|
+
# `:TYPE_UNSPECIFIED`
|
|
148
|
+
#
|
|
149
|
+
# @return [Symbol]
|
|
150
|
+
|
|
151
|
+
def type
|
|
152
|
+
@grpc.type
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# The instance is meant for development and testing purposes only; it has
|
|
156
|
+
# no performance or uptime guarantees and is not covered by SLA.
|
|
157
|
+
# After a development instance is created, it can be upgraded by
|
|
158
|
+
# updating the instance to type `PRODUCTION`. An instance created
|
|
159
|
+
# 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.
|
|
162
|
+
#
|
|
163
|
+
# @return [Boolean]
|
|
164
|
+
|
|
165
|
+
def development?
|
|
166
|
+
type == :DEVELOPMENT
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# An instance meant for production use. `serve_nodes` must be set
|
|
170
|
+
# on the cluster.
|
|
171
|
+
#
|
|
172
|
+
# @return [Boolean]
|
|
173
|
+
|
|
174
|
+
def production?
|
|
175
|
+
type == :PRODUCTION
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
# Set instance type.
|
|
179
|
+
#
|
|
180
|
+
# Valid values are `:DEVELOPMENT`, `:PRODUCTION`.
|
|
181
|
+
# If instance already created then After a development instance is
|
|
182
|
+
# created, it can be upgraded by updating the instance to type `PRODUCTION`.
|
|
183
|
+
# An instance created as a production instance cannot be changed to a
|
|
184
|
+
# development instance.
|
|
185
|
+
#
|
|
186
|
+
# @param instance_type [Symbol]
|
|
187
|
+
|
|
188
|
+
def type= instance_type
|
|
189
|
+
@grpc.type = instance_type
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# Get instance labels.
|
|
193
|
+
#
|
|
194
|
+
# Cloud Labels are a flexible and lightweight mechanism for organizing
|
|
195
|
+
# cloud resources into groups that reflect a customer's organizational
|
|
196
|
+
# needs and deployment strategies. Cloud Labels can be used to filter
|
|
197
|
+
# collections of resources. They can be used to control how resource
|
|
198
|
+
# metrics are aggregated. And they can be used as arguments to policy
|
|
199
|
+
# management rules (e.g. route, firewall, load balancing, etc.).
|
|
200
|
+
#
|
|
201
|
+
# * Label keys must be between 1 and 63 characters long and must conform
|
|
202
|
+
# to the following regular expression: `[a-z]([-a-z0-9]*[a-z0-9])?`.
|
|
203
|
+
# * Label values must be between 0 and 63 characters long and must
|
|
204
|
+
# conform to the regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
|
|
205
|
+
# * No more than 64 labels can be associated with a given resource.
|
|
206
|
+
#
|
|
207
|
+
# @return [Hash{String=>String}] The label keys and values in a hash.
|
|
208
|
+
|
|
209
|
+
def labels
|
|
210
|
+
@grpc.labels
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Set the Cloud Labels.
|
|
214
|
+
#
|
|
215
|
+
# @param labels [Hash{String=>String}] The Cloud Labels.
|
|
216
|
+
|
|
217
|
+
def labels= labels
|
|
218
|
+
labels ||= {}
|
|
219
|
+
@grpc.labels = Google::Protobuf::Map.new(
|
|
220
|
+
:string, :string,
|
|
221
|
+
Hash[labels.map { |k, v| [String(k), String(v)] }]
|
|
222
|
+
)
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# Update instance.
|
|
226
|
+
#
|
|
227
|
+
# Updatable attributes are :
|
|
228
|
+
# * `display_name` - The descriptive name for this instance.
|
|
229
|
+
# * `type` - `:DEVELOPMENT` type instance can be upgraded to `:PRODUCTION` instance.
|
|
230
|
+
# An instance created as a production instance cannot be changed to a development instance.
|
|
231
|
+
# * `labels` - Cloud Labels are a flexible and lightweight mechanism for organizing cloud resources.
|
|
232
|
+
#
|
|
233
|
+
# @return [Google::Cloud::Bigtable::Instance::Job]
|
|
234
|
+
# The job representing the long-running, asynchronous processing of
|
|
235
|
+
# an instance update operation.
|
|
236
|
+
# @example
|
|
237
|
+
# require "google/cloud/bigtable"
|
|
238
|
+
#
|
|
239
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
240
|
+
#
|
|
241
|
+
# instance = bigtable.instance("my-instance")
|
|
242
|
+
# instance.display_name = "My app dev instance" # Set display name
|
|
243
|
+
# instance.labels = { env: "dev", data: "users" }
|
|
244
|
+
# job = instance.save
|
|
245
|
+
#
|
|
246
|
+
# job.done? #=> false
|
|
247
|
+
#
|
|
248
|
+
# # Reload job until completion.
|
|
249
|
+
# job.wait_until_done!
|
|
250
|
+
# job.done? #=> true
|
|
251
|
+
#
|
|
252
|
+
# if job.error?
|
|
253
|
+
# puts job.error
|
|
254
|
+
# else
|
|
255
|
+
# instance = job.instance
|
|
256
|
+
# puts instance.name
|
|
257
|
+
# puts instance.labels
|
|
258
|
+
# end
|
|
259
|
+
|
|
260
|
+
def save
|
|
261
|
+
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)
|
|
267
|
+
end
|
|
268
|
+
alias update save
|
|
269
|
+
|
|
270
|
+
# Reload instance information.
|
|
271
|
+
#
|
|
272
|
+
# @return [Google::Cloud::Bigtable::Instance]
|
|
273
|
+
|
|
274
|
+
def reload!
|
|
275
|
+
@grpc = service.get_instance(instance_id)
|
|
276
|
+
self
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# Permanently deletes the instance from a project.
|
|
280
|
+
#
|
|
281
|
+
# @return [Boolean] Returns `true` if the instance was deleted.
|
|
282
|
+
#
|
|
283
|
+
# @example
|
|
284
|
+
# require "google/cloud/bigtable"
|
|
285
|
+
#
|
|
286
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
287
|
+
#
|
|
288
|
+
# instance = bigtable.instance("my-instance")
|
|
289
|
+
# instance.delete
|
|
290
|
+
|
|
291
|
+
def delete
|
|
292
|
+
ensure_service!
|
|
293
|
+
service.delete_instance(instance_id)
|
|
294
|
+
true
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
# Lists information about clusters in an instance.
|
|
298
|
+
#
|
|
299
|
+
# See to delete {Google::Cloud::Bigtable::Cluster#delete} and update
|
|
300
|
+
# cluster {Google::Cloud::Bigtable::Cluster#save}.
|
|
301
|
+
#
|
|
302
|
+
# @param token [String] The `token` value returned by the last call to
|
|
303
|
+
# `clusters`; indicates that this is a continuation of a call,
|
|
304
|
+
# and that the system should return the next page of data.
|
|
305
|
+
# @return [Array<Google::Cloud::Bigtable::Cluster>]
|
|
306
|
+
# See({Google::Cloud::Bigtable::Cluster::List})
|
|
307
|
+
#
|
|
308
|
+
# @example
|
|
309
|
+
# require "google/cloud/bigtable"
|
|
310
|
+
#
|
|
311
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
312
|
+
#
|
|
313
|
+
# instance = bigtable.instance("my-instance")
|
|
314
|
+
#
|
|
315
|
+
# instance.clusters.all do |cluster|
|
|
316
|
+
# puts cluster.cluster_id
|
|
317
|
+
# end
|
|
318
|
+
|
|
319
|
+
def clusters token: nil
|
|
320
|
+
ensure_service!
|
|
321
|
+
grpc = service.list_clusters(instance_id, token: token)
|
|
322
|
+
Cluster::List.from_grpc(grpc, service, instance_id: instance_id)
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
# Gets cluster information.
|
|
326
|
+
#
|
|
327
|
+
# See to delete {Google::Cloud::Bigtable::Cluster#delete} and update
|
|
328
|
+
# cluster {Google::Cloud::Bigtable::Cluster#save}.
|
|
329
|
+
#
|
|
330
|
+
# @param cluster_id [String] The unique ID of the requested cluster.
|
|
331
|
+
# @return [Google::Cloud::Bigtable::Cluster, nil]
|
|
332
|
+
#
|
|
333
|
+
# @example
|
|
334
|
+
# require "google/cloud/bigtable"
|
|
335
|
+
#
|
|
336
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
337
|
+
#
|
|
338
|
+
# instance = bigtable.instance("my-instance")
|
|
339
|
+
#
|
|
340
|
+
# cluster = instance.cluster("my-instance-cluster")
|
|
341
|
+
# puts cluster.cluster_id
|
|
342
|
+
|
|
343
|
+
def cluster cluster_id
|
|
344
|
+
ensure_service!
|
|
345
|
+
grpc = service.get_cluster(instance_id, cluster_id)
|
|
346
|
+
Cluster.from_grpc(grpc, service)
|
|
347
|
+
rescue Google::Cloud::NotFoundError
|
|
348
|
+
nil
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# Creates a cluster within an instance.
|
|
352
|
+
#
|
|
353
|
+
# @param cluster_id [String]
|
|
354
|
+
# The ID to be used when referring to the new cluster within its instance,
|
|
355
|
+
# e.g., just +mycluster+
|
|
356
|
+
# @param location [String]
|
|
357
|
+
# The location where this cluster's nodes and storage reside. For best
|
|
358
|
+
# performance, clients should be located as close as possible to this
|
|
359
|
+
# cluster. Currently only zones are supported.
|
|
360
|
+
# i.e "us-east-1b"
|
|
361
|
+
# @param nodes [Integer] The number of nodes allocated to this cluster.
|
|
362
|
+
# More nodes enable higher throughput and more consistent performance.
|
|
363
|
+
# @param storage_type [Symbol] Type of storage type.
|
|
364
|
+
# The type of storage used by this cluster to serve its
|
|
365
|
+
# parent instance's tables.
|
|
366
|
+
# Valid types are:
|
|
367
|
+
# * `:SSD` - Flash (SSD) storage.
|
|
368
|
+
# * `:HDD` - Magnetic drive (HDD).
|
|
369
|
+
# @return [Google::Cloud::Bigtable::Cluster::Job]
|
|
370
|
+
#
|
|
371
|
+
# @example
|
|
372
|
+
# require "google/cloud/bigtable"
|
|
373
|
+
#
|
|
374
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
375
|
+
#
|
|
376
|
+
# instance = bigtable.instance("my-instance")
|
|
377
|
+
# job = instance.create_cluster(
|
|
378
|
+
# "my-new-cluster",
|
|
379
|
+
# "us-east-1b",
|
|
380
|
+
# nodes: 3,
|
|
381
|
+
# storage_type: :SSD
|
|
382
|
+
# )
|
|
383
|
+
#
|
|
384
|
+
# job.done? #=> false
|
|
385
|
+
#
|
|
386
|
+
# # To block until the operation completes.
|
|
387
|
+
# job.wait_until_done!
|
|
388
|
+
# job.done? #=> true
|
|
389
|
+
#
|
|
390
|
+
# if job.error?
|
|
391
|
+
# status = job.error
|
|
392
|
+
# else
|
|
393
|
+
# cluster = job.cluster
|
|
394
|
+
# end
|
|
395
|
+
|
|
396
|
+
def create_cluster cluster_id, location, nodes: nil, storage_type: nil
|
|
397
|
+
ensure_service!
|
|
398
|
+
attrs = {
|
|
399
|
+
serve_nodes: nodes,
|
|
400
|
+
default_storage_type: storage_type,
|
|
401
|
+
location: location
|
|
402
|
+
}.delete_if { |_, v| v.nil? }
|
|
403
|
+
|
|
404
|
+
cluster = Google::Bigtable::Admin::V2::Cluster.new(attrs)
|
|
405
|
+
grpc = service.create_cluster(instance_id, cluster_id, cluster)
|
|
406
|
+
Cluster::Job.from_grpc(grpc, service)
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
# List all tables.
|
|
410
|
+
#
|
|
411
|
+
# See to delete table {Google::Cloud::Bigtable::Table#delete} and update
|
|
412
|
+
# table {Google::Cloud::Bigtable::Table#save}.
|
|
413
|
+
#
|
|
414
|
+
# @return [Array<Google::Cloud::Bigtable::Table>]
|
|
415
|
+
# (See {Google::Cloud::Bigtable::Table::List})
|
|
416
|
+
#
|
|
417
|
+
# @example
|
|
418
|
+
# require "google/cloud/bigtable"
|
|
419
|
+
#
|
|
420
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
421
|
+
#
|
|
422
|
+
# instance = bigtable.instance("my-instance")
|
|
423
|
+
#
|
|
424
|
+
# # Default name only view
|
|
425
|
+
# instance.tables.all do |table|
|
|
426
|
+
# puts table.name
|
|
427
|
+
# end
|
|
428
|
+
#
|
|
429
|
+
# # Full view
|
|
430
|
+
# instance.tables(view: :FULL).all do |table|
|
|
431
|
+
# puts table.name
|
|
432
|
+
# puts table.column_families
|
|
433
|
+
# end
|
|
434
|
+
#
|
|
435
|
+
def tables
|
|
436
|
+
ensure_service!
|
|
437
|
+
grpc = service.list_tables(instance_id)
|
|
438
|
+
Table::List.from_grpc(grpc, service)
|
|
439
|
+
end
|
|
440
|
+
|
|
441
|
+
# Get metadata information of table.
|
|
442
|
+
#
|
|
443
|
+
# @param view [Symbol]
|
|
444
|
+
# The view to be applied to the returned tables' fields
|
|
445
|
+
# Defaults to `SCHEMA_VIEW` if unspecified.
|
|
446
|
+
# Valid view types are.
|
|
447
|
+
# * `:NAME_ONLY` - Only populates `name`
|
|
448
|
+
# * `:SCHEMA_VIEW` - Only populates `name` and fields related to the table's schema
|
|
449
|
+
# * `:REPLICATION_VIEW` - Only populates `name` and fields related to the table's replication state.
|
|
450
|
+
# * `:FULL` - Populates all fields
|
|
451
|
+
# @param perform_lookup [Boolean] Create table object without verifying
|
|
452
|
+
# that the table resource exists.
|
|
453
|
+
# Calls made on this object will raise errors if the table.
|
|
454
|
+
# does not exist. Default value is `false`. Optional.
|
|
455
|
+
# It helps to reduce admin apis calls.
|
|
456
|
+
# @param app_profile_id [String] The unique identifier for the app profile. Optional.
|
|
457
|
+
# It is used only in data operations.
|
|
458
|
+
# This value specifies routing for replication. If not specified, the
|
|
459
|
+
# "default" application profile will be used.
|
|
460
|
+
# @return [Google::Cloud::Bigtable::Table]
|
|
461
|
+
#
|
|
462
|
+
# @example
|
|
463
|
+
# require "google/cloud/bigtable"
|
|
464
|
+
#
|
|
465
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
466
|
+
#
|
|
467
|
+
# instance = bigtable.instance("my-instance")
|
|
468
|
+
#
|
|
469
|
+
# # Default view is full view
|
|
470
|
+
# table = instance.table("my-table", perform_lookup: true)
|
|
471
|
+
# puts table.name
|
|
472
|
+
# puts table.column_families
|
|
473
|
+
#
|
|
474
|
+
# # Name only view
|
|
475
|
+
# table = instance.table("my-table", view: :NAME_ONLY, perform_lookup: true)
|
|
476
|
+
# puts table.name
|
|
477
|
+
#
|
|
478
|
+
# @example Mutate rows
|
|
479
|
+
# require "google/cloud/bigtable"
|
|
480
|
+
#
|
|
481
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
482
|
+
#
|
|
483
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
484
|
+
#
|
|
485
|
+
# entry = table.new_mutation_entry("user-1")
|
|
486
|
+
# entry.set_cell(
|
|
487
|
+
# "cf-1",
|
|
488
|
+
# "field-1",
|
|
489
|
+
# "XYZ"
|
|
490
|
+
# timestamp: Time.now.to_i * 1000 # Time stamp in milli seconds.
|
|
491
|
+
# ).delete_from_column("cf2", "field02")
|
|
492
|
+
#
|
|
493
|
+
# table.mutate_row(entry)
|
|
494
|
+
|
|
495
|
+
#
|
|
496
|
+
def table table_id, view: nil, perform_lookup: nil, app_profile_id: nil
|
|
497
|
+
ensure_service!
|
|
498
|
+
|
|
499
|
+
table = if perform_lookup
|
|
500
|
+
grpc = service.get_table(instance_id, table_id, view: view)
|
|
501
|
+
Table.from_grpc(grpc, service, view: view)
|
|
502
|
+
else
|
|
503
|
+
Table.from_path(
|
|
504
|
+
service.table_path(instance_id, table_id),
|
|
505
|
+
service
|
|
506
|
+
)
|
|
507
|
+
end
|
|
508
|
+
|
|
509
|
+
table.app_profile_id = app_profile_id
|
|
510
|
+
table
|
|
511
|
+
rescue Google::Cloud::NotFoundError
|
|
512
|
+
nil
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
# Create table
|
|
516
|
+
#
|
|
517
|
+
# The table can be created with a full set of initial column families,
|
|
518
|
+
# specified in the request.
|
|
519
|
+
#
|
|
520
|
+
# @param name [String]
|
|
521
|
+
# The name by which the new table should be referred to within the parent
|
|
522
|
+
# instance, e.g., +foobar+
|
|
523
|
+
# @param column_families [Hash{String => Google::Cloud::Bigtable::ColumnFamily}]
|
|
524
|
+
# (See {Google::Cloud::Bigtable::Table::ColumnFamilyMap})
|
|
525
|
+
# If passed as an empty use code block to add column families.
|
|
526
|
+
# @param granularity [Symbol]
|
|
527
|
+
# The granularity at which timestamps are stored in this table.
|
|
528
|
+
# Timestamps not matching the granularity will be rejected.
|
|
529
|
+
# Valid values are `:MILLIS`.
|
|
530
|
+
# If unspecified, the value will be set to `:MILLIS`
|
|
531
|
+
# @param initial_splits [Array<String>]
|
|
532
|
+
# The optional list of row keys that will be used to initially split the
|
|
533
|
+
# table into several tablets (tablets are similar to HBase regions).
|
|
534
|
+
# Given two split keys, +s1+ and +s2+, three tablets will be created,
|
|
535
|
+
# spanning the key ranges: +[, s1), [s1, s2), [s2, )+.
|
|
536
|
+
#
|
|
537
|
+
# Example:
|
|
538
|
+
#
|
|
539
|
+
# * Row keys := +["a", "apple", "custom", "customer_1", "customer_2",+
|
|
540
|
+
# +"other", "zz"]+
|
|
541
|
+
# * initial_split_keys := +["apple", "customer_1", "customer_2", "other"]+
|
|
542
|
+
# * Key assignment:
|
|
543
|
+
# * Tablet 1 : +[, apple) => {"a"}.+
|
|
544
|
+
# * Tablet 2 : +[apple, customer_1) => {"apple", "custom"}.+
|
|
545
|
+
# * Tablet 3 : +[customer_1, customer_2) => {"customer_1"}.+
|
|
546
|
+
# * Tablet 4 : +[customer_2, other) => {"customer_2"}.+
|
|
547
|
+
# * Tablet 5 : +[other, ) => {"other", "zz"}.+
|
|
548
|
+
# A hash of the same form as `Google::Bigtable::Admin::V2::CreateTableRequest::Split`
|
|
549
|
+
# can also be provided.
|
|
550
|
+
# @yield [column_families] A block for adding column_families.
|
|
551
|
+
# @yieldparam [Hash{String => Google::Cloud::Bigtable::ColumnFamily}]
|
|
552
|
+
# Cluster map of cluster name and cluster object.
|
|
553
|
+
# (See {Google::Cloud::Bigtable::Instance::ClusterMap})
|
|
554
|
+
# GC Rules for column family see {Google::Cloud::Bigtable::GcRule})
|
|
555
|
+
#
|
|
556
|
+
# @return [Google::Cloud::Bigtable::Table]
|
|
557
|
+
#
|
|
558
|
+
# @example Create table without column families.
|
|
559
|
+
# require "google/cloud/bigtable"
|
|
560
|
+
#
|
|
561
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
562
|
+
#
|
|
563
|
+
# instance = bigtable.instance("my-instance")
|
|
564
|
+
#
|
|
565
|
+
# table = instance.create_table("my-table")
|
|
566
|
+
# puts table.name
|
|
567
|
+
#
|
|
568
|
+
# @example Create table with column families and initial splits.
|
|
569
|
+
# require "google/cloud/bigtable"
|
|
570
|
+
#
|
|
571
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
572
|
+
#
|
|
573
|
+
# instance = bigtable.instance("my-instance")
|
|
574
|
+
#
|
|
575
|
+
# table = instance.create_table(my-table") do |column_families|
|
|
576
|
+
# column_families.add('cf1', Google::Cloud::Bigtable::GcRule.max_versions(3))
|
|
577
|
+
# column_families.add('cf2', Google::Cloud::Bigtable::GcRule.max_age(100))
|
|
578
|
+
#
|
|
579
|
+
# gc_rule = Google::Cloud::Bigtable::GcRule.new
|
|
580
|
+
# gc_rule.union = [
|
|
581
|
+
# Google::Cloud::Bigtable::GcRule.max_versions(3),
|
|
582
|
+
# Google::Cloud::Bigtable::GcRule.max_age(1800),
|
|
583
|
+
# ]
|
|
584
|
+
# column_families.add('cf3', gc_rule)
|
|
585
|
+
# end
|
|
586
|
+
#
|
|
587
|
+
# puts table
|
|
588
|
+
|
|
589
|
+
def create_table \
|
|
590
|
+
name,
|
|
591
|
+
column_families: nil,
|
|
592
|
+
granularity: nil,
|
|
593
|
+
initial_splits: nil,
|
|
594
|
+
&block
|
|
595
|
+
ensure_service!
|
|
596
|
+
Table.create(
|
|
597
|
+
service,
|
|
598
|
+
instance_id,
|
|
599
|
+
name,
|
|
600
|
+
column_families: column_families,
|
|
601
|
+
granularity: granularity,
|
|
602
|
+
initial_splits: initial_splits,
|
|
603
|
+
&block
|
|
604
|
+
)
|
|
605
|
+
end
|
|
606
|
+
|
|
607
|
+
# Create app profile of instance with routing policy.
|
|
608
|
+
# Only one routing policy can applied to app profile. It can be
|
|
609
|
+
# multi cluster routing or single cluster routing
|
|
610
|
+
#
|
|
611
|
+
# @param name [String] Unique Id of the app profile
|
|
612
|
+
# @param routing_policy [Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting | Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny]
|
|
613
|
+
# The routing policy for all read/write requests which use this app profile.
|
|
614
|
+
# A value must be explicitly set.
|
|
615
|
+
#
|
|
616
|
+
# Routing Policies:
|
|
617
|
+
# * `multi_cluster_routing` - Read/write requests may be routed to any
|
|
618
|
+
# cluster in the instance, and will fail over to another cluster in the event
|
|
619
|
+
# of transient errors or delays. Choosing this option sacrifices
|
|
620
|
+
# read-your-writes consistency to improve availability.
|
|
621
|
+
# * `single_cluster_routing` - Unconditionally routes all read/write requests
|
|
622
|
+
# to a specific cluster. This option preserves read-your-writes consistency,
|
|
623
|
+
# but does not improve availability.
|
|
624
|
+
# Value contain `cluster_id` and optional field `allow_transactional_writes`.
|
|
625
|
+
# @param description [String] Description of the use case for this AppProfile
|
|
626
|
+
# @param etag [String]
|
|
627
|
+
# Strongly validated etag for optimistic concurrency control. Preserve the
|
|
628
|
+
# value returned from `GetAppProfile` when calling `UpdateAppProfile` to
|
|
629
|
+
# fail the request if there has been a modification in the mean time. The
|
|
630
|
+
# `update_mask` of the request need not include `etag` for this protection
|
|
631
|
+
# to apply.
|
|
632
|
+
# See [Wikipedia](https://en.wikipedia.org/wiki/HTTP_ETag) and
|
|
633
|
+
# [RFC 7232](https://tools.ietf.org/html/rfc7232#section-2.3) for more details.
|
|
634
|
+
# @param ignore_warnings [Boolean]
|
|
635
|
+
# If true, ignore safety checks when creating the app profile.
|
|
636
|
+
# Default value is `false`
|
|
637
|
+
# @return [Google::Cloud::Bigtable::AppProfile]
|
|
638
|
+
#
|
|
639
|
+
# @example Create app profile with single cluster routing policy
|
|
640
|
+
# require "google/cloud/bigtable"
|
|
641
|
+
#
|
|
642
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
643
|
+
#
|
|
644
|
+
# instance = bigtable.instance("my-instance")
|
|
645
|
+
#
|
|
646
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
|
|
647
|
+
# "my-instance-cluster-1"
|
|
648
|
+
# allow_transactional_writes: true
|
|
649
|
+
# )
|
|
650
|
+
#
|
|
651
|
+
# app_profile = instance.create_app_profile(
|
|
652
|
+
# "my-app-profile",
|
|
653
|
+
# routing_policy: routing_policy,
|
|
654
|
+
# description: "App profile for user data instance"
|
|
655
|
+
# )
|
|
656
|
+
# puts app_profile.name
|
|
657
|
+
#
|
|
658
|
+
# @example Create app profile with multi cluster routing policy
|
|
659
|
+
# require "google/cloud/bigtable"
|
|
660
|
+
#
|
|
661
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
662
|
+
#
|
|
663
|
+
# instance = bigtable.instance("my-instance")
|
|
664
|
+
#
|
|
665
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
|
|
666
|
+
#
|
|
667
|
+
# app_profile = instance.create_app_profile(
|
|
668
|
+
# "my-app-profile",
|
|
669
|
+
# routing_policy,
|
|
670
|
+
# description: "App profile for user data instance"
|
|
671
|
+
# )
|
|
672
|
+
# puts app_profile.name
|
|
673
|
+
#
|
|
674
|
+
# @example Create app profile and ignore warnings.
|
|
675
|
+
# require "google/cloud/bigtable"
|
|
676
|
+
#
|
|
677
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
678
|
+
#
|
|
679
|
+
# instance = bigtable.instance("my-instance")
|
|
680
|
+
#
|
|
681
|
+
# routing_policy = Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
|
|
682
|
+
#
|
|
683
|
+
# app_profile = instance.create_app_profile(
|
|
684
|
+
# "my-app-profile",
|
|
685
|
+
# routing_policy,
|
|
686
|
+
# description: "App profile for user data instance",
|
|
687
|
+
# ignore_warnings: true
|
|
688
|
+
# )
|
|
689
|
+
# puts app_profile.name
|
|
690
|
+
|
|
691
|
+
def create_app_profile \
|
|
692
|
+
name,
|
|
693
|
+
routing_policy,
|
|
694
|
+
description: nil,
|
|
695
|
+
etag: nil,
|
|
696
|
+
ignore_warnings: false
|
|
697
|
+
ensure_service!
|
|
698
|
+
|
|
699
|
+
if routing_policy.is_a?(Google::Bigtable::Admin::V2::AppProfile:: \
|
|
700
|
+
MultiClusterRoutingUseAny)
|
|
701
|
+
multi_cluster_routing = routing_policy
|
|
702
|
+
else
|
|
703
|
+
single_cluster_routing = routing_policy
|
|
704
|
+
end
|
|
705
|
+
|
|
706
|
+
app_profile_attrs = {
|
|
707
|
+
multi_cluster_routing_use_any: multi_cluster_routing,
|
|
708
|
+
single_cluster_routing: single_cluster_routing,
|
|
709
|
+
description: description,
|
|
710
|
+
etag: etag
|
|
711
|
+
}.delete_if { |_, v| v.nil? }
|
|
712
|
+
|
|
713
|
+
grpc = service.create_app_profile(
|
|
714
|
+
instance_id,
|
|
715
|
+
name,
|
|
716
|
+
Google::Bigtable::Admin::V2::AppProfile.new(app_profile_attrs),
|
|
717
|
+
ignore_warnings: ignore_warnings
|
|
718
|
+
)
|
|
719
|
+
AppProfile.from_grpc(grpc, service)
|
|
720
|
+
end
|
|
721
|
+
|
|
722
|
+
# Get app profile.
|
|
723
|
+
#
|
|
724
|
+
# See to delete app_profile {Google::Cloud::Bigtable::AppProfile#delete} and update
|
|
725
|
+
# app_profile {Google::Cloud::Bigtable::AppProfile#save}.
|
|
726
|
+
#
|
|
727
|
+
# @param app_profile_id [String] The unique name of the requested app profile.
|
|
728
|
+
# @return [Google::Cloud::Bigtable::AppProfile, nil]
|
|
729
|
+
#
|
|
730
|
+
# @example
|
|
731
|
+
# require "google/cloud/bigtable"
|
|
732
|
+
#
|
|
733
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
734
|
+
#
|
|
735
|
+
# instance = bigtable.instance("my-instance")
|
|
736
|
+
#
|
|
737
|
+
# app_profile = instance.app_profile("my-app-profile")
|
|
738
|
+
#
|
|
739
|
+
# if app_profile
|
|
740
|
+
# puts app_profile.name
|
|
741
|
+
# end
|
|
742
|
+
|
|
743
|
+
def app_profile app_profile_id
|
|
744
|
+
ensure_service!
|
|
745
|
+
grpc = service.get_app_profile(instance_id, app_profile_id)
|
|
746
|
+
AppProfile.from_grpc(grpc, service)
|
|
747
|
+
rescue Google::Cloud::NotFoundError
|
|
748
|
+
nil
|
|
749
|
+
end
|
|
750
|
+
|
|
751
|
+
# List all app profiles
|
|
752
|
+
#
|
|
753
|
+
# See to delete app_profile {Google::Cloud::Bigtable::AppProfile#delete} and update
|
|
754
|
+
# app_profile {Google::Cloud::Bigtable::AppProfile#save}.
|
|
755
|
+
#
|
|
756
|
+
# @return [Array<Google::Cloud::Bigtable::AppProfile>]
|
|
757
|
+
# (See {Google::Cloud::Bigtable::AppProfile::List})
|
|
758
|
+
#
|
|
759
|
+
# @example
|
|
760
|
+
# require "google/cloud/bigtable"
|
|
761
|
+
#
|
|
762
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
763
|
+
#
|
|
764
|
+
# instance = bigtable.instance("my-instance")
|
|
765
|
+
#
|
|
766
|
+
# instance.app_profiles.all do |app_profile|
|
|
767
|
+
# puts app_profile.name
|
|
768
|
+
# end
|
|
769
|
+
|
|
770
|
+
def app_profiles
|
|
771
|
+
ensure_service!
|
|
772
|
+
grpc = service.list_app_profiles(instance_id)
|
|
773
|
+
AppProfile::List.from_grpc(grpc, service)
|
|
774
|
+
end
|
|
775
|
+
|
|
776
|
+
# Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
|
|
777
|
+
# policy for this instance.
|
|
778
|
+
#
|
|
779
|
+
# @see https://cloud.google.com/bigtable/docs/access-control
|
|
780
|
+
#
|
|
781
|
+
# @yield [policy] A block for updating the policy. The latest policy
|
|
782
|
+
# will be read from the Bigtable service and passed to the block. After
|
|
783
|
+
# the block completes, the modified policy will be written to the
|
|
784
|
+
# service.
|
|
785
|
+
# @yieldparam [Policy] policy the current Cloud IAM Policy for this
|
|
786
|
+
# instance
|
|
787
|
+
#
|
|
788
|
+
# @return [Policy] The current Cloud IAM Policy for this instance.
|
|
789
|
+
#
|
|
790
|
+
# @example
|
|
791
|
+
# require "google/cloud/bigtable"
|
|
792
|
+
#
|
|
793
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
794
|
+
#
|
|
795
|
+
# instance = bigtable.instance("my-instance")
|
|
796
|
+
# policy = instance.policy
|
|
797
|
+
#
|
|
798
|
+
# @example Update the policy by passing a block:
|
|
799
|
+
# require "google/cloud/spanner"
|
|
800
|
+
#
|
|
801
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
802
|
+
# instance = bigtable.instance("my-instance")
|
|
803
|
+
#
|
|
804
|
+
# instance.policy do |p|
|
|
805
|
+
# p.add("roles/owner", "user:owner@example.com")
|
|
806
|
+
# end # 2 API calls
|
|
807
|
+
|
|
808
|
+
def policy
|
|
809
|
+
ensure_service!
|
|
810
|
+
grpc = service.get_instance_policy(instance_id)
|
|
811
|
+
policy = Policy.from_grpc(grpc)
|
|
812
|
+
return policy unless block_given?
|
|
813
|
+
yield policy
|
|
814
|
+
update_policy policy
|
|
815
|
+
end
|
|
816
|
+
|
|
817
|
+
# Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
|
|
818
|
+
# policy for this instance. The policy should be read from {#policy}.
|
|
819
|
+
# See {Google::Cloud::Bigtable::Policy} for an explanation of the policy
|
|
820
|
+
# `etag` property and how to modify policies.
|
|
821
|
+
#
|
|
822
|
+
# You can also update the policy by passing a block to {#policy}, which
|
|
823
|
+
# will call this method internally after the block completes.
|
|
824
|
+
#
|
|
825
|
+
# @param new_policy [Policy] a new or modified Cloud IAM Policy for this
|
|
826
|
+
# instance
|
|
827
|
+
#
|
|
828
|
+
# @return [Policy] The policy returned by the API update operation.
|
|
829
|
+
#
|
|
830
|
+
# @example
|
|
831
|
+
# require "google/cloud/bigtable"
|
|
832
|
+
#
|
|
833
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
834
|
+
#
|
|
835
|
+
# instance = bigtable.instance("my-instance")
|
|
836
|
+
#
|
|
837
|
+
# policy = instance.policy
|
|
838
|
+
# policy.add("roles/owner", "user:owner@example.com")
|
|
839
|
+
# updated_policy = instance.update_policy(policy)
|
|
840
|
+
#
|
|
841
|
+
# puts update_policy.roles
|
|
842
|
+
|
|
843
|
+
def update_policy new_policy
|
|
844
|
+
ensure_service!
|
|
845
|
+
grpc = service.set_instance_policy(instance_id, new_policy.to_grpc)
|
|
846
|
+
Policy.from_grpc(grpc)
|
|
847
|
+
end
|
|
848
|
+
alias policy= update_policy
|
|
849
|
+
|
|
850
|
+
# Tests the specified permissions against the [Cloud
|
|
851
|
+
# IAM](https://cloud.google.com/iam/) access control policy.
|
|
852
|
+
#
|
|
853
|
+
# @see https://cloud.google.com/iam/docs/managing-policies Managing
|
|
854
|
+
# Policies
|
|
855
|
+
#
|
|
856
|
+
# @param permissions [String, Array<String>] permissions The set of permissions to
|
|
857
|
+
# check access for. Permissions with wildcards (such as `*` or
|
|
858
|
+
# `bigtable.*`) are not allowed.
|
|
859
|
+
# See (https://cloud.google.com/bigtable/docs/access-control)
|
|
860
|
+
#
|
|
861
|
+
# Some of the permissions that can be checked on a instance are:
|
|
862
|
+
# * bigtable.instances.create
|
|
863
|
+
# * bigtable.instances.list
|
|
864
|
+
# * bigtable.instances.get
|
|
865
|
+
# * bigtable.tables.create
|
|
866
|
+
# * bigtable.tables.delete
|
|
867
|
+
# * bigtable.tables.get
|
|
868
|
+
# * bigtable.tables.list
|
|
869
|
+
#
|
|
870
|
+
# @return [Array<Strings>] The permissions that have access.
|
|
871
|
+
#
|
|
872
|
+
# @example
|
|
873
|
+
# require "google/cloud/bigtable"
|
|
874
|
+
#
|
|
875
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
876
|
+
#
|
|
877
|
+
# instance = bigtable.instance("my-instance")
|
|
878
|
+
#
|
|
879
|
+
# permissions = bigtable.test_permissions(
|
|
880
|
+
# "bigtable.instances.get",
|
|
881
|
+
# "bigtable.instances.update"
|
|
882
|
+
# )
|
|
883
|
+
# permissions.include? "bigtable.instances.get" #=> true
|
|
884
|
+
# permissions.include? "bigtable.instances.update" #=> false
|
|
885
|
+
|
|
886
|
+
def test_iam_permissions *permissions
|
|
887
|
+
ensure_service!
|
|
888
|
+
grpc = service.test_instance_permissions(
|
|
889
|
+
instance_id,
|
|
890
|
+
Array(permissions).flatten
|
|
891
|
+
)
|
|
892
|
+
grpc.permissions
|
|
893
|
+
end
|
|
894
|
+
|
|
895
|
+
# @private
|
|
896
|
+
#
|
|
897
|
+
# Creates a new Instance instance from a
|
|
898
|
+
# Google::Bigtable::Admin::V2::Instance.
|
|
899
|
+
#
|
|
900
|
+
# @param grpc [Google::Bigtable::Admin::V2::Instance]
|
|
901
|
+
# @param service [Google::Cloud::Bigtable::Service]
|
|
902
|
+
# @return [Google::Cloud::Bigtable::Instance]
|
|
903
|
+
|
|
904
|
+
def self.from_grpc grpc, service
|
|
905
|
+
new(grpc, service)
|
|
906
|
+
end
|
|
907
|
+
|
|
908
|
+
protected
|
|
909
|
+
|
|
910
|
+
# @private
|
|
911
|
+
#
|
|
912
|
+
# Raise an error unless an active connection to the service is
|
|
913
|
+
# available.
|
|
914
|
+
|
|
915
|
+
def ensure_service!
|
|
916
|
+
raise "Must have active connection to service" unless service
|
|
917
|
+
end
|
|
918
|
+
end
|
|
919
|
+
end
|
|
920
|
+
end
|
|
921
|
+
end
|