google-cloud-bigtable 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.yardopts +19 -0
- data/AUTHENTICATION.md +177 -0
- data/CHANGELOG.md +223 -0
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +188 -0
- data/EMULATOR.md +30 -0
- data/LICENSE +201 -0
- data/LOGGING.md +32 -0
- data/OVERVIEW.md +400 -0
- data/TROUBLESHOOTING.md +31 -0
- data/lib/google-cloud-bigtable.rb +171 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +145 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +90 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +208 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +154 -0
- data/lib/google/bigtable/admin/v2/common_pb.rb +30 -0
- data/lib/google/bigtable/admin/v2/instance_pb.rb +74 -0
- data/lib/google/bigtable/admin/v2/table_pb.rb +127 -0
- data/lib/google/bigtable/v2/bigtable_pb.rb +113 -0
- data/lib/google/bigtable/v2/bigtable_services_pb.rb +68 -0
- data/lib/google/bigtable/v2/data_pb.rb +156 -0
- data/lib/google/cloud/bigtable.rb +184 -0
- data/lib/google/cloud/bigtable/admin.rb +202 -0
- data/lib/google/cloud/bigtable/admin/credentials.rb +27 -0
- data/lib/google/cloud/bigtable/admin/v2.rb +223 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +1451 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +139 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1734 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +163 -0
- data/lib/google/cloud/bigtable/admin/v2/credentials.rb +51 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +297 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +587 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +193 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +303 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +64 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/options.rb +33 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +151 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +51 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +131 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +91 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +29 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +222 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +113 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +39 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/type/expr.rb +45 -0
- data/lib/google/cloud/bigtable/app_profile.rb +439 -0
- data/lib/google/cloud/bigtable/app_profile/job.rb +99 -0
- data/lib/google/cloud/bigtable/app_profile/list.rb +165 -0
- data/lib/google/cloud/bigtable/backup.rb +324 -0
- data/lib/google/cloud/bigtable/backup/job.rb +87 -0
- data/lib/google/cloud/bigtable/backup/list.rb +167 -0
- data/lib/google/cloud/bigtable/chunk_processor.rb +241 -0
- data/lib/google/cloud/bigtable/cluster.rb +390 -0
- data/lib/google/cloud/bigtable/cluster/job.rb +88 -0
- data/lib/google/cloud/bigtable/cluster/list.rb +171 -0
- data/lib/google/cloud/bigtable/column_family.rb +73 -0
- data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
- data/lib/google/cloud/bigtable/column_range.rb +194 -0
- data/lib/google/cloud/bigtable/convert.rb +83 -0
- data/lib/google/cloud/bigtable/credentials.rb +25 -0
- data/lib/google/cloud/bigtable/errors.rb +38 -0
- data/lib/google/cloud/bigtable/gc_rule.rb +334 -0
- data/lib/google/cloud/bigtable/instance.rb +935 -0
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +74 -0
- data/lib/google/cloud/bigtable/instance/job.rb +98 -0
- data/lib/google/cloud/bigtable/instance/list.rb +164 -0
- data/lib/google/cloud/bigtable/longrunning_job.rb +122 -0
- data/lib/google/cloud/bigtable/mutation_entry.rb +256 -0
- data/lib/google/cloud/bigtable/mutation_operations.rb +357 -0
- data/lib/google/cloud/bigtable/policy.rb +167 -0
- data/lib/google/cloud/bigtable/project.rb +471 -0
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +134 -0
- data/lib/google/cloud/bigtable/read_operations.rb +328 -0
- data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
- data/lib/google/cloud/bigtable/row.rb +136 -0
- data/lib/google/cloud/bigtable/row_filter.rb +639 -0
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +590 -0
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +114 -0
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +621 -0
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +287 -0
- data/lib/google/cloud/bigtable/row_range.rb +179 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +113 -0
- data/lib/google/cloud/bigtable/rows_reader.rb +200 -0
- data/lib/google/cloud/bigtable/sample_row_key.rb +85 -0
- data/lib/google/cloud/bigtable/service.rb +913 -0
- data/lib/google/cloud/bigtable/status.rb +76 -0
- data/lib/google/cloud/bigtable/table.rb +686 -0
- data/lib/google/cloud/bigtable/table/cluster_state.rb +125 -0
- data/lib/google/cloud/bigtable/table/list.rb +154 -0
- data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
- data/lib/google/cloud/bigtable/v2.rb +146 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client.rb +591 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +83 -0
- data/lib/google/cloud/bigtable/v2/credentials.rb +46 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +290 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +493 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +131 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +34 -0
- data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +39 -0
- data/lib/google/cloud/bigtable/value_range.rb +181 -0
- data/lib/google/cloud/bigtable/version.rb +22 -0
- metadata +337 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
# Copyright 2018 Google LLC
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
# you may not use this file except in compliance with the License.
|
|
5
|
+
# You may obtain a copy of the License at
|
|
6
|
+
#
|
|
7
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
#
|
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
# See the License for the specific language governing permissions and
|
|
13
|
+
# limitations under the License.
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
module Google
|
|
17
|
+
module Cloud
|
|
18
|
+
module Bigtable
|
|
19
|
+
##
|
|
20
|
+
# # Policy
|
|
21
|
+
#
|
|
22
|
+
# Represents a Cloud IAM Policy for Bigtable resources.
|
|
23
|
+
#
|
|
24
|
+
# A common pattern for updating a resource's metadata, such as its policy,
|
|
25
|
+
# is to read the current data from the service, update the data locally,
|
|
26
|
+
# and then write the modified data back to the resource. This pattern may
|
|
27
|
+
# result in a conflict if two or more processes attempt the sequence simultaneously.
|
|
28
|
+
# IAM solves this problem with the {Google::Cloud::Bigtable::Policy#etag}
|
|
29
|
+
# property, which is used to verify whether the policy has changed since
|
|
30
|
+
# the last request. When you make a request with an `etag` value, Cloud
|
|
31
|
+
# IAM compares the `etag` value in the request with the existing `etag`
|
|
32
|
+
# value associated with the policy. It writes the policy only if the
|
|
33
|
+
# `etag` values match.
|
|
34
|
+
#
|
|
35
|
+
# @see https://cloud.google.com/bigtable/docs/access-control Permissions and roles
|
|
36
|
+
#
|
|
37
|
+
# @attr [String] etag Used to check if the policy has changed since
|
|
38
|
+
# the last request. The policy will be written only if the `etag` values
|
|
39
|
+
# match.
|
|
40
|
+
# @attr [Hash{String => Array<String>}] roles The bindings that associate
|
|
41
|
+
# roles with an array of members. See [Understanding
|
|
42
|
+
# Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
|
|
43
|
+
# listing of primitive and curated roles.
|
|
44
|
+
#
|
|
45
|
+
# @example
|
|
46
|
+
# require "google/cloud/bigtable"
|
|
47
|
+
#
|
|
48
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
49
|
+
# instance = bigtable.instance "my-instance"
|
|
50
|
+
#
|
|
51
|
+
# policy = instance.policy
|
|
52
|
+
# policy.remove("roles/owner", "user:owner@example.com")
|
|
53
|
+
# policy.add("roles/owner", "user:newowner@example.com")
|
|
54
|
+
# policy.roles["roles/viewer"] = ["allUsers"]
|
|
55
|
+
#
|
|
56
|
+
class Policy
|
|
57
|
+
attr_reader :etag, :roles
|
|
58
|
+
|
|
59
|
+
# Creates a Policy instance.
|
|
60
|
+
# @param etag [String]
|
|
61
|
+
# @param roles [Array<String>]
|
|
62
|
+
def initialize etag, roles = nil
|
|
63
|
+
@etag = etag
|
|
64
|
+
@roles = roles
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
##
|
|
68
|
+
# Convenience method for adding a member to a binding on this policy.
|
|
69
|
+
# See [Understanding
|
|
70
|
+
# Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
|
|
71
|
+
# list of primitive and curated roles. See
|
|
72
|
+
# [Binding](https://cloud.google.com/bigtable/docs/access-control)
|
|
73
|
+
# for a list of values and patterns for members.
|
|
74
|
+
#
|
|
75
|
+
# @param [String] role_name A Cloud IAM role, such as
|
|
76
|
+
# `"roles/bigtable.admin"`.
|
|
77
|
+
# @param [String] member A Cloud IAM identity, such as
|
|
78
|
+
# `"user:owner@example.com"`.
|
|
79
|
+
#
|
|
80
|
+
# @example
|
|
81
|
+
# require "google/cloud/bigtable"
|
|
82
|
+
#
|
|
83
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
84
|
+
# instance = bigtable.instance "my-instance"
|
|
85
|
+
#
|
|
86
|
+
# policy = instance.policy
|
|
87
|
+
# policy.add("roles/owner", "user:newowner@example.com")
|
|
88
|
+
#
|
|
89
|
+
def add role_name, member
|
|
90
|
+
role(role_name) << member
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
##
|
|
94
|
+
# Convenience method for removing a member from a binding on this
|
|
95
|
+
# policy. See [Understanding
|
|
96
|
+
# Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
|
|
97
|
+
# list of primitive and curated roles.See
|
|
98
|
+
# [Binding](https://cloud.google.com/bigtable/docs/access-control)
|
|
99
|
+
# for a list of values and patterns for members.
|
|
100
|
+
#
|
|
101
|
+
# @param [String] role_name A Cloud IAM role, such as
|
|
102
|
+
# `"roles/Bigtable.admin"`.
|
|
103
|
+
# @param [String] member A Cloud IAM identity, such as
|
|
104
|
+
# `"user:owner@example.com"`.
|
|
105
|
+
#
|
|
106
|
+
# @example
|
|
107
|
+
# require "google/cloud/bigtable"
|
|
108
|
+
#
|
|
109
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
110
|
+
# instance = bigtable.instance "my-instance"
|
|
111
|
+
#
|
|
112
|
+
# policy = instance.policy
|
|
113
|
+
# policy.remove("roles/owner", "user:newowner@example.com")
|
|
114
|
+
#
|
|
115
|
+
def remove role_name, member
|
|
116
|
+
role(role_name).delete member
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
##
|
|
120
|
+
# Convenience method returning the array of members bound to a role in
|
|
121
|
+
# this policy. Returns an empty array if no value is present for the role in
|
|
122
|
+
# {#roles}. See [Understanding
|
|
123
|
+
# Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
|
|
124
|
+
# list of primitive and curated roles. See
|
|
125
|
+
# [Binding](https://cloud.google.com/bigtable/docs/access-control)
|
|
126
|
+
# for a list of values and patterns for members.
|
|
127
|
+
#
|
|
128
|
+
# @return [Array<String>] The members strings, or an empty array.
|
|
129
|
+
#
|
|
130
|
+
# @example
|
|
131
|
+
# require "google/cloud/bigtable"
|
|
132
|
+
#
|
|
133
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
134
|
+
# instance = bigtable.instance "my-instance"
|
|
135
|
+
#
|
|
136
|
+
# policy = instance.policy
|
|
137
|
+
# policy.role("roles/viewer") << "user:viewer@example.com"
|
|
138
|
+
#
|
|
139
|
+
def role role_name
|
|
140
|
+
roles[role_name] ||= []
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
# @private
|
|
144
|
+
# Convert the Policy to a Google::Iam::V1::Policy object.
|
|
145
|
+
def to_grpc
|
|
146
|
+
bindings = roles.keys.map do |role_name|
|
|
147
|
+
next if roles[role_name].empty?
|
|
148
|
+
Google::Iam::V1::Binding.new(
|
|
149
|
+
role: role_name,
|
|
150
|
+
members: roles[role_name]
|
|
151
|
+
)
|
|
152
|
+
end
|
|
153
|
+
Google::Iam::V1::Policy.new etag: etag, bindings: bindings
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
# @private
|
|
157
|
+
# New Policy from a Google::Iam::V1::Policy object.
|
|
158
|
+
def self.from_grpc grpc
|
|
159
|
+
roles = grpc.bindings.each_with_object({}) do |binding, memo|
|
|
160
|
+
memo[binding.role] = binding.members.to_a
|
|
161
|
+
end
|
|
162
|
+
new grpc.etag, roles
|
|
163
|
+
end
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
@@ -0,0 +1,471 @@
|
|
|
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/errors"
|
|
19
|
+
require "google/cloud/bigtable/longrunning_job"
|
|
20
|
+
require "google/cloud/bigtable/convert"
|
|
21
|
+
require "google/cloud/bigtable/service"
|
|
22
|
+
require "google/cloud/bigtable/instance"
|
|
23
|
+
require "google/cloud/bigtable/cluster"
|
|
24
|
+
require "google/cloud/bigtable/table"
|
|
25
|
+
|
|
26
|
+
module Google
|
|
27
|
+
module Cloud
|
|
28
|
+
module Bigtable
|
|
29
|
+
##
|
|
30
|
+
# # Project
|
|
31
|
+
#
|
|
32
|
+
# Projects are top-level containers in Google Cloud Platform. They store
|
|
33
|
+
# information about billing and authorized users, and they contain
|
|
34
|
+
# Cloud Bigtable data. Each project has a friendly name and a unique ID.
|
|
35
|
+
#
|
|
36
|
+
# `Google::Cloud::Bigtable::Project` is the main object for interacting with
|
|
37
|
+
# Cloud Bigtable.
|
|
38
|
+
#
|
|
39
|
+
# {Google::Cloud::Bigtable::Cluster} and {Google::Cloud::Bigtable::Instance}
|
|
40
|
+
# objects are created, accessed, and managed by Google::Cloud::Bigtable::Project.
|
|
41
|
+
#
|
|
42
|
+
# To create a `Project` instance, use {Google::Cloud::Bigtable.new}.
|
|
43
|
+
#
|
|
44
|
+
# @example Obtaining an instance and the clusters from a project.
|
|
45
|
+
# require "google/cloud/bigtable"
|
|
46
|
+
#
|
|
47
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
48
|
+
#
|
|
49
|
+
# instance = bigtable.instance("my-instance")
|
|
50
|
+
# clusters = bigtable.clusters # All clusters in the project
|
|
51
|
+
#
|
|
52
|
+
class Project
|
|
53
|
+
# @private
|
|
54
|
+
# The Service object
|
|
55
|
+
attr_accessor :service
|
|
56
|
+
|
|
57
|
+
# @private
|
|
58
|
+
# Creates a new Bigtable Project instance.
|
|
59
|
+
# @param service [Google::Cloud::Bigtable::Service]
|
|
60
|
+
def initialize service
|
|
61
|
+
@service = service
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
##
|
|
65
|
+
# The identifier for the Cloud Bigtable project.
|
|
66
|
+
#
|
|
67
|
+
# @return [String] Project ID.
|
|
68
|
+
#
|
|
69
|
+
# @example
|
|
70
|
+
# require "google/cloud/bigtable"
|
|
71
|
+
#
|
|
72
|
+
# bigtable = Google::Cloud::Bigtable.new(
|
|
73
|
+
# project_id: "my-project",
|
|
74
|
+
# credentials: "/path/to/keyfile.json"
|
|
75
|
+
# )
|
|
76
|
+
#
|
|
77
|
+
# bigtable.project_id #=> "my-project"
|
|
78
|
+
#
|
|
79
|
+
def project_id
|
|
80
|
+
ensure_service!
|
|
81
|
+
service.project_id
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
##
|
|
85
|
+
# Retrieves the list of Bigtable instances for the project.
|
|
86
|
+
#
|
|
87
|
+
# @param token [String] The `token` value returned by the last call to
|
|
88
|
+
# `instances`; indicates that this is a continuation of a call
|
|
89
|
+
# and that the system should return the next page of data.
|
|
90
|
+
# @return [Array<Google::Cloud::Bigtable::Instance>] The list of instances.
|
|
91
|
+
# (See {Google::Cloud::Bigtable::Instance::List})
|
|
92
|
+
#
|
|
93
|
+
# @example
|
|
94
|
+
# require "google/cloud/bigtable"
|
|
95
|
+
#
|
|
96
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
97
|
+
#
|
|
98
|
+
# instances = bigtable.instances
|
|
99
|
+
# instances.all do |instance|
|
|
100
|
+
# puts instance.instance_id
|
|
101
|
+
# end
|
|
102
|
+
#
|
|
103
|
+
def instances token: nil
|
|
104
|
+
ensure_service!
|
|
105
|
+
grpc = service.list_instances token: token
|
|
106
|
+
Instance::List.from_grpc grpc, service
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
##
|
|
110
|
+
# Gets an existing Bigtable instance.
|
|
111
|
+
#
|
|
112
|
+
# @param instance_id [String] Existing instance ID.
|
|
113
|
+
# @return [Google::Cloud::Bigtable::Instance, nil]
|
|
114
|
+
#
|
|
115
|
+
# @example
|
|
116
|
+
# require "google/cloud/bigtable"
|
|
117
|
+
#
|
|
118
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
119
|
+
#
|
|
120
|
+
# instance = bigtable.instance("my-instance")
|
|
121
|
+
#
|
|
122
|
+
# if instance
|
|
123
|
+
# puts instance.instance_id
|
|
124
|
+
# end
|
|
125
|
+
#
|
|
126
|
+
def instance instance_id
|
|
127
|
+
ensure_service!
|
|
128
|
+
grpc = service.get_instance instance_id
|
|
129
|
+
Instance.from_grpc grpc, service
|
|
130
|
+
rescue Google::Cloud::NotFoundError
|
|
131
|
+
nil
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
##
|
|
135
|
+
# Creates a Bigtable instance.
|
|
136
|
+
#
|
|
137
|
+
# @see https://cloud.google.com/compute/docs/regions-zones Cluster zone locations
|
|
138
|
+
#
|
|
139
|
+
# @param instance_id [String] The unique identifier for the instance,
|
|
140
|
+
# which cannot be changed after the instance is created. Values are of
|
|
141
|
+
# the form `[a-z][-a-z0-9]*[a-z0-9]` and must be between 6 and 30
|
|
142
|
+
# characters. Required.
|
|
143
|
+
# @param display_name [String] The descriptive name for this instance as it
|
|
144
|
+
# appears in UIs. Must be unique per project and between 4 and 30
|
|
145
|
+
# characters.
|
|
146
|
+
# @param type [Symbol] The type of the instance. When creating a development instance,
|
|
147
|
+
# `nodes` on the cluster must not be set.
|
|
148
|
+
# Valid values are `:DEVELOPMENT` or `:PRODUCTION`. Default is `:PRODUCTION`.
|
|
149
|
+
# @param labels [Hash{String=>String}] labels Cloud Labels are a flexible and lightweight
|
|
150
|
+
# mechanism for organizing cloud resources into groups that reflect a
|
|
151
|
+
# customer's organizational needs and deployment strategies. Cloud
|
|
152
|
+
# Labels can be used to filter collections of resources. They can be
|
|
153
|
+
# used to control how resource metrics are aggregated. Cloud Labels can be
|
|
154
|
+
# used as arguments to policy management rules (e.g., route, firewall, or
|
|
155
|
+
# load balancing).
|
|
156
|
+
#
|
|
157
|
+
# * Label keys must be between 1 and 63 characters and must
|
|
158
|
+
# conform to the following regular expression:
|
|
159
|
+
# `[a-z]([-a-z0-9]*[a-z0-9])?`.
|
|
160
|
+
# * Label values must be between 0 and 63 characters and must
|
|
161
|
+
# conform to the regular expression `([a-z]([-a-z0-9]*[a-z0-9])?)?`.
|
|
162
|
+
# * No more than 64 labels can be associated with a given resource.
|
|
163
|
+
# @param clusters [Hash{String => Google::Cloud::Bigtable::Cluster}]
|
|
164
|
+
# (See {Google::Cloud::Bigtable::Instance::ClusterMap})
|
|
165
|
+
# If unspecified, you may use a code block to add clusters.
|
|
166
|
+
# Minimum of one cluster must be specified.
|
|
167
|
+
# @yield [clusters] A block for adding clusters.
|
|
168
|
+
# @yieldparam [Hash{String => Google::Cloud::Bigtable::Cluster}]
|
|
169
|
+
# Cluster map of cluster name and cluster object.
|
|
170
|
+
# (See {Google::Cloud::Bigtable::Instance::ClusterMap})
|
|
171
|
+
# @return [Google::Cloud::Bigtable::Instance::Job]
|
|
172
|
+
# The job representing the long-running, asynchronous processing of
|
|
173
|
+
# an instance create operation.
|
|
174
|
+
#
|
|
175
|
+
# @example Create a development instance.
|
|
176
|
+
# require "google/cloud/bigtable"
|
|
177
|
+
#
|
|
178
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
179
|
+
#
|
|
180
|
+
# job = bigtable.create_instance(
|
|
181
|
+
# "my-instance",
|
|
182
|
+
# display_name: "Instance for user data",
|
|
183
|
+
# type: :DEVELOPMENT,
|
|
184
|
+
# labels: { "env" => "dev"}
|
|
185
|
+
# ) do |clusters|
|
|
186
|
+
# clusters.add("test-cluster", "us-east1-b") # nodes not allowed
|
|
187
|
+
# end
|
|
188
|
+
#
|
|
189
|
+
# job.done? #=> false
|
|
190
|
+
#
|
|
191
|
+
# # Reload job until completion.
|
|
192
|
+
# job.wait_until_done!
|
|
193
|
+
# job.done? #=> true
|
|
194
|
+
#
|
|
195
|
+
# if job.error?
|
|
196
|
+
# status = job.error
|
|
197
|
+
# else
|
|
198
|
+
# instance = job.instance
|
|
199
|
+
# end
|
|
200
|
+
#
|
|
201
|
+
# @example Create a production instance.
|
|
202
|
+
# require "google/cloud/bigtable"
|
|
203
|
+
#
|
|
204
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
205
|
+
#
|
|
206
|
+
# job = bigtable.create_instance(
|
|
207
|
+
# "my-instance",
|
|
208
|
+
# display_name: "Instance for user data",
|
|
209
|
+
# labels: { "env" => "dev"}
|
|
210
|
+
# ) do |clusters|
|
|
211
|
+
# clusters.add("test-cluster", "us-east1-b", nodes: 3, storage_type: :SSD)
|
|
212
|
+
# end
|
|
213
|
+
#
|
|
214
|
+
# job.done? #=> false
|
|
215
|
+
#
|
|
216
|
+
# # To block until the operation completes.
|
|
217
|
+
# job.wait_until_done!
|
|
218
|
+
# job.done? #=> true
|
|
219
|
+
#
|
|
220
|
+
# if job.error?
|
|
221
|
+
# status = job.error
|
|
222
|
+
# else
|
|
223
|
+
# instance = job.instance
|
|
224
|
+
# end
|
|
225
|
+
#
|
|
226
|
+
def create_instance instance_id, display_name: nil, type: nil, labels: nil, clusters: nil
|
|
227
|
+
labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels
|
|
228
|
+
|
|
229
|
+
instance_attrs = { display_name: display_name, type: type, labels: labels }.delete_if { |_, v| v.nil? }
|
|
230
|
+
instance = Google::Bigtable::Admin::V2::Instance.new instance_attrs
|
|
231
|
+
clusters ||= Instance::ClusterMap.new
|
|
232
|
+
yield clusters if block_given?
|
|
233
|
+
|
|
234
|
+
clusters.each_value do |cluster|
|
|
235
|
+
cluster.location = service.location_path cluster.location unless cluster.location == ""
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
grpc = service.create_instance instance_id, instance, clusters.to_h
|
|
239
|
+
Instance::Job.from_grpc grpc, service
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
##
|
|
243
|
+
# Lists all clusters in the project.
|
|
244
|
+
#
|
|
245
|
+
# @param token [String] The `token` value returned by the last call to
|
|
246
|
+
# `clusters` indicates that this is a continuation of a call
|
|
247
|
+
# and the system should return the next page of data.
|
|
248
|
+
# @return [Array<Google::Cloud::Bigtable::Cluster>]
|
|
249
|
+
# (See {Google::Cloud::Bigtable::Cluster::List})
|
|
250
|
+
# @example
|
|
251
|
+
# require "google/cloud/bigtable"
|
|
252
|
+
#
|
|
253
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
254
|
+
#
|
|
255
|
+
# bigtable.clusters.all do |cluster|
|
|
256
|
+
# puts cluster.cluster_id
|
|
257
|
+
# puts cluster.ready?
|
|
258
|
+
# end
|
|
259
|
+
#
|
|
260
|
+
def clusters token: nil
|
|
261
|
+
ensure_service!
|
|
262
|
+
grpc = service.list_clusters "-", token: token
|
|
263
|
+
Cluster::List.from_grpc grpc, service, instance_id: "-"
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
##
|
|
267
|
+
# Lists all tables for the given instance.
|
|
268
|
+
#
|
|
269
|
+
# @param instance_id [String] Existing instance Id.
|
|
270
|
+
# @return [Array<Google::Cloud::Bigtable::Table>]
|
|
271
|
+
# (See {Google::Cloud::Bigtable::Table::List})
|
|
272
|
+
#
|
|
273
|
+
# @example
|
|
274
|
+
# require "google/cloud/bigtable"
|
|
275
|
+
#
|
|
276
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
277
|
+
#
|
|
278
|
+
# bigtable.tables("my-instance").all do |table|
|
|
279
|
+
# puts table.name
|
|
280
|
+
# puts table.column_families
|
|
281
|
+
# end
|
|
282
|
+
#
|
|
283
|
+
def tables instance_id
|
|
284
|
+
ensure_service!
|
|
285
|
+
grpc = service.list_tables instance_id
|
|
286
|
+
Table::List.from_grpc grpc, service
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
##
|
|
290
|
+
# Returns a table representation. If `perform_lookup` is `false` (the default), a sparse representation will be
|
|
291
|
+
# returned without performing an RPC and without verifying that the table resource exists.
|
|
292
|
+
#
|
|
293
|
+
# @param instance_id [String] Existing instance Id.
|
|
294
|
+
# @param table_id [String] Existing table Id.
|
|
295
|
+
# @param view [Symbol] Optional. Table view type. Default `:SCHEMA_VIEW`
|
|
296
|
+
# Valid view types are the following:
|
|
297
|
+
# * `:NAME_ONLY` - Only populates `name`
|
|
298
|
+
# * `:SCHEMA_VIEW` - Only populates `name` and fields related to the table's schema
|
|
299
|
+
# * `:REPLICATION_VIEW` - Only populates `name` and fields related to the table's replication state.
|
|
300
|
+
# * `:FULL` - Populates all fields
|
|
301
|
+
# @param perform_lookup [Boolean]
|
|
302
|
+
# Get table object without verifying that the table resource exists.
|
|
303
|
+
# Calls made on this object will raise errors if the table does not exist.
|
|
304
|
+
# Default value is `false`. Optional.
|
|
305
|
+
# Helps to reduce admin API calls.
|
|
306
|
+
# @param app_profile_id [String] The unique identifier for the app profile. Optional.
|
|
307
|
+
# Used only in data operations.
|
|
308
|
+
# This value specifies routing for replication. If not specified, the
|
|
309
|
+
# "default" application profile will be used.
|
|
310
|
+
# @return [Google::Cloud::Bigtable::Table, nil]
|
|
311
|
+
#
|
|
312
|
+
# @example Get a sparse table representation without performing an RPC.
|
|
313
|
+
# require "google/cloud/bigtable"
|
|
314
|
+
#
|
|
315
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
316
|
+
#
|
|
317
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
318
|
+
#
|
|
319
|
+
# @example Get a table with schema-only view.
|
|
320
|
+
# require "google/cloud/bigtable"
|
|
321
|
+
#
|
|
322
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
323
|
+
#
|
|
324
|
+
# table = bigtable.table("my-instance", "my-table", perform_lookup: true, view: :SCHEMA_VIEW)
|
|
325
|
+
# if table
|
|
326
|
+
# puts table.name
|
|
327
|
+
# puts table.column_families
|
|
328
|
+
# end
|
|
329
|
+
#
|
|
330
|
+
# @example Get a table with all fields, cluster states, and column families.
|
|
331
|
+
# require "google/cloud/bigtable"
|
|
332
|
+
#
|
|
333
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
334
|
+
#
|
|
335
|
+
# table = bigtable.table("my-instance", "my-table", view: :FULL, perform_lookup: true)
|
|
336
|
+
# if table
|
|
337
|
+
# puts table.name
|
|
338
|
+
# puts table.column_families
|
|
339
|
+
# puts table.cluster_states
|
|
340
|
+
# end
|
|
341
|
+
#
|
|
342
|
+
def table instance_id, table_id, view: nil, perform_lookup: nil, app_profile_id: nil
|
|
343
|
+
ensure_service!
|
|
344
|
+
|
|
345
|
+
table = if perform_lookup
|
|
346
|
+
grpc = service.get_table instance_id, table_id, view: view
|
|
347
|
+
Table.from_grpc grpc, service, view: view
|
|
348
|
+
else
|
|
349
|
+
Table.from_path service.table_path(instance_id, table_id), service
|
|
350
|
+
end
|
|
351
|
+
|
|
352
|
+
table.app_profile_id = app_profile_id
|
|
353
|
+
table
|
|
354
|
+
rescue Google::Cloud::NotFoundError
|
|
355
|
+
nil
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
##
|
|
359
|
+
# Creates a new table in the specified instance.
|
|
360
|
+
# The table can be created with a full set of initial column families,
|
|
361
|
+
# specified in the request.
|
|
362
|
+
#
|
|
363
|
+
# @param instance_id [String]
|
|
364
|
+
# The unique ID of the instance in which to create the table.
|
|
365
|
+
# @param table_id [String]
|
|
366
|
+
# The ID by which the new table should be referred to within the
|
|
367
|
+
# instance, e.g., `foobar`.
|
|
368
|
+
# @param column_families [Google::Cloud::Bigtable::ColumnFamilyMap]
|
|
369
|
+
# An object containing the column families for the table, mapped by
|
|
370
|
+
# column family name.
|
|
371
|
+
# @param granularity [Symbol]
|
|
372
|
+
# The granularity at which timestamps are stored in this table.
|
|
373
|
+
# Timestamps not matching the granularity will be rejected.
|
|
374
|
+
# Valid value is `:MILLIS`.
|
|
375
|
+
# If unspecified, the value will be set to `:MILLIS`.
|
|
376
|
+
# @param initial_splits [Array<String>]
|
|
377
|
+
# The optional list of row keys that will be used to initially split the
|
|
378
|
+
# table into several tablets (tablets are similar to HBase regions).
|
|
379
|
+
# Given two split keys, `s1` and `s2`, three tablets will be created,
|
|
380
|
+
# spanning the key ranges: `[, s1), [s1, s2), [s2, )`.
|
|
381
|
+
#
|
|
382
|
+
# Example:
|
|
383
|
+
#
|
|
384
|
+
# * Row keys := `["a", "apple", "custom", "customer_1", "customer_2", "other", "zz"]`
|
|
385
|
+
# * initial_split_keys := `["apple", "customer_1", "customer_2", "other"]`
|
|
386
|
+
# * Key assignment:
|
|
387
|
+
# * Tablet 1 : `[, apple) => {"a"}`
|
|
388
|
+
# * Tablet 2 : `[apple, customer_1) => {"apple", "custom"}`
|
|
389
|
+
# * Tablet 3 : `[customer_1, customer_2) => {"customer_1"}`
|
|
390
|
+
# * Tablet 4 : `[customer_2, other) => {"customer_2"}`
|
|
391
|
+
# * Tablet 5 : `[other, ) => {"other", "zz"}`
|
|
392
|
+
# @yield [column_families] A block for adding column families.
|
|
393
|
+
# @yieldparam [Google::Cloud::Bigtable::ColumnFamilyMap] column_families
|
|
394
|
+
# A mutable object containing the column families for the table,
|
|
395
|
+
# mapped by column family name.
|
|
396
|
+
#
|
|
397
|
+
# @return [Google::Cloud::Bigtable::Table]
|
|
398
|
+
#
|
|
399
|
+
# @example Create a table without column families.
|
|
400
|
+
# require "google/cloud/bigtable"
|
|
401
|
+
#
|
|
402
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
403
|
+
#
|
|
404
|
+
# table = bigtable.create_table("my-instance", "my-table")
|
|
405
|
+
# puts table.name
|
|
406
|
+
#
|
|
407
|
+
# @example Create a table with initial splits and column families.
|
|
408
|
+
# require "google/cloud/bigtable"
|
|
409
|
+
#
|
|
410
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
411
|
+
#
|
|
412
|
+
# initial_splits = ["user-00001", "user-100000", "others"]
|
|
413
|
+
# table = bigtable.create_table("my-instance", "my-table", initial_splits: initial_splits) do |cfm|
|
|
414
|
+
# cfm.add('cf1', gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
|
|
415
|
+
# cfm.add('cf2', gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
|
|
416
|
+
#
|
|
417
|
+
# gc_rule = Google::Cloud::Bigtable::GcRule.union(
|
|
418
|
+
# Google::Cloud::Bigtable::GcRule.max_age(1800),
|
|
419
|
+
# Google::Cloud::Bigtable::GcRule.max_versions(3)
|
|
420
|
+
# )
|
|
421
|
+
# cfm.add('cf3', gc_rule: gc_rule)
|
|
422
|
+
# end
|
|
423
|
+
#
|
|
424
|
+
# puts table
|
|
425
|
+
#
|
|
426
|
+
def create_table instance_id, table_id, column_families: nil, granularity: nil, initial_splits: nil, &block
|
|
427
|
+
ensure_service!
|
|
428
|
+
Table.create(
|
|
429
|
+
service,
|
|
430
|
+
instance_id,
|
|
431
|
+
table_id,
|
|
432
|
+
column_families: column_families,
|
|
433
|
+
granularity: granularity,
|
|
434
|
+
initial_splits: initial_splits,
|
|
435
|
+
&block
|
|
436
|
+
)
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
##
|
|
440
|
+
# Permanently deletes the specified table and all of its data.
|
|
441
|
+
#
|
|
442
|
+
# @param instance_id [String]
|
|
443
|
+
# The unique ID of the instance the table is in.
|
|
444
|
+
# @param table_id [String]
|
|
445
|
+
# The unique ID of the table to be deleted.
|
|
446
|
+
#
|
|
447
|
+
# @example
|
|
448
|
+
# require "google/cloud/bigtable"
|
|
449
|
+
#
|
|
450
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
451
|
+
#
|
|
452
|
+
# bigtable.delete_table("my-instance", "my-table")
|
|
453
|
+
#
|
|
454
|
+
def delete_table instance_id, table_id
|
|
455
|
+
service.delete_table instance_id, table_id
|
|
456
|
+
true
|
|
457
|
+
end
|
|
458
|
+
|
|
459
|
+
protected
|
|
460
|
+
|
|
461
|
+
# @private
|
|
462
|
+
#
|
|
463
|
+
# Raise an error unless an active connection to the service is
|
|
464
|
+
# available.
|
|
465
|
+
def ensure_service!
|
|
466
|
+
raise "Must have active connection to service" unless service
|
|
467
|
+
end
|
|
468
|
+
end
|
|
469
|
+
end
|
|
470
|
+
end
|
|
471
|
+
end
|