google-cloud-bigtable 1.0.2 → 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 (44) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/TROUBLESHOOTING.md +2 -8
  4. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +27 -24
  5. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +60 -57
  6. data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +90 -23
  7. data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +125 -98
  8. data/lib/google/bigtable/admin/v2/common_pb.rb +9 -4
  9. data/lib/google/bigtable/admin/v2/instance_pb.rb +12 -11
  10. data/lib/google/bigtable/admin/v2/table_pb.rb +52 -14
  11. data/lib/google/bigtable/v2/bigtable_pb.rb +17 -17
  12. data/lib/google/bigtable/v2/bigtable_services_pb.rb +39 -39
  13. data/lib/google/bigtable/v2/data_pb.rb +21 -21
  14. data/lib/google/cloud/bigtable/admin.rb +3 -3
  15. data/lib/google/cloud/bigtable/admin/v2.rb +4 -3
  16. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +60 -50
  17. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +1 -1
  18. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +547 -58
  19. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +31 -1
  20. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +46 -39
  21. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +281 -53
  22. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +15 -17
  23. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +119 -26
  24. data/lib/google/cloud/bigtable/app_profile/list.rb +2 -2
  25. data/lib/google/cloud/bigtable/backup.rb +324 -0
  26. data/lib/google/cloud/bigtable/backup/job.rb +87 -0
  27. data/lib/google/cloud/bigtable/backup/list.rb +167 -0
  28. data/lib/google/cloud/bigtable/cluster.rb +99 -0
  29. data/lib/google/cloud/bigtable/cluster/list.rb +1 -1
  30. data/lib/google/cloud/bigtable/column_family_map.rb +1 -1
  31. data/lib/google/cloud/bigtable/instance.rb +4 -7
  32. data/lib/google/cloud/bigtable/instance/list.rb +1 -1
  33. data/lib/google/cloud/bigtable/longrunning_job.rb +11 -0
  34. data/lib/google/cloud/bigtable/policy.rb +1 -1
  35. data/lib/google/cloud/bigtable/service.rb +131 -0
  36. data/lib/google/cloud/bigtable/table.rb +112 -0
  37. data/lib/google/cloud/bigtable/table/cluster_state.rb +25 -4
  38. data/lib/google/cloud/bigtable/table/list.rb +1 -1
  39. data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
  40. data/lib/google/cloud/bigtable/v2.rb +1 -1
  41. data/lib/google/cloud/bigtable/v2/bigtable_client.rb +3 -0
  42. data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +7 -7
  43. data/lib/google/cloud/bigtable/version.rb +1 -1
  44. metadata +9 -5
@@ -19,16 +19,15 @@ module Google
19
19
  module V2
20
20
  # A collection of Bigtable {Google::Bigtable::Admin::V2::Table Tables} and
21
21
  # the resources that serve them.
22
- # All tables in an instance are served from a single
23
- # {Google::Bigtable::Admin::V2::Cluster Cluster}.
22
+ # All tables in an instance are served from all
23
+ # {Google::Bigtable::Admin::V2::Cluster Clusters} in the instance.
24
24
  # @!attribute [rw] name
25
25
  # @return [String]
26
- # (`OutputOnly`)
27
26
  # The unique name of the instance. Values are of the form
28
- # `projects/<project>/instances/[a-z][a-z0-9\\-]+[a-z0-9]`.
27
+ # `projects/{project}/instances/[a-z][a-z0-9\\-]+[a-z0-9]`.
29
28
  # @!attribute [rw] display_name
30
29
  # @return [String]
31
- # The descriptive name for this instance as it appears in UIs.
30
+ # Required. The descriptive name for this instance as it appears in UIs.
32
31
  # Can be changed at any time, but should be kept globally unique
33
32
  # to avoid confusion.
34
33
  # @!attribute [rw] state
@@ -93,24 +92,22 @@ module Google
93
92
  # {Google::Bigtable::Admin::V2::Instance Instance}.
94
93
  # @!attribute [rw] name
95
94
  # @return [String]
96
- # (`OutputOnly`)
97
95
  # The unique name of the cluster. Values are of the form
98
- # `projects/<project>/instances/<instance>/clusters/[a-z][-a-z0-9]*`.
96
+ # `projects/{project}/instances/{instance}/clusters/[a-z][-a-z0-9]*`.
99
97
  # @!attribute [rw] location
100
98
  # @return [String]
101
99
  # (`CreationOnly`)
102
100
  # The location where this cluster's nodes and storage reside. For best
103
101
  # performance, clients should be located as close as possible to this
104
102
  # cluster. Currently only zones are supported, so values should be of the
105
- # form `projects/<project>/locations/<zone>`.
103
+ # form `projects/{project}/locations/{zone}`.
106
104
  # @!attribute [rw] state
107
105
  # @return [Google::Bigtable::Admin::V2::Cluster::State]
108
- # (`OutputOnly`)
109
106
  # The current state of the cluster.
110
107
  # @!attribute [rw] serve_nodes
111
108
  # @return [Integer]
112
- # The number of nodes allocated to this cluster. More nodes enable higher
113
- # throughput and more consistent performance.
109
+ # Required. The number of nodes allocated to this cluster. More nodes enable
110
+ # higher throughput and more consistent performance.
114
111
  # @!attribute [rw] default_storage_type
115
112
  # @return [Google::Bigtable::Admin::V2::StorageType]
116
113
  # (`CreationOnly`)
@@ -165,19 +162,20 @@ module Google
165
162
  # Optional long form description of the use case for this AppProfile.
166
163
  # @!attribute [rw] multi_cluster_routing_use_any
167
164
  # @return [Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny]
168
- # Use a multi-cluster routing policy that may pick any cluster.
165
+ # Use a multi-cluster routing policy.
169
166
  # @!attribute [rw] single_cluster_routing
170
167
  # @return [Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting]
171
168
  # Use a single-cluster routing policy.
172
169
  class AppProfile
173
- # Read/write requests may be routed to any cluster in the instance, and will
174
- # fail over to another cluster in the event of transient errors or delays.
175
- # Choosing this option sacrifices read-your-writes consistency to improve
176
- # availability.
170
+ # Read/write requests are routed to the nearest cluster in the instance, and
171
+ # will fail over to the nearest cluster that is available in the event of
172
+ # transient errors or delays. Clusters in a region are considered
173
+ # equidistant. Choosing this option sacrifices read-your-writes consistency
174
+ # to improve availability.
177
175
  class MultiClusterRoutingUseAny; end
178
176
 
179
177
  # Unconditionally routes all read/write requests to a specific cluster.
180
- # This option preserves read-your-writes consistency, but does not improve
178
+ # This option preserves read-your-writes consistency but does not improve
181
179
  # availability.
182
180
  # @!attribute [rw] cluster_id
183
181
  # @return [String]
@@ -17,18 +17,26 @@ module Google
17
17
  module Bigtable
18
18
  module Admin
19
19
  module V2
20
+ # Information about a table restore.
21
+ # @!attribute [rw] source_type
22
+ # @return [Google::Bigtable::Admin::V2::RestoreSourceType]
23
+ # The type of the restore source.
24
+ # @!attribute [rw] backup_info
25
+ # @return [Google::Bigtable::Admin::V2::BackupInfo]
26
+ # Information about the backup used to restore the table. The backup
27
+ # may no longer exist.
28
+ class RestoreInfo; end
29
+
20
30
  # A collection of user data indexed by row, column, and timestamp.
21
31
  # Each table is served using the resources of its parent cluster.
22
32
  # @!attribute [rw] name
23
33
  # @return [String]
24
- # (`OutputOnly`)
25
- # The unique name of the table. Values are of the form
34
+ # Output only. The unique name of the table. Values are of the form
26
35
  # `projects/<project>/instances/<instance>/tables/[_a-zA-Z0-9][-_.a-zA-Z0-9]*`.
27
36
  # Views: `NAME_ONLY`, `SCHEMA_VIEW`, `REPLICATION_VIEW`, `FULL`
28
37
  # @!attribute [rw] cluster_states
29
38
  # @return [Hash{String => Google::Bigtable::Admin::V2::Table::ClusterState}]
30
- # (`OutputOnly`)
31
- # Map from cluster ID to per-cluster table state.
39
+ # Output only. Map from cluster ID to per-cluster table state.
32
40
  # If it could not be determined whether or not the table has data in a
33
41
  # particular cluster (for example, if its zone is unavailable), then
34
42
  # there will be an entry for the cluster with UNKNOWN `replication_status`.
@@ -44,13 +52,16 @@ module Google
44
52
  # The granularity (i.e. `MILLIS`) at which timestamps are stored in
45
53
  # this table. Timestamps not matching the granularity will be rejected.
46
54
  # If unspecified at creation time, the value will be set to `MILLIS`.
47
- # Views: `SCHEMA_VIEW`, `FULL`
55
+ # Views: `SCHEMA_VIEW`, `FULL`.
56
+ # @!attribute [rw] restore_info
57
+ # @return [Google::Bigtable::Admin::V2::RestoreInfo]
58
+ # Output only. If this table was restored from another data source (e.g. a
59
+ # backup), this field will be populated with information about the restore.
48
60
  class Table
49
61
  # The state of a table's data in a particular cluster.
50
62
  # @!attribute [rw] replication_state
51
63
  # @return [Google::Bigtable::Admin::V2::Table::ClusterState::ReplicationState]
52
- # (`OutputOnly`)
53
- # The state of replication for the table in this cluster.
64
+ # Output only. The state of replication for the table in this cluster.
54
65
  class ClusterState
55
66
  # Table replication states.
56
67
  module ReplicationState
@@ -74,6 +85,11 @@ module Google
74
85
  # replication delay, reads may not immediately reflect the state of the
75
86
  # table in other clusters.
76
87
  READY = 4
88
+
89
+ # The table is fully created and ready for use after a restore, and is
90
+ # being optimized for performance. When optimizations are complete, the
91
+ # table will transition to `READY` state.
92
+ READY_OPTIMIZING = 5
77
93
  end
78
94
  end
79
95
 
@@ -99,8 +115,8 @@ module Google
99
115
  # Only populates `name` and fields related to the table's schema.
100
116
  SCHEMA_VIEW = 2
101
117
 
102
- # Only populates `name` and fields related to the table's
103
- # replication state.
118
+ # Only populates `name` and fields related to the table's replication
119
+ # state.
104
120
  REPLICATION_VIEW = 3
105
121
 
106
122
  # Populates all fields.
@@ -157,38 +173,32 @@ module Google
157
173
  # for production use. It is not subject to any SLA or deprecation policy.
158
174
  # @!attribute [rw] name
159
175
  # @return [String]
160
- # (`OutputOnly`)
161
- # The unique name of the snapshot.
176
+ # Output only. The unique name of the snapshot.
162
177
  # Values are of the form
163
178
  # `projects/<project>/instances/<instance>/clusters/<cluster>/snapshots/<snapshot>`.
164
179
  # @!attribute [rw] source_table
165
180
  # @return [Google::Bigtable::Admin::V2::Table]
166
- # (`OutputOnly`)
167
- # The source table at the time the snapshot was taken.
181
+ # Output only. The source table at the time the snapshot was taken.
168
182
  # @!attribute [rw] data_size_bytes
169
183
  # @return [Integer]
170
- # (`OutputOnly`)
171
- # The size of the data in the source table at the time the snapshot was
172
- # taken. In some cases, this value may be computed asynchronously via a
173
- # background process and a placeholder of 0 will be used in the meantime.
184
+ # Output only. The size of the data in the source table at the time the
185
+ # snapshot was taken. In some cases, this value may be computed
186
+ # asynchronously via a background process and a placeholder of 0 will be used
187
+ # in the meantime.
174
188
  # @!attribute [rw] create_time
175
189
  # @return [Google::Protobuf::Timestamp]
176
- # (`OutputOnly`)
177
- # The time when the snapshot is created.
190
+ # Output only. The time when the snapshot is created.
178
191
  # @!attribute [rw] delete_time
179
192
  # @return [Google::Protobuf::Timestamp]
180
- # (`OutputOnly`)
181
- # The time when the snapshot will be deleted. The maximum amount of time a
182
- # snapshot can stay active is 365 days. If 'ttl' is not specified,
193
+ # Output only. The time when the snapshot will be deleted. The maximum amount
194
+ # of time a snapshot can stay active is 365 days. If 'ttl' is not specified,
183
195
  # the default maximum of 365 days will be used.
184
196
  # @!attribute [rw] state
185
197
  # @return [Google::Bigtable::Admin::V2::Snapshot::State]
186
- # (`OutputOnly`)
187
- # The current state of the snapshot.
198
+ # Output only. The current state of the snapshot.
188
199
  # @!attribute [rw] description
189
200
  # @return [String]
190
- # (`OutputOnly`)
191
- # Description of the snapshot.
201
+ # Output only. Description of the snapshot.
192
202
  class Snapshot
193
203
  # Possible states of a snapshot.
194
204
  module State
@@ -204,6 +214,89 @@ module Google
204
214
  CREATING = 2
205
215
  end
206
216
  end
217
+
218
+ # A backup of a Cloud Bigtable table.
219
+ # @!attribute [rw] name
220
+ # @return [String]
221
+ # Output only. A globally unique identifier for the backup which cannot be
222
+ # changed. Values are of the form
223
+ # `projects/{project}/instances/{instance}/clusters/{cluster}/
224
+ # backups/[_a-zA-Z0-9][-_.a-zA-Z0-9]*`
225
+ # The final segment of the name must be between 1 and 50 characters
226
+ # in length.
227
+ #
228
+ # The backup is stored in the cluster identified by the prefix of the backup
229
+ # name of the form
230
+ # `projects/{project}/instances/{instance}/clusters/{cluster}`.
231
+ # @!attribute [rw] source_table
232
+ # @return [String]
233
+ # Required. Immutable. Name of the table from which this backup was created.
234
+ # This needs to be in the same instance as the backup. Values are of the form
235
+ # `projects/{project}/instances/{instance}/tables/{source_table}`.
236
+ # @!attribute [rw] expire_time
237
+ # @return [Google::Protobuf::Timestamp]
238
+ # Required. The expiration time of the backup, with microseconds
239
+ # granularity that must be at least 6 hours and at most 30 days
240
+ # from the time the request is received. Once the `expire_time`
241
+ # has passed, Cloud Bigtable will delete the backup and free the
242
+ # resources used by the backup.
243
+ # @!attribute [rw] start_time
244
+ # @return [Google::Protobuf::Timestamp]
245
+ # Output only. `start_time` is the time that the backup was started
246
+ # (i.e. approximately the time the
247
+ # {Google::Bigtable::Admin::V2::BigtableTableAdmin::CreateBackup CreateBackup}
248
+ # request is received). The row data in this backup will be no older than
249
+ # this timestamp.
250
+ # @!attribute [rw] end_time
251
+ # @return [Google::Protobuf::Timestamp]
252
+ # Output only. `end_time` is the time that the backup was finished. The row
253
+ # data in the backup will be no newer than this timestamp.
254
+ # @!attribute [rw] size_bytes
255
+ # @return [Integer]
256
+ # Output only. Size of the backup in bytes.
257
+ # @!attribute [rw] state
258
+ # @return [Google::Bigtable::Admin::V2::Backup::State]
259
+ # Output only. The current state of the backup.
260
+ class Backup
261
+ # Indicates the current state of the backup.
262
+ module State
263
+ # Not specified.
264
+ STATE_UNSPECIFIED = 0
265
+
266
+ # The pending backup is still being created. Operations on the
267
+ # backup may fail with `FAILED_PRECONDITION` in this state.
268
+ CREATING = 1
269
+
270
+ # The backup is complete and ready for use.
271
+ READY = 2
272
+ end
273
+ end
274
+
275
+ # Information about a backup.
276
+ # @!attribute [rw] backup
277
+ # @return [String]
278
+ # Output only. Name of the backup.
279
+ # @!attribute [rw] start_time
280
+ # @return [Google::Protobuf::Timestamp]
281
+ # Output only. The time that the backup was started. Row data in the backup
282
+ # will be no older than this timestamp.
283
+ # @!attribute [rw] end_time
284
+ # @return [Google::Protobuf::Timestamp]
285
+ # Output only. This time that the backup was finished. Row data in the
286
+ # backup will be no newer than this timestamp.
287
+ # @!attribute [rw] source_table
288
+ # @return [String]
289
+ # Output only. Name of the table the backup was created from.
290
+ class BackupInfo; end
291
+
292
+ # Indicates the type of the restore source.
293
+ module RestoreSourceType
294
+ # No restore associated.
295
+ RESTORE_SOURCE_TYPE_UNSPECIFIED = 0
296
+
297
+ # A backup was used as the source of the restore.
298
+ BACKUP = 1
299
+ end
207
300
  end
208
301
  end
209
302
  end
@@ -97,7 +97,7 @@ module Google
97
97
  # @yield [app_profile] The block for accessing each app profile.
98
98
  # @yieldparam [AppProfile] app_profile The app profile object.
99
99
  #
100
- # @return [Enumerator]
100
+ # @return [Enumerator,nil] An enumerator is returned if no block is given, otherwise `nil`.
101
101
  #
102
102
  # @example Iterating each app profile by passing a block:
103
103
  # require "google/cloud/bigtable"
@@ -118,7 +118,7 @@ module Google
118
118
  #
119
119
  # instance = bigtable.instance("my-instance")
120
120
  #
121
- # all_snapshot_ids = instance.app_profiles.all.map do |app_profile|
121
+ # all_app_profile_ids = instance.app_profiles.all.map do |app_profile|
122
122
  # app_profile.name
123
123
  # end
124
124
  #
@@ -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