google-cloud-bigtable 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,165 @@
|
|
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 AppProfile
|
22
|
+
##
|
23
|
+
# AppProfile::List is a special-case array with additional
|
24
|
+
# values.
|
25
|
+
class List < DelegateClass(::Array)
|
26
|
+
# @private
|
27
|
+
# The gRPC Service object.
|
28
|
+
attr_accessor :service
|
29
|
+
|
30
|
+
# @private
|
31
|
+
# The gRPC page enumerable object.
|
32
|
+
attr_accessor :grpc
|
33
|
+
|
34
|
+
# @private
|
35
|
+
# Creates a new AppProfile::List with an array of app profiles.
|
36
|
+
def initialize arr = []
|
37
|
+
super arr
|
38
|
+
end
|
39
|
+
|
40
|
+
##
|
41
|
+
# Whether there is a next page of app profiles.
|
42
|
+
#
|
43
|
+
# @return [Boolean]
|
44
|
+
#
|
45
|
+
# @example
|
46
|
+
# require "google/cloud/bigtable"
|
47
|
+
#
|
48
|
+
# bigtable = Google::Cloud::Bigtable.new
|
49
|
+
#
|
50
|
+
# instance = bigtable.instance("my-instance")
|
51
|
+
# app_profiles = instance.app_profiles
|
52
|
+
#
|
53
|
+
# if app_profiles.next?
|
54
|
+
# next_app_profiles = app_profiles.next
|
55
|
+
# end
|
56
|
+
#
|
57
|
+
def next?
|
58
|
+
grpc.next_page?
|
59
|
+
end
|
60
|
+
|
61
|
+
##
|
62
|
+
# Retrieves the next page of app profiles.
|
63
|
+
#
|
64
|
+
# @return [AppProfile::List] The list of app profiles.
|
65
|
+
#
|
66
|
+
# @example
|
67
|
+
# require "google/cloud/bigtable"
|
68
|
+
#
|
69
|
+
# bigtable = Google::Cloud::Bigtable.new
|
70
|
+
#
|
71
|
+
# instance = bigtable.instance("my-instance")
|
72
|
+
# app_profiles = instance.app_profiles
|
73
|
+
#
|
74
|
+
# if app_profiles.next?
|
75
|
+
# next_app_profiles = app_profiles.next
|
76
|
+
# end
|
77
|
+
#
|
78
|
+
def next
|
79
|
+
ensure_grpc!
|
80
|
+
|
81
|
+
return nil unless next?
|
82
|
+
grpc.next_page
|
83
|
+
self.class.from_grpc grpc, service
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# Retrieves remaining results by repeatedly invoking {#next} until
|
88
|
+
# {#next?} returns `false`. Calls the given block once for each
|
89
|
+
# result, which is passed as the argument to the block.
|
90
|
+
#
|
91
|
+
# An enumerator is returned if no block is given.
|
92
|
+
#
|
93
|
+
# This method will make repeated API calls until all remaining results
|
94
|
+
# are retrieved (unlike `#each`, for example, which merely iterates
|
95
|
+
# over the results returned by a single API call). Use with caution.
|
96
|
+
#
|
97
|
+
# @yield [app_profile] The block for accessing each app profile.
|
98
|
+
# @yieldparam [AppProfile] app_profile The app profile object.
|
99
|
+
#
|
100
|
+
# @return [Enumerator,nil] An enumerator is returned if no block is given, otherwise `nil`.
|
101
|
+
#
|
102
|
+
# @example Iterating each app profile by passing a block:
|
103
|
+
# require "google/cloud/bigtable"
|
104
|
+
#
|
105
|
+
# bigtable = Google::Cloud::Bigtable.new
|
106
|
+
#
|
107
|
+
# instance = bigtable.instance("my-instance")
|
108
|
+
# app_profiles = instance.app_profiles
|
109
|
+
#
|
110
|
+
# instance.app_profiles.all do |app_profile|
|
111
|
+
# puts app_profile.name
|
112
|
+
# end
|
113
|
+
#
|
114
|
+
# @example Using the enumerator by not passing a block:
|
115
|
+
# require "google/cloud/bigtable"
|
116
|
+
#
|
117
|
+
# bigtable = Google::Cloud::Bigtable.new
|
118
|
+
#
|
119
|
+
# instance = bigtable.instance("my-instance")
|
120
|
+
#
|
121
|
+
# all_app_profile_ids = instance.app_profiles.all.map do |app_profile|
|
122
|
+
# app_profile.name
|
123
|
+
# end
|
124
|
+
#
|
125
|
+
def all
|
126
|
+
return enum_for :all unless block_given?
|
127
|
+
|
128
|
+
results = self
|
129
|
+
loop do
|
130
|
+
results.each { |r| yield r }
|
131
|
+
break unless next?
|
132
|
+
grpc.next_page
|
133
|
+
results = self.class.from_grpc grpc, service
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# @private
|
138
|
+
# New Snapshot::List from a Google::Gax::PagedEnumerable<Google::Bigtable::Admin::V2::AppProfile> object.
|
139
|
+
# @param grpc [Google::Gax::PagedEnumerable<Google::Bigtable::Admin::V2::AppProfile> ]
|
140
|
+
# @param service [Google::Cloud::Bigtable::Service]
|
141
|
+
# @return [Array<Google::Cloud::Bigtable::AppProfile>]
|
142
|
+
def self.from_grpc grpc, service
|
143
|
+
app_profiles = List.new(
|
144
|
+
Array(grpc.response.app_profiles).map do |app_profile|
|
145
|
+
AppProfile.from_grpc app_profile, service
|
146
|
+
end
|
147
|
+
)
|
148
|
+
app_profiles.grpc = grpc
|
149
|
+
app_profiles.service = service
|
150
|
+
app_profiles
|
151
|
+
end
|
152
|
+
|
153
|
+
protected
|
154
|
+
|
155
|
+
# @private
|
156
|
+
#
|
157
|
+
# Raises an error if an active gRPC call is not available.
|
158
|
+
def ensure_grpc!
|
159
|
+
raise "Must have active gRPC call" unless grpc
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,324 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright 2020 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/backup/job"
|
19
|
+
require "google/cloud/bigtable/backup/list"
|
20
|
+
require "google/cloud/bigtable/convert"
|
21
|
+
require "google/cloud/bigtable/table/restore_job"
|
22
|
+
|
23
|
+
|
24
|
+
module Google
|
25
|
+
module Cloud
|
26
|
+
module Bigtable
|
27
|
+
##
|
28
|
+
# # Backup
|
29
|
+
#
|
30
|
+
# A backup of a Cloud Bigtable table. See {Cluster#create_backup}, {Cluster#backup} and {Cluster#backups}.
|
31
|
+
#
|
32
|
+
# @example
|
33
|
+
# require "google/cloud/bigtable"
|
34
|
+
#
|
35
|
+
# bigtable = Google::Cloud::Bigtable.new
|
36
|
+
# instance = bigtable.instance("my-instance")
|
37
|
+
# cluster = instance.cluster("my-cluster")
|
38
|
+
#
|
39
|
+
# backup = cluster.backup("my-backup")
|
40
|
+
#
|
41
|
+
# # Update
|
42
|
+
# backup.expire_time = Time.now + 60 * 60 * 7
|
43
|
+
# backup.save
|
44
|
+
#
|
45
|
+
# # Delete
|
46
|
+
# backup.delete
|
47
|
+
#
|
48
|
+
class Backup
|
49
|
+
# @private
|
50
|
+
# The gRPC Service object.
|
51
|
+
attr_accessor :service
|
52
|
+
|
53
|
+
##
|
54
|
+
# @private A list of attributes that were updated.
|
55
|
+
attr_reader :updates
|
56
|
+
|
57
|
+
# @private
|
58
|
+
#
|
59
|
+
# Creates a new Backup instance.
|
60
|
+
def initialize grpc, service
|
61
|
+
@grpc = grpc
|
62
|
+
@service = service
|
63
|
+
end
|
64
|
+
|
65
|
+
##
|
66
|
+
# The unique identifier for the project to which the backup belongs.
|
67
|
+
#
|
68
|
+
# @return [String]
|
69
|
+
#
|
70
|
+
def project_id
|
71
|
+
@grpc.name.split("/")[1]
|
72
|
+
end
|
73
|
+
|
74
|
+
##
|
75
|
+
# The unique identifier for the instance to which the backup belongs.
|
76
|
+
#
|
77
|
+
# @return [String]
|
78
|
+
#
|
79
|
+
def instance_id
|
80
|
+
@grpc.name.split("/")[3]
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# The unique identifier for the cluster to which the backup belongs.
|
85
|
+
#
|
86
|
+
# @return [String]
|
87
|
+
#
|
88
|
+
def cluster_id
|
89
|
+
@grpc.name.split("/")[5]
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# The unique identifier for the backup.
|
94
|
+
#
|
95
|
+
# @return [String]
|
96
|
+
#
|
97
|
+
def backup_id
|
98
|
+
@grpc.name.split("/")[7]
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# The unique name of the backup. Value in the form
|
103
|
+
# `projects/<project>/instances/<instance>/clusters/<cluster>/backups/<backup>`.
|
104
|
+
#
|
105
|
+
# @return [String]
|
106
|
+
#
|
107
|
+
def path
|
108
|
+
@grpc.name
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# The table from which this backup was created.
|
113
|
+
#
|
114
|
+
# @param perform_lookup [Boolean] Creates table object without verifying that the table resource exists. Calls
|
115
|
+
# made on this object will raise errors if the table does not exist. Default value is `false`. Optional. Helps
|
116
|
+
# to reduce admin API calls.
|
117
|
+
# @param view [Symbol] Table view type. Default view type is `:SCHEMA_VIEW`. Valid view types are:
|
118
|
+
#
|
119
|
+
# * `:NAME_ONLY` - Only populates `name`.
|
120
|
+
# * `:SCHEMA_VIEW` - Only populates `name` and fields related to the table's schema.
|
121
|
+
# * `:REPLICATION_VIEW` - Only populates `name` and fields related to the table's replication state.
|
122
|
+
# * `:FULL` - Populates all fields.
|
123
|
+
#
|
124
|
+
# @return [Table]
|
125
|
+
#
|
126
|
+
def source_table perform_lookup: nil, view: nil
|
127
|
+
table = Table.from_path @grpc.source_table, service
|
128
|
+
return table.reload! view: view if perform_lookup
|
129
|
+
table
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# The expiration time of the backup, with microseconds granularity that must be at least 6 hours and at most 30
|
134
|
+
# days from the time the request is received. Once the expire time has passed, Cloud Bigtable will delete the
|
135
|
+
# backup and free the resources used by the backup.
|
136
|
+
#
|
137
|
+
# @return [Time]
|
138
|
+
#
|
139
|
+
def expire_time
|
140
|
+
Convert.timestamp_to_time @grpc.expire_time
|
141
|
+
end
|
142
|
+
|
143
|
+
##
|
144
|
+
# Sets the expiration time of the backup, with microseconds granularity that must be at least 6 hours and at
|
145
|
+
# most 30 days from the time the request is received. Once the {#expire_time} has passed, Cloud Bigtable will
|
146
|
+
# delete the backup and free the resources used by the backup.
|
147
|
+
#
|
148
|
+
# @param [Time] new_expire_time The new expiration time of the backup.
|
149
|
+
#
|
150
|
+
def expire_time= new_expire_time
|
151
|
+
@grpc.expire_time = Convert.time_to_timestamp new_expire_time
|
152
|
+
end
|
153
|
+
|
154
|
+
##
|
155
|
+
# The time that the backup was started (i.e. approximately the time the `CreateBackup` request is received). The
|
156
|
+
# row data in this backup will be no older than this timestamp.
|
157
|
+
#
|
158
|
+
# @return [Time]
|
159
|
+
#
|
160
|
+
def start_time
|
161
|
+
Convert.timestamp_to_time @grpc.start_time
|
162
|
+
end
|
163
|
+
|
164
|
+
##
|
165
|
+
# The time that the backup was finished. The row data in the backup will be no newer than this timestamp.
|
166
|
+
#
|
167
|
+
# @return [Time]
|
168
|
+
#
|
169
|
+
def end_time
|
170
|
+
Convert.timestamp_to_time @grpc.end_time
|
171
|
+
end
|
172
|
+
|
173
|
+
##
|
174
|
+
# The size of the backup in bytes.
|
175
|
+
#
|
176
|
+
# @return [Integer]
|
177
|
+
#
|
178
|
+
def size_bytes
|
179
|
+
@grpc.size_bytes
|
180
|
+
end
|
181
|
+
|
182
|
+
##
|
183
|
+
# The current state of the backup. Possible values are `:CREATING` and `:READY`.
|
184
|
+
#
|
185
|
+
# @return [Symbol]
|
186
|
+
#
|
187
|
+
def state
|
188
|
+
@grpc.state
|
189
|
+
end
|
190
|
+
|
191
|
+
##
|
192
|
+
# The backup is currently being created, and may be destroyed if the creation process encounters an error.
|
193
|
+
#
|
194
|
+
# @return [Boolean]
|
195
|
+
#
|
196
|
+
def creating?
|
197
|
+
state == :CREATING
|
198
|
+
end
|
199
|
+
|
200
|
+
##
|
201
|
+
# The backup has been successfully created and is ready to serve requests.
|
202
|
+
#
|
203
|
+
# @return [Boolean]
|
204
|
+
#
|
205
|
+
def ready?
|
206
|
+
state == :READY
|
207
|
+
end
|
208
|
+
|
209
|
+
##
|
210
|
+
# Creates a new table by restoring from a completed backup.
|
211
|
+
#
|
212
|
+
# @param table_id [String] The table ID for the new table. This table must not yet exist. Required.
|
213
|
+
#
|
214
|
+
# @return [Google::Cloud::Bigtable::Table::RestoreJob] The job representing the long-running, asynchronous
|
215
|
+
# processing of a backup restore table operation.
|
216
|
+
#
|
217
|
+
# @example
|
218
|
+
# require "google/cloud/bigtable"
|
219
|
+
#
|
220
|
+
# bigtable = Google::Cloud::Bigtable.new
|
221
|
+
# instance = bigtable.instance("my-instance")
|
222
|
+
# cluster = instance.cluster("my-cluster")
|
223
|
+
#
|
224
|
+
# backup = cluster.backup("my-backup")
|
225
|
+
#
|
226
|
+
# job = backup.restore("my-new-table")
|
227
|
+
#
|
228
|
+
# job.wait_until_done!
|
229
|
+
# job.done? #=> true
|
230
|
+
#
|
231
|
+
# if job.error?
|
232
|
+
# status = job.error
|
233
|
+
# else
|
234
|
+
# table = job.table
|
235
|
+
# optimized = job.optimize_table_operation_name
|
236
|
+
# end
|
237
|
+
#
|
238
|
+
def restore table_id
|
239
|
+
grpc = service.restore_table table_id, instance_id, cluster_id, backup_id
|
240
|
+
Table::RestoreJob.from_grpc grpc, service
|
241
|
+
end
|
242
|
+
|
243
|
+
##
|
244
|
+
# Updates the backup.
|
245
|
+
#
|
246
|
+
# `expire_time` is the only updatable field.
|
247
|
+
#
|
248
|
+
# @return [Boolean] Returns `true` if the update succeeded.
|
249
|
+
#
|
250
|
+
# @example
|
251
|
+
# require "google/cloud/bigtable"
|
252
|
+
#
|
253
|
+
# bigtable = Google::Cloud::Bigtable.new
|
254
|
+
# instance = bigtable.instance("my-instance")
|
255
|
+
# cluster = instance.cluster("my-cluster")
|
256
|
+
#
|
257
|
+
# backup = cluster.backup("my-backup")
|
258
|
+
#
|
259
|
+
# # Update
|
260
|
+
# backup.expire_time = Time.now + 60 * 60 * 7
|
261
|
+
# backup.save
|
262
|
+
#
|
263
|
+
def save
|
264
|
+
ensure_service!
|
265
|
+
@grpc = service.update_backup @grpc, [:expire_time]
|
266
|
+
true
|
267
|
+
end
|
268
|
+
alias update save
|
269
|
+
|
270
|
+
##
|
271
|
+
# Reloads backup data.
|
272
|
+
#
|
273
|
+
# @return [Google::Cloud::Bigtable::Backup]
|
274
|
+
#
|
275
|
+
def reload!
|
276
|
+
@grpc = service.get_backup instance_id, cluster_id, backup_id
|
277
|
+
self
|
278
|
+
end
|
279
|
+
|
280
|
+
##
|
281
|
+
# Permanently deletes the backup.
|
282
|
+
#
|
283
|
+
# @return [Boolean] Returns `true` if the backup was deleted.
|
284
|
+
#
|
285
|
+
# @example
|
286
|
+
# require "google/cloud/bigtable"
|
287
|
+
#
|
288
|
+
# bigtable = Google::Cloud::Bigtable.new
|
289
|
+
# instance = bigtable.instance("my-instance")
|
290
|
+
# cluster = instance.cluster("my-cluster")
|
291
|
+
#
|
292
|
+
# backup = cluster.backup("my-backup")
|
293
|
+
#
|
294
|
+
# backup.delete
|
295
|
+
#
|
296
|
+
def delete
|
297
|
+
ensure_service!
|
298
|
+
service.delete_backup instance_id, cluster_id, backup_id
|
299
|
+
true
|
300
|
+
end
|
301
|
+
|
302
|
+
# @private
|
303
|
+
#
|
304
|
+
# Creates a new Backup instance from a Google::Bigtable::Admin::V2::Backup.
|
305
|
+
#
|
306
|
+
# @param grpc [Google::Bigtable::Admin::V2::Backup]
|
307
|
+
# @param service [Google::Cloud::Bigtable::Service]
|
308
|
+
# @return [Google::Cloud::Bigtable::Backup]
|
309
|
+
def self.from_grpc grpc, service
|
310
|
+
new grpc, service
|
311
|
+
end
|
312
|
+
|
313
|
+
protected
|
314
|
+
|
315
|
+
# @private
|
316
|
+
#
|
317
|
+
# Raise an error unless an active connection to the service is available.
|
318
|
+
def ensure_service!
|
319
|
+
raise "Must have active connection to service" unless service
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|