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.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +19 -0
  3. data/AUTHENTICATION.md +177 -0
  4. data/CHANGELOG.md +223 -0
  5. data/CODE_OF_CONDUCT.md +40 -0
  6. data/CONTRIBUTING.md +188 -0
  7. data/EMULATOR.md +30 -0
  8. data/LICENSE +201 -0
  9. data/LOGGING.md +32 -0
  10. data/OVERVIEW.md +400 -0
  11. data/TROUBLESHOOTING.md +31 -0
  12. data/lib/google-cloud-bigtable.rb +171 -0
  13. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +145 -0
  14. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +90 -0
  15. data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +208 -0
  16. data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +154 -0
  17. data/lib/google/bigtable/admin/v2/common_pb.rb +30 -0
  18. data/lib/google/bigtable/admin/v2/instance_pb.rb +74 -0
  19. data/lib/google/bigtable/admin/v2/table_pb.rb +127 -0
  20. data/lib/google/bigtable/v2/bigtable_pb.rb +113 -0
  21. data/lib/google/bigtable/v2/bigtable_services_pb.rb +68 -0
  22. data/lib/google/bigtable/v2/data_pb.rb +156 -0
  23. data/lib/google/cloud/bigtable.rb +184 -0
  24. data/lib/google/cloud/bigtable/admin.rb +202 -0
  25. data/lib/google/cloud/bigtable/admin/credentials.rb +27 -0
  26. data/lib/google/cloud/bigtable/admin/v2.rb +223 -0
  27. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +1451 -0
  28. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +139 -0
  29. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1734 -0
  30. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +163 -0
  31. data/lib/google/cloud/bigtable/admin/v2/credentials.rb +51 -0
  32. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +297 -0
  33. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +587 -0
  34. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +193 -0
  35. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +303 -0
  36. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +64 -0
  37. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/options.rb +33 -0
  38. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +151 -0
  39. data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +51 -0
  40. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +131 -0
  41. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +91 -0
  42. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +29 -0
  43. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +222 -0
  44. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +113 -0
  45. data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +39 -0
  46. data/lib/google/cloud/bigtable/admin/v2/doc/google/type/expr.rb +45 -0
  47. data/lib/google/cloud/bigtable/app_profile.rb +439 -0
  48. data/lib/google/cloud/bigtable/app_profile/job.rb +99 -0
  49. data/lib/google/cloud/bigtable/app_profile/list.rb +165 -0
  50. data/lib/google/cloud/bigtable/backup.rb +324 -0
  51. data/lib/google/cloud/bigtable/backup/job.rb +87 -0
  52. data/lib/google/cloud/bigtable/backup/list.rb +167 -0
  53. data/lib/google/cloud/bigtable/chunk_processor.rb +241 -0
  54. data/lib/google/cloud/bigtable/cluster.rb +390 -0
  55. data/lib/google/cloud/bigtable/cluster/job.rb +88 -0
  56. data/lib/google/cloud/bigtable/cluster/list.rb +171 -0
  57. data/lib/google/cloud/bigtable/column_family.rb +73 -0
  58. data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
  59. data/lib/google/cloud/bigtable/column_range.rb +194 -0
  60. data/lib/google/cloud/bigtable/convert.rb +83 -0
  61. data/lib/google/cloud/bigtable/credentials.rb +25 -0
  62. data/lib/google/cloud/bigtable/errors.rb +38 -0
  63. data/lib/google/cloud/bigtable/gc_rule.rb +334 -0
  64. data/lib/google/cloud/bigtable/instance.rb +935 -0
  65. data/lib/google/cloud/bigtable/instance/cluster_map.rb +74 -0
  66. data/lib/google/cloud/bigtable/instance/job.rb +98 -0
  67. data/lib/google/cloud/bigtable/instance/list.rb +164 -0
  68. data/lib/google/cloud/bigtable/longrunning_job.rb +122 -0
  69. data/lib/google/cloud/bigtable/mutation_entry.rb +256 -0
  70. data/lib/google/cloud/bigtable/mutation_operations.rb +357 -0
  71. data/lib/google/cloud/bigtable/policy.rb +167 -0
  72. data/lib/google/cloud/bigtable/project.rb +471 -0
  73. data/lib/google/cloud/bigtable/read_modify_write_rule.rb +134 -0
  74. data/lib/google/cloud/bigtable/read_operations.rb +328 -0
  75. data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
  76. data/lib/google/cloud/bigtable/row.rb +136 -0
  77. data/lib/google/cloud/bigtable/row_filter.rb +639 -0
  78. data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +590 -0
  79. data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +114 -0
  80. data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +621 -0
  81. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +287 -0
  82. data/lib/google/cloud/bigtable/row_range.rb +179 -0
  83. data/lib/google/cloud/bigtable/rows_mutator.rb +113 -0
  84. data/lib/google/cloud/bigtable/rows_reader.rb +200 -0
  85. data/lib/google/cloud/bigtable/sample_row_key.rb +85 -0
  86. data/lib/google/cloud/bigtable/service.rb +913 -0
  87. data/lib/google/cloud/bigtable/status.rb +76 -0
  88. data/lib/google/cloud/bigtable/table.rb +686 -0
  89. data/lib/google/cloud/bigtable/table/cluster_state.rb +125 -0
  90. data/lib/google/cloud/bigtable/table/list.rb +154 -0
  91. data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
  92. data/lib/google/cloud/bigtable/v2.rb +146 -0
  93. data/lib/google/cloud/bigtable/v2/bigtable_client.rb +591 -0
  94. data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +83 -0
  95. data/lib/google/cloud/bigtable/v2/credentials.rb +46 -0
  96. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +290 -0
  97. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +493 -0
  98. data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +131 -0
  99. data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +34 -0
  100. data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +39 -0
  101. data/lib/google/cloud/bigtable/value_range.rb +181 -0
  102. data/lib/google/cloud/bigtable/version.rb +22 -0
  103. metadata +337 -0
@@ -0,0 +1,74 @@
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
+ module Google
19
+ module Cloud
20
+ module Bigtable
21
+ class Instance
22
+ ##
23
+ # Instance::ClusterMap is a hash with cluster ID keys and cluster configuration values.
24
+ # It is used to create a cluster.
25
+ #
26
+ # @example
27
+ #
28
+ # clusters = Google::Cloud::Bigtable::Instance::ClusterMap.new
29
+ #
30
+ # clusters.add("cluster-1", "us-east1-b", nodes: 3, storage_type: :SSD)
31
+ #
32
+ # # Or
33
+ # clusters.add("cluster-2", "us-east1-b")
34
+ #
35
+ class ClusterMap < DelegateClass(::Hash)
36
+ # @private
37
+ #
38
+ # Creates a new Instance::ClusterMap with an hash of Cluster name and
39
+ # cluster grpc instances.
40
+ def initialize value = {}
41
+ super value
42
+ end
43
+
44
+ ##
45
+ # Adds a cluster to the cluster map.
46
+ #
47
+ # @param name [String] The unique identifier for the cluster.
48
+ # @param location [String]
49
+ # The location where this cluster's nodes and storage reside. For best
50
+ # performance, clients should be located as close as possible to this
51
+ # cluster. Currently only zones are supported.
52
+ # @param nodes [Integer] Number of nodes for the cluster. When creating
53
+ # an instance of type `:DEVELOPMENT`, `nodes` must not be set.
54
+ # @param storage_type [Symbol]
55
+ # Valid values are:
56
+ # * `:SSD`(Flash (SSD) storage should be used),
57
+ # *`:HDD`(Magnetic drive (HDD) storage should be used)
58
+ #
59
+ # If not set then default will set to `:STORAGE_TYPE_UNSPECIFIED`
60
+ #
61
+ def add name, location, nodes: nil, storage_type: nil
62
+ attrs = {
63
+ serve_nodes: nodes,
64
+ location: location,
65
+ default_storage_type: storage_type
66
+ }.delete_if { |_, v| v.nil? }
67
+
68
+ self[name] = Google::Bigtable::Admin::V2::Cluster.new attrs
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,98 @@
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
+ class Instance
20
+ ##
21
+ # # Job
22
+ #
23
+ # A resource representing the long-running, asynchronous processing of
24
+ # an instance create or update operation. The job can be refreshed to
25
+ # retrieve the instance object once the operation has been completed.
26
+ #
27
+ # See {Project#create_instance} and {Instance#update}.
28
+ #
29
+ # @see https://cloud.google.com/bigtable/docs/reference/admin/rpc/google.longrunning#google.longrunning.Operation
30
+ # Long-running Operation
31
+ #
32
+ # @example
33
+ # require "google/cloud/bigtable"
34
+ #
35
+ # bigtable = Google::Cloud::Bigtable.new
36
+ #
37
+ # job = bigtable.create_instance(
38
+ # "my-instance",
39
+ # display_name: "Instance for user data",
40
+ # type: :DEVELOPMENT,
41
+ # labels: { "env" => "dev"}
42
+ # ) do |clusters|
43
+ # clusters.add("test-cluster", "us-east1-b") # nodes not allowed
44
+ # end
45
+ #
46
+ # # Check and reload.
47
+ # job.done? #=> false
48
+ # job.reload! # API call
49
+ # job.done? #=> true
50
+ #
51
+ # # OR - Wailt until complete
52
+ # job.wait_until_done!
53
+ # job.done? #=> true
54
+ #
55
+ # if job.error?
56
+ # status = job.error
57
+ # else
58
+ # instance = job.instance
59
+ # end
60
+ #
61
+ class Job < LongrunningJob
62
+ ##
63
+ # Get the instance object from operation results.
64
+ #
65
+ # @return [Google::Cloud::Bigtable::Instance, nil] The Instance instance, or
66
+ # `nil` if the operation is not complete.
67
+ #
68
+ # @example
69
+ # require "google/cloud/bigtable"
70
+ #
71
+ # bigtable = Google::Cloud::Bigtable.new
72
+ #
73
+ # job = bigtable.create_instance(
74
+ # "my-instance",
75
+ # display_name: "Instance for user data",
76
+ # type: :DEVELOPMENT,
77
+ # labels: { "env" => "dev"}
78
+ # ) do |clusters|
79
+ # clusters.add("test-cluster", "us-east1-b") # nodes not allowed
80
+ # end
81
+ #
82
+ # job.done? #=> false
83
+ # job.reload!
84
+ # job.done? #=> true
85
+ #
86
+ # # OR
87
+ # job.wait_until_done!
88
+ #
89
+ # instance = job.instance
90
+ #
91
+ def instance
92
+ Instance.from_grpc results, service if results
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,164 @@
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
+ ##
25
+ # Instance::List is a special-case array with additional
26
+ # values and failed_locations.
27
+ class List < DelegateClass(::Array)
28
+ # @private
29
+ # The gRPC Service object.
30
+ attr_accessor :service
31
+
32
+ ##
33
+ # If not empty, indicates that more records match
34
+ # the request and this value should be passed to continue.
35
+ attr_accessor :token
36
+
37
+ ##
38
+ # Locations from which instance information could not be retrieved,
39
+ # due to an outage or some other transient condition.
40
+ # Instances whose clusters are all in one of the failed locations
41
+ # may be missing from `instances`, and instances with at least one
42
+ # cluster in a failed location may only have partial information returned.
43
+ attr_accessor :failed_locations
44
+
45
+ # @private
46
+ # Creates a new Instance::List with an array of
47
+ # Instance instances.
48
+ def initialize arr = []
49
+ super arr
50
+ end
51
+
52
+ ##
53
+ # Whether there is a next page of instances.
54
+ #
55
+ # @return [Boolean]
56
+ #
57
+ # @example
58
+ # require "google/cloud/bigtable"
59
+ #
60
+ # bigtable = Google::Cloud::Bigtable.new
61
+ #
62
+ # instances = bigtable.instances
63
+ # if instances.next?
64
+ # next_instances = instances.next
65
+ # end
66
+ #
67
+ def next?
68
+ !token.nil?
69
+ end
70
+
71
+ ##
72
+ # Retrieves the next page of instances.
73
+ #
74
+ # @return [Instance::List] The list of instances.
75
+ #
76
+ # @example
77
+ # require "google/cloud/bigtable"
78
+ #
79
+ # bigtable = Google::Cloud::Bigtable.new
80
+ #
81
+ # instances = bigtable.instances
82
+ # if instances.next?
83
+ # next_instances = instances.next
84
+ # end
85
+ #
86
+ def next
87
+ return nil unless next?
88
+ ensure_service!
89
+ grpc = service.list_instances token: token
90
+ next_list = self.class.from_grpc grpc, service
91
+ next_list.failed_locations.concat(failed_locations.map(&:to_s)) if failed_locations
92
+ next_list
93
+ end
94
+
95
+ ##
96
+ # Retrieves remaining results by repeatedly invoking {#next} until
97
+ # {#next?} returns `false`. Calls the given block once for each
98
+ # result, which is passed as the argument to the block.
99
+ #
100
+ # An enumerator is returned if no block is given.
101
+ #
102
+ # This method will make repeated API calls until all remaining results
103
+ # are retrieved (unlike `#each`, for example, which merely iterates
104
+ # over the results returned by a single API call). Use with caution.
105
+ #
106
+ # @yield [instance] The block for accessing each instance.
107
+ # @yieldparam [Instance] instance The instance object.
108
+ #
109
+ # @return [Enumerator,nil] An enumerator is returned if no block is given, otherwise `nil`.
110
+ #
111
+ # @example Iterating each instance by passing a block:
112
+ # require "google/cloud/bigtable"
113
+ #
114
+ # bigtable = Google::Cloud::Bigtable.new
115
+ #
116
+ # bigtable.instances.all do |instance|
117
+ # puts instance.instance_id
118
+ # end
119
+ #
120
+ # @example Using the enumerator by not passing a block:
121
+ # require "google/cloud/bigtable"
122
+ #
123
+ # bigtable = Google::Cloud::Bigtable.new
124
+ #
125
+ # all_instance_ids = bigtable.instances.all.map do |instance|
126
+ # puts instance.instance_id
127
+ # end
128
+ #
129
+ def all
130
+ return enum_for :all unless block_given?
131
+
132
+ results = self
133
+ loop do
134
+ results.each { |r| yield r }
135
+ break unless results.next?
136
+ results = results.next
137
+ end
138
+ end
139
+
140
+ # @private
141
+ # New Instance::List from a Google::Bigtable::Admin::V2::Instance object.
142
+ def self.from_grpc grpc, service
143
+ instances = List.new(Array(grpc.instances).map do |instance|
144
+ Instance.from_grpc instance, service
145
+ end)
146
+ token = grpc.next_page_token
147
+ token = nil if token == ""
148
+ instances.token = token
149
+ instances.service = service
150
+ instances.failed_locations = grpc.failed_locations.map(&:to_s)
151
+ instances
152
+ end
153
+
154
+ protected
155
+
156
+ # Raises an error unless an active service is available.
157
+ def ensure_service!
158
+ raise "Must have active connection" unless service
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
164
+ end
@@ -0,0 +1,122 @@
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
+ module Google
19
+ module Cloud
20
+ module Bigtable
21
+ ##
22
+ # # LongrunningJob
23
+ #
24
+ # A resource representing the long-running, asynchronous processing operation.
25
+ # The job can be refreshed to retrieve the result object once the operation has been completed.
26
+ #
27
+ # @see https://cloud.google.com/bigtable/docs/reference/admin/rpc/google.longrunning#google.longrunning.Operation
28
+ # Long-running Operation
29
+ #
30
+ class LongrunningJob
31
+ # @private
32
+ # The Google::Gax::Operation gRPC object.
33
+ attr_accessor :grpc
34
+
35
+ # @private
36
+ # The gRPC Service object.
37
+ attr_accessor :service
38
+
39
+ ##
40
+ # Gets the result object of the operation.
41
+ #
42
+ # @return [Object, nil]
43
+ # `nil` if the operation is not complete.
44
+ #
45
+ def results
46
+ return nil unless done?
47
+ return nil unless @grpc.grpc_op.result == :response
48
+ @grpc.results
49
+ end
50
+
51
+ ##
52
+ # Checks if the processing of the instance operation is complete.
53
+ #
54
+ # @return [boolean] `true` when complete, `false` otherwise.
55
+ #
56
+ def done?
57
+ @grpc.done?
58
+ end
59
+
60
+ ##
61
+ # Checks if the processing of the instance operation has errored.
62
+ #
63
+ # @return [boolean] `true` when errored, `false` otherwise.
64
+ #
65
+ def error?
66
+ @grpc.error?
67
+ end
68
+
69
+ ##
70
+ # The status when the operation associated with this job produced an
71
+ # error.
72
+ #
73
+ # @return [Object, Google::Rpc::Status, nil] A status object with
74
+ # the status code and message, or `nil` if no error occurred.
75
+ #
76
+ def error
77
+ return nil unless error?
78
+ @grpc.error
79
+ end
80
+
81
+ ##
82
+ # Reloads the job with current data from the long-running,
83
+ # asynchronous processing of an operation.
84
+ #
85
+ # @return [Google::Cloud::Bigtable::Instance::Job] The same job instance.
86
+ #
87
+ def reload!
88
+ @grpc.reload!
89
+ self
90
+ end
91
+
92
+ ##
93
+ # Reloads the job until the operation is complete. The delay between
94
+ # reloads will incrementally increase.
95
+ #
96
+ def wait_until_done!
97
+ @grpc.wait_until_done!
98
+ end
99
+
100
+ ##
101
+ # @private Gets the metadata object of the operation.
102
+ #
103
+ # @return [Object, nil] `nil` if the operation is not complete.
104
+ #
105
+ def metadata
106
+ return nil unless done?
107
+ return nil unless @grpc.grpc_op.result == :response
108
+ @grpc.metadata
109
+ end
110
+
111
+ # @private
112
+ # New BasicJob from a Google::Gax::Operation object.
113
+ def self.from_grpc grpc, service
114
+ new.tap do |job|
115
+ job.grpc = grpc
116
+ job.service = service
117
+ end
118
+ end
119
+ end
120
+ end
121
+ end
122
+ end