google-cloud-bigtable 1.2.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +1 -1
  3. data/CHANGELOG.md +54 -0
  4. data/TROUBLESHOOTING.md +2 -8
  5. data/lib/google-cloud-bigtable.rb +30 -27
  6. data/lib/google/cloud/bigtable.rb +18 -26
  7. data/lib/google/cloud/bigtable/app_profile.rb +3 -3
  8. data/lib/google/cloud/bigtable/app_profile/list.rb +6 -4
  9. data/lib/google/cloud/bigtable/backup.rb +324 -0
  10. data/lib/google/cloud/bigtable/backup/job.rb +87 -0
  11. data/lib/google/cloud/bigtable/backup/list.rb +167 -0
  12. data/lib/google/cloud/bigtable/chunk_processor.rb +1 -1
  13. data/lib/google/cloud/bigtable/cluster.rb +101 -2
  14. data/lib/google/cloud/bigtable/cluster/list.rb +2 -2
  15. data/lib/google/cloud/bigtable/column_family.rb +2 -2
  16. data/lib/google/cloud/bigtable/column_family_map.rb +11 -11
  17. data/lib/google/cloud/bigtable/column_range.rb +2 -2
  18. data/lib/google/cloud/bigtable/credentials.rb +36 -2
  19. data/lib/google/cloud/bigtable/gc_rule.rb +7 -7
  20. data/lib/google/cloud/bigtable/instance.rb +6 -6
  21. data/lib/google/cloud/bigtable/instance/cluster_map.rb +1 -1
  22. data/lib/google/cloud/bigtable/instance/list.rb +2 -2
  23. data/lib/google/cloud/bigtable/longrunning_job.rb +13 -2
  24. data/lib/google/cloud/bigtable/mutation_entry.rb +10 -9
  25. data/lib/google/cloud/bigtable/mutation_operations.rb +2 -2
  26. data/lib/google/cloud/bigtable/project.rb +1 -1
  27. data/lib/google/cloud/bigtable/read_modify_write_rule.rb +2 -2
  28. data/lib/google/cloud/bigtable/read_operations.rb +2 -2
  29. data/lib/google/cloud/bigtable/routing_policy.rb +2 -2
  30. data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +3 -3
  31. data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +3 -3
  32. data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +3 -3
  33. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +3 -3
  34. data/lib/google/cloud/bigtable/row_range.rb +2 -2
  35. data/lib/google/cloud/bigtable/rows_mutator.rb +3 -3
  36. data/lib/google/cloud/bigtable/rows_reader.rb +10 -10
  37. data/lib/google/cloud/bigtable/sample_row_key.rb +2 -2
  38. data/lib/google/cloud/bigtable/service.rb +241 -245
  39. data/lib/google/cloud/bigtable/table.rb +5 -4
  40. data/lib/google/cloud/bigtable/table/cluster_state.rb +27 -6
  41. data/lib/google/cloud/bigtable/table/list.rb +2 -2
  42. data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
  43. data/lib/google/cloud/bigtable/value_range.rb +2 -2
  44. data/lib/google/cloud/bigtable/version.rb +1 -1
  45. metadata +18 -96
  46. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +0 -145
  47. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +0 -90
  48. data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +0 -144
  49. data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +0 -128
  50. data/lib/google/bigtable/admin/v2/common_pb.rb +0 -25
  51. data/lib/google/bigtable/admin/v2/instance_pb.rb +0 -75
  52. data/lib/google/bigtable/admin/v2/table_pb.rb +0 -91
  53. data/lib/google/bigtable/v2/bigtable_pb.rb +0 -113
  54. data/lib/google/bigtable/v2/bigtable_services_pb.rb +0 -68
  55. data/lib/google/bigtable/v2/data_pb.rb +0 -156
  56. data/lib/google/cloud/bigtable/admin.rb +0 -202
  57. data/lib/google/cloud/bigtable/admin/credentials.rb +0 -27
  58. data/lib/google/cloud/bigtable/admin/v2.rb +0 -222
  59. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +0 -1451
  60. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +0 -139
  61. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +0 -1257
  62. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +0 -133
  63. data/lib/google/cloud/bigtable/admin/v2/credentials.rb +0 -51
  64. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +0 -297
  65. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +0 -367
  66. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +0 -193
  67. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +0 -200
  68. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +0 -64
  69. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/options.rb +0 -33
  70. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +0 -151
  71. data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +0 -51
  72. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +0 -131
  73. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +0 -91
  74. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +0 -29
  75. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +0 -222
  76. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +0 -113
  77. data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +0 -39
  78. data/lib/google/cloud/bigtable/admin/v2/doc/google/type/expr.rb +0 -45
  79. data/lib/google/cloud/bigtable/v2.rb +0 -146
  80. data/lib/google/cloud/bigtable/v2/bigtable_client.rb +0 -591
  81. data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +0 -83
  82. data/lib/google/cloud/bigtable/v2/credentials.rb +0 -46
  83. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +0 -290
  84. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +0 -493
  85. data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +0 -131
  86. data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +0 -34
  87. data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7482026aa78be2730c7c84f2f9eb94b777b99a900903757b432b554018609e59
4
- data.tar.gz: 1bd67186d8e0b9b768dc15cf8c639dcdc17061fb8553c7102b3cd419540c3d88
3
+ metadata.gz: a096cf8d1c1d26e38753da0ac165bdec3491bd821ce49da374b35362d5dc32a2
4
+ data.tar.gz: b7c9b2b6832514c1861f8cd9c6af2e73b1c4c7c2fa1ce3354ff7dd125c769dea
5
5
  SHA512:
6
- metadata.gz: f55df34a047ea018755dfc3e0e68dd617f262fc0216ba53a65c6fd9b3d854aaf722d6a5cfa01d5d3cefc548767471688e049fcb309f5beccb3c92a8a66d6e43c
7
- data.tar.gz: 34dd6cebddf95f056bb33d4e57206fbb8d5ac35865205d87c87c8a26288c44729a96b0e7d21941821d064302d88e955ad34bb1e59672edc571d22cf41c7c9acb
6
+ metadata.gz: b40689f9ab7ef728fa6e156e2cd3c2aa8dbaa0e23adb957501ec2b016fc1dff0235485c2c95f2a9d2398bee9a070455fc36f55f2fcdd5cc4ebabb971c3155e66
7
+ data.tar.gz: 33383bc875ced164d0f32e230653c03b2786ffaa00f024145bfb3ee1e067412e60eedb28814a2571d904e1c3706bea34c3cbc9129b7063c7259050ccd38eb2bb
@@ -76,7 +76,7 @@ The environment variables that google-cloud-bigtable checks for project ID are:
76
76
  1. `BIGTABLE_PROJECT`
77
77
  2. `GOOGLE_CLOUD_PROJECT`
78
78
 
79
- The environment variables that google-cloud-bigtable checks for credentials are configured on {Google::Cloud::Bigtable::V2::Credentials}:
79
+ The environment variables that google-cloud-bigtable checks for credentials are configured on {Google::Cloud::Bigtable::Credentials}:
80
80
 
81
81
  1. `BIGTABLE_CREDENTIALS` - Path to JSON file, or JSON contents
82
82
  2. `BIGTABLE_KEYFILE` - Path to JSON file, or JSON contents
@@ -1,5 +1,59 @@
1
1
  # Release History
2
2
 
3
+ ### 2.1.0 / 2020-09-17
4
+
5
+ #### Features
6
+
7
+ * quota_project can be set via library configuration ([#7630](https://www.github.com/googleapis/google-cloud-ruby/issues/7630))
8
+
9
+ ### 2.0.0 / 2020-08-06
10
+
11
+ This is a major update that removes the "low-level" client interface code, and
12
+ instead adds the new `google-cloud-bigtable-v2` and
13
+ `google-cloud-bigtable-admin-v2` gems as dependencies. The new dependencies
14
+ are rewritten low-level clients, produced by a next-generation client code
15
+ generator, with improved performance and stability.
16
+
17
+ This change should have no effect on the high-level interface that most users
18
+ will use. The one exception is that the (mostly undocumented) `client_config`
19
+ argument, for adjusting low-level parameters such as RPC retry settings on
20
+ client objects, has been removed. If you need to adjust these parameters, use
21
+ the configuration interface in `google-cloud-bigtable-v2` and
22
+ `google-cloud-bigtable-admin-v2`.
23
+
24
+ Substantial changes have been made in the low-level interfaces, however. If you
25
+ are using the low-level classes under the `Google::Cloud::Bigtable::V2` or
26
+ `Google::Cloud::Bigtable::Admin::V2` modules, please review the docs for the
27
+ new `google-cloud-bigtable-v2` and `google-cloud-bigtable-admin-v2` gems.
28
+ In particular:
29
+
30
+ * Some classes have been renamed, notably the client classes themselves.
31
+ * The client constructor takes a configuration block instead of configuration
32
+ keyword arguments.
33
+ * All RPC method arguments are now keyword arguments.
34
+
35
+ ### 1.3.0 / 2020-07-21
36
+
37
+ #### Features
38
+
39
+ * Add Managed Backups
40
+ * Add Cluster#create_backup, Cluster#backup and Cluster#backups
41
+ * Add Backup, Backup::Job and Backup::List
42
+ * Add Table::RestoreJob
43
+ * Add ClusterState#ready_optimizing?
44
+
45
+ ### 1.2.2 / 2020-05-28
46
+
47
+ #### Documentation
48
+
49
+ * Fix a few broken links
50
+
51
+ ### 1.2.1 / 2020-05-21
52
+
53
+ #### Bug Fixes
54
+
55
+ * Disable streaming RPC retries in lower-level client
56
+
3
57
  ### 1.2.0 / 2020-03-11
4
58
 
5
59
  #### Features
@@ -24,14 +24,8 @@ improved, *please* create a new issue on GitHub so we can talk about it.
24
24
 
25
25
  - [New issue][gh-ruby]
26
26
 
27
- Or, you can ask questions on the [Google Cloud Platform Slack][slack-ruby]. You
28
- can use the "ruby" channel for general Ruby questions, or use the
29
- "google-cloud-ruby" channel if you have questions about this gem in particular.
30
-
31
27
  [so-ruby]: http://stackoverflow.com/questions/tagged/google-cloud-platform+ruby+bigtable
32
28
 
33
- [gh-search-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues?q=label%3A%22api%3A+bigtable%22
34
-
35
- [gh-ruby]: https://github.com/googlecloudplatform/google-cloud-ruby/issues/new
29
+ [gh-search-ruby]: https://github.com/googleapis/google-cloud-ruby/issues?q=label%3A%22api%3A+bigtable%22
36
30
 
37
- [slack-ruby]: https://gcp-slack.appspot.com/
31
+ [gh-ruby]: https://github.com/googleapis/google-cloud-ruby/issues/new
@@ -55,11 +55,6 @@ module Google
55
55
  # should already be composed with a `GRPC::Core::CallCredentials` object.
56
56
  # `Proc` will be used as an updater_proc for the gRPC channel. The proc transforms the
57
57
  # metadata for requests, generally, to give OAuth credentials.
58
- # @param client_config [Hash]
59
- # A hash for call options for each method.
60
- # See Google::Gax#construct_settings for the structure of
61
- # this data. Falls back to the default config if not specified
62
- # or the specified config is missing data points.
63
58
  # @return [Google::Cloud::Bigtable::Project]
64
59
  #
65
60
  # @example
@@ -69,13 +64,12 @@ module Google
69
64
  #
70
65
  # bigtable = gcloud.bigtable
71
66
  #
72
- def bigtable scope: nil, timeout: nil, credentials: nil, client_config: nil
67
+ def bigtable scope: nil, timeout: nil, credentials: nil
73
68
  Google::Cloud.bigtable(
74
- project_id: @project,
75
- credentials: (credentials || @keyfile),
76
- scope: scope,
77
- timeout: (timeout || @timeout),
78
- client_config: client_config
69
+ project_id: @project,
70
+ credentials: (credentials || @keyfile),
71
+ scope: scope,
72
+ timeout: (timeout || @timeout)
79
73
  )
80
74
  end
81
75
 
@@ -110,11 +104,6 @@ module Google
110
104
  # updater_proc is supplied.
111
105
  # @param timeout [Integer]
112
106
  # The default timeout, in seconds, for calls made through this client.
113
- # @param client_config [Hash]
114
- # A hash for call options for each method.
115
- # See Google::Gax#construct_settings for the structure of
116
- # this data. Falls back to the default config if not specified
117
- # or the specified config is missing data points. Optional.
118
107
  # @return [Google::Cloud::Bigtable::Project]
119
108
  #
120
109
  # @example
@@ -122,14 +111,13 @@ module Google
122
111
  #
123
112
  # bigtable = Google::Cloud.bigtable
124
113
  #
125
- def self.bigtable project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil
114
+ def self.bigtable project_id: nil, credentials: nil, scope: nil, timeout: nil
126
115
  require "google/cloud/bigtable"
127
116
  Google::Cloud::Bigtable.new(
128
- project_id: project_id,
129
- credentials: credentials,
130
- scope: scope,
131
- timeout: timeout,
132
- client_config: client_config
117
+ project_id: project_id,
118
+ credentials: credentials,
119
+ scope: scope,
120
+ timeout: timeout
133
121
  )
134
122
  end
135
123
  end
@@ -149,6 +137,21 @@ Google::Cloud.configure.add_config! :bigtable do |config|
149
137
  default_emulator = Google::Cloud::Config.deferred do
150
138
  ENV["BIGTABLE_EMULATOR_HOST"]
151
139
  end
140
+ default_scopes = [
141
+ "https://www.googleapis.com/auth/bigtable.admin",
142
+ "https://www.googleapis.com/auth/bigtable.admin.cluster",
143
+ "https://www.googleapis.com/auth/bigtable.admin.instance",
144
+ "https://www.googleapis.com/auth/bigtable.admin.table",
145
+ "https://www.googleapis.com/auth/bigtable.data",
146
+ "https://www.googleapis.com/auth/bigtable.data.readonly",
147
+ "https://www.googleapis.com/auth/cloud-bigtable.admin",
148
+ "https://www.googleapis.com/auth/cloud-bigtable.admin.cluster",
149
+ "https://www.googleapis.com/auth/cloud-bigtable.admin.table",
150
+ "https://www.googleapis.com/auth/cloud-bigtable.data",
151
+ "https://www.googleapis.com/auth/cloud-bigtable.data.readonly",
152
+ "https://www.googleapis.com/auth/cloud-platform",
153
+ "https://www.googleapis.com/auth/cloud-platform.read-only"
154
+ ]
152
155
 
153
156
  config.add_field! :project_id, default_project, match: String, allow_nil: true
154
157
  config.add_alias! :project, :project_id
@@ -162,10 +165,10 @@ Google::Cloud.configure.add_config! :bigtable do |config|
162
165
  Proc
163
166
  ],
164
167
  allow_nil: true
165
- config.add_field! :scope, nil, match: [String, Array]
168
+ config.add_field! :scope, default_scopes, match: [String, Array]
169
+ config.add_field! :quota_project, nil, match: String
166
170
  config.add_field! :timeout, nil, match: Integer
167
- config.add_field! :client_config, nil, match: Hash
168
- config.add_field! :emulator_host, default_emulator,
169
- match: String, allow_nil: true
170
- config.add_field! :endpoint, nil, match: String
171
+ config.add_field! :emulator_host, default_emulator, match: String, allow_nil: true
172
+ config.add_field! :endpoint, "bigtable.googleapis.com", match: String
173
+ config.add_field! :endpoint_admin, "bigtableadmin.googleapis.com", match: String
171
174
  end
@@ -51,6 +51,8 @@ module Google
51
51
  # metadata for requests, generally, to give OAuth credentials.
52
52
  # @param [String] endpoint Override of the endpoint host name. Optional.
53
53
  # If the param is nil, uses the default endpoint.
54
+ # @param [String] endpoint_admin Override of the admin service endpoint host name. Optional.
55
+ # If the param is nil, uses the default admin endpoint.
54
56
  # @param [String] emulator_host Bigtable emulator host. Optional.
55
57
  # If the parameter is nil, uses the value of the `emulator_host` config.
56
58
  # @param scope [Array<String>]
@@ -59,11 +61,6 @@ module Google
59
61
  # APIs](https://developers.google.com/identity/protocols/OAuth2).
60
62
  # The OAuth scopes for this service. This parameter is ignored if an
61
63
  # updater_proc is supplied.
62
- # @param client_config [Hash]
63
- # A hash for call options for each method.
64
- # See Google::Gax#construct_settings for the structure of
65
- # this data. Falls back to the default config if not specified
66
- # or the specified config is missing data points.
67
64
  # @param timeout [Integer]
68
65
  # The default timeout, in seconds, for calls made through this client. Optional.
69
66
  # @return [Google::Cloud::Bigtable::Project]
@@ -73,28 +70,28 @@ module Google
73
70
  #
74
71
  # client = Google::Cloud::Bigtable.new
75
72
  #
76
- def self.new project_id: nil, credentials: nil, emulator_host: nil, scope: nil, client_config: nil, endpoint: nil,
73
+ def self.new project_id: nil,
74
+ credentials: nil,
75
+ emulator_host: nil,
76
+ scope: nil,
77
+ endpoint: nil,
78
+ endpoint_admin: nil,
77
79
  timeout: nil
78
80
  project_id ||= default_project_id
79
81
  scope ||= configure.scope
80
82
  timeout ||= configure.timeout
81
- client_config ||= configure.client_config
82
83
  emulator_host ||= configure.emulator_host
83
84
  endpoint ||= configure.endpoint
85
+ endpoint_admin ||= configure.endpoint_admin
84
86
 
85
- if emulator_host
86
- return new_with_emulator project_id, emulator_host, timeout,
87
- client_config
88
- end
87
+ return new_with_emulator project_id, emulator_host, timeout if emulator_host
89
88
 
90
89
  credentials = resolve_credentials credentials, scope
91
90
  project_id = resolve_project_id project_id, credentials
92
91
  raise ArgumentError, "project_id is missing" if project_id.empty?
93
92
 
94
- service = Bigtable::Service.new(
95
- project_id, credentials,
96
- host: endpoint, timeout: timeout, client_config: client_config
97
- )
93
+ service = Bigtable::Service.new \
94
+ project_id, credentials, host: endpoint, host_admin: endpoint_admin, timeout: timeout
98
95
  Bigtable::Project.new service
99
96
  end
100
97
 
@@ -113,10 +110,10 @@ module Google
113
110
  # * `scope` - (String, Array<String>) The OAuth 2.0 scopes controlling
114
111
  # the set of resources and operations that the connection can access.
115
112
  # * `timeout` - (Integer) Default timeout to use in requests.
116
- # * `client_config` - (Hash) A hash of values to override the default
117
- # behavior of the API client.
118
113
  # * `endpoint` - (String) Override of the endpoint host name, or `nil`
119
114
  # to use the default endpoint.
115
+ # * `endpoint_admin` - (String) Override of the admin service endpoint
116
+ # host name, or `nil` to use the default admin endpoint.
120
117
  #
121
118
  # @return [Google::Cloud::Config] The configuration object the
122
119
  # Google::Cloud::Bigtable library uses.
@@ -130,18 +127,13 @@ module Google
130
127
  # @private
131
128
  # New client given an emulator host.
132
129
  #
133
- def self.new_with_emulator project_id, emulator_host, timeout,
134
- client_config
130
+ def self.new_with_emulator project_id, emulator_host, timeout
135
131
  project_id = project_id.to_s # Always cast to a string
136
132
  raise ArgumentError, "project_id is missing" if project_id.empty?
137
133
 
138
- Bigtable::Project.new(
139
- Bigtable::Service.new(
140
- project_id, :this_channel_is_insecure,
141
- host: emulator_host, timeout: timeout,
142
- client_config: client_config
143
- )
144
- )
134
+ service = Bigtable::Service.new \
135
+ project_id, :this_channel_is_insecure, host: emulator_host, host_admin: emulator_host, timeout: timeout
136
+ Bigtable::Project.new service
145
137
  end
146
138
 
147
139
  # @private
@@ -193,7 +193,7 @@ module Google
193
193
  #
194
194
  def routing_policy= policy
195
195
  routing_policy_grpc = policy.to_grpc
196
- if routing_policy_grpc.is_a? Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting
196
+ if routing_policy_grpc.is_a? Google::Cloud::Bigtable::Admin::V2::AppProfile::SingleClusterRouting
197
197
  @grpc.single_cluster_routing = routing_policy_grpc
198
198
  @changed_fields["routing_policy"] = "single_cluster_routing"
199
199
  else
@@ -417,8 +417,8 @@ module Google
417
417
  # @private
418
418
  #
419
419
  # Creates a new Instance instance from a
420
- # Google::Bigtable::Admin::V2::Table.
421
- # @param grpc [Google::Bigtable::Admin::V2::Table]
420
+ # Google::Cloud::Bigtable::Admin::V2::Table.
421
+ # @param grpc [Google::Cloud::Bigtable::Admin::V2::Table]
422
422
  # @param service [Google::Cloud::Bigtable::Service]
423
423
  # @return [Google::Cloud::Bigtable::Table]
424
424
  def self.from_grpc grpc, service
@@ -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
  #
@@ -135,8 +135,10 @@ module Google
135
135
  end
136
136
 
137
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> ]
138
+ # New Snapshot::List from a Gapic::PagedEnumerable<Google::Cloud::Bigtable::Admin::V2::AppProfile>
139
+ # object.
140
+ #
141
+ # @param grpc [Gapic::PagedEnumerable<Google::Cloud::Bigtable::Admin::V2::AppProfile> ]
140
142
  # @param service [Google::Cloud::Bigtable::Service]
141
143
  # @return [Array<Google::Cloud::Bigtable::AppProfile>]
142
144
  def self.from_grpc grpc, service
@@ -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::Cloud::Bigtable::Admin::V2::Backup.
305
+ #
306
+ # @param grpc [Google::Cloud::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