google-cloud-bigtable 1.2.2 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +1 -1
  3. data/CHANGELOG.md +57 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/OVERVIEW.md +4 -4
  6. data/lib/google-cloud-bigtable.rb +30 -27
  7. data/lib/google/cloud/bigtable.rb +18 -26
  8. data/lib/google/cloud/bigtable/app_profile.rb +3 -3
  9. data/lib/google/cloud/bigtable/app_profile/list.rb +6 -4
  10. data/lib/google/cloud/bigtable/backup.rb +445 -0
  11. data/lib/google/cloud/bigtable/backup/job.rb +87 -0
  12. data/lib/google/cloud/bigtable/backup/list.rb +167 -0
  13. data/lib/google/cloud/bigtable/chunk_processor.rb +1 -1
  14. data/lib/google/cloud/bigtable/cluster.rb +101 -2
  15. data/lib/google/cloud/bigtable/cluster/list.rb +2 -2
  16. data/lib/google/cloud/bigtable/column_family.rb +2 -2
  17. data/lib/google/cloud/bigtable/column_family_map.rb +11 -11
  18. data/lib/google/cloud/bigtable/column_range.rb +2 -2
  19. data/lib/google/cloud/bigtable/credentials.rb +36 -2
  20. data/lib/google/cloud/bigtable/gc_rule.rb +7 -7
  21. data/lib/google/cloud/bigtable/instance.rb +8 -8
  22. data/lib/google/cloud/bigtable/instance/cluster_map.rb +1 -1
  23. data/lib/google/cloud/bigtable/instance/list.rb +2 -2
  24. data/lib/google/cloud/bigtable/longrunning_job.rb +13 -2
  25. data/lib/google/cloud/bigtable/mutation_entry.rb +16 -15
  26. data/lib/google/cloud/bigtable/mutation_operations.rb +6 -6
  27. data/lib/google/cloud/bigtable/project.rb +1 -1
  28. data/lib/google/cloud/bigtable/read_modify_write_rule.rb +2 -2
  29. data/lib/google/cloud/bigtable/read_operations.rb +2 -2
  30. data/lib/google/cloud/bigtable/routing_policy.rb +2 -2
  31. data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +3 -3
  32. data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +3 -3
  33. data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +3 -3
  34. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +3 -3
  35. data/lib/google/cloud/bigtable/row_range.rb +2 -2
  36. data/lib/google/cloud/bigtable/rows_mutator.rb +3 -3
  37. data/lib/google/cloud/bigtable/rows_reader.rb +10 -10
  38. data/lib/google/cloud/bigtable/sample_row_key.rb +2 -2
  39. data/lib/google/cloud/bigtable/service.rb +282 -245
  40. data/lib/google/cloud/bigtable/table.rb +5 -4
  41. data/lib/google/cloud/bigtable/table/cluster_state.rb +27 -6
  42. data/lib/google/cloud/bigtable/table/list.rb +2 -2
  43. data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
  44. data/lib/google/cloud/bigtable/value_range.rb +2 -2
  45. data/lib/google/cloud/bigtable/version.rb +1 -1
  46. metadata +16 -94
  47. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +0 -145
  48. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +0 -90
  49. data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +0 -208
  50. data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +0 -154
  51. data/lib/google/bigtable/admin/v2/common_pb.rb +0 -30
  52. data/lib/google/bigtable/admin/v2/instance_pb.rb +0 -74
  53. data/lib/google/bigtable/admin/v2/table_pb.rb +0 -127
  54. data/lib/google/bigtable/v2/bigtable_pb.rb +0 -113
  55. data/lib/google/bigtable/v2/bigtable_services_pb.rb +0 -68
  56. data/lib/google/bigtable/v2/data_pb.rb +0 -156
  57. data/lib/google/cloud/bigtable/admin.rb +0 -202
  58. data/lib/google/cloud/bigtable/admin/credentials.rb +0 -27
  59. data/lib/google/cloud/bigtable/admin/v2.rb +0 -223
  60. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +0 -1451
  61. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +0 -139
  62. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +0 -1734
  63. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +0 -163
  64. data/lib/google/cloud/bigtable/admin/v2/credentials.rb +0 -51
  65. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +0 -297
  66. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +0 -587
  67. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +0 -193
  68. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +0 -303
  69. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +0 -64
  70. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/options.rb +0 -33
  71. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +0 -151
  72. data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +0 -51
  73. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +0 -131
  74. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +0 -91
  75. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +0 -29
  76. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +0 -222
  77. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +0 -113
  78. data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +0 -39
  79. data/lib/google/cloud/bigtable/admin/v2/doc/google/type/expr.rb +0 -45
  80. data/lib/google/cloud/bigtable/v2.rb +0 -146
  81. data/lib/google/cloud/bigtable/v2/bigtable_client.rb +0 -591
  82. data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +0 -83
  83. data/lib/google/cloud/bigtable/v2/credentials.rb +0 -46
  84. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +0 -290
  85. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +0 -493
  86. data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +0 -131
  87. data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +0 -34
  88. 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: 22ba3e63a3716fdb413bafb9c74a72f8f86e356a5b8a3f3a2776522313d7efbd
4
- data.tar.gz: 984879dec7e158489426f4f12c41b947e604c6164f0ebe26aa01dae7216ad6f5
3
+ metadata.gz: c055b86b9d279e27fdb78ec71ddb8babd48661349c0404db696496c84fb3d8e1
4
+ data.tar.gz: 4c3557a421b16d56680b9c9a39f1d5073a6886efe5198262df0ca02494a000be
5
5
  SHA512:
6
- metadata.gz: 7afc6e313ac4fda9ccd2d810d5b698d0790fbfbcbab2ddcdd748c8597b7d979c83e24de30d89a0cd201fe7e06afb3597961620c3efa68a6b205500e0c146ed6d
7
- data.tar.gz: 05c513ddcd8aabf0f9f53100c863708e648384b9252c17e10a8e721446b579f2e6466f9d3d87bf7ce5fdc4fbca94e0cf0707f585b79bf77703a0c4b35da9cade
6
+ metadata.gz: da4f265ebb057cc6e291104edf56cfdf121efc9a75def53dbc9831aba3708049eb68a53c378c147c9f49277afa8cf46822ce01c4e11aa8fcefd907522408862c
7
+ data.tar.gz: 79be648c3e85fe49e9a285fcdec140e16e015e510b8d5327a802c0e1d36b825d4c4ab2cb52f63c9d5e8b96ef3177c0f91648ea56e5aac5c045ffba90e0a1c101
@@ -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,62 @@
1
1
  # Release History
2
2
 
3
+ ### 2.2.1 / 2021-01-13
4
+
5
+ #### Documentation
6
+
7
+ * Use consistent column family and field names in samples
8
+
9
+ ### 2.2.0 / 2020-11-11
10
+
11
+ #### Features
12
+
13
+ * Add Backup-level IAM Policy support
14
+ * Add Backup#policy
15
+ * Add Backup#update_policy
16
+ * Add Backup#test_iam_permissions
17
+
18
+ ### 2.1.0 / 2020-09-17
19
+
20
+ #### Features
21
+
22
+ * quota_project can be set via library configuration ([#7630](https://www.github.com/googleapis/google-cloud-ruby/issues/7630))
23
+
24
+ ### 2.0.0 / 2020-08-06
25
+
26
+ This is a major update that removes the "low-level" client interface code, and
27
+ instead adds the new `google-cloud-bigtable-v2` and
28
+ `google-cloud-bigtable-admin-v2` gems as dependencies. The new dependencies
29
+ are rewritten low-level clients, produced by a next-generation client code
30
+ generator, with improved performance and stability.
31
+
32
+ This change should have no effect on the high-level interface that most users
33
+ will use. The one exception is that the (mostly undocumented) `client_config`
34
+ argument, for adjusting low-level parameters such as RPC retry settings on
35
+ client objects, has been removed. If you need to adjust these parameters, use
36
+ the configuration interface in `google-cloud-bigtable-v2` and
37
+ `google-cloud-bigtable-admin-v2`.
38
+
39
+ Substantial changes have been made in the low-level interfaces, however. If you
40
+ are using the low-level classes under the `Google::Cloud::Bigtable::V2` or
41
+ `Google::Cloud::Bigtable::Admin::V2` modules, please review the docs for the
42
+ new `google-cloud-bigtable-v2` and `google-cloud-bigtable-admin-v2` gems.
43
+ In particular:
44
+
45
+ * Some classes have been renamed, notably the client classes themselves.
46
+ * The client constructor takes a configuration block instead of configuration
47
+ keyword arguments.
48
+ * All RPC method arguments are now keyword arguments.
49
+
50
+ ### 1.3.0 / 2020-07-21
51
+
52
+ #### Features
53
+
54
+ * Add Managed Backups
55
+ * Add Cluster#create_backup, Cluster#backup and Cluster#backups
56
+ * Add Backup, Backup::Job and Backup::List
57
+ * Add Table::RestoreJob
58
+ * Add ClusterState#ready_optimizing?
59
+
3
60
  ### 1.2.2 / 2020-05-28
4
61
 
5
62
  #### Documentation
@@ -45,7 +45,7 @@ there is a small amount of setup:
45
45
 
46
46
  ```sh
47
47
  $ cd google-cloud-bigtable/
48
- $ bundle exec rake bundleupdate
48
+ $ bundle install
49
49
  ```
50
50
 
51
51
  ## Console
@@ -194,8 +194,8 @@ table = bigtable.table("my-instance", "my-table")
194
194
 
195
195
  entry = table.new_mutation_entry("user-1")
196
196
  entry.set_cell(
197
- "cf-1",
198
- "field-1",
197
+ "cf1",
198
+ "field1",
199
199
  "XYZ",
200
200
  timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
201
201
  ).delete_cells("cf2", "field02")
@@ -245,8 +245,8 @@ table = bigtable.table("my-instance", "my-table")
245
245
  predicate_filter = Google::Cloud::Bigtable::RowFilter.key("user-10")
246
246
  on_match_mutations = Google::Cloud::Bigtable::MutationEntry.new
247
247
  on_match_mutations.set_cell(
248
- "cf-1",
249
- "field-1",
248
+ "cf1",
249
+ "field1",
250
250
  "XYZ",
251
251
  timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
252
252
  ).delete_cells("cf2", "field02")
@@ -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,445 @@
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/policy"
22
+ require "google/cloud/bigtable/table/restore_job"
23
+
24
+
25
+ module Google
26
+ module Cloud
27
+ module Bigtable
28
+ ##
29
+ # # Backup
30
+ #
31
+ # A backup of a Cloud Bigtable table. See {Cluster#create_backup}, {Cluster#backup} and {Cluster#backups}.
32
+ #
33
+ # @example
34
+ # require "google/cloud/bigtable"
35
+ #
36
+ # bigtable = Google::Cloud::Bigtable.new
37
+ # instance = bigtable.instance("my-instance")
38
+ # cluster = instance.cluster("my-cluster")
39
+ #
40
+ # backup = cluster.backup("my-backup")
41
+ #
42
+ # # Update
43
+ # backup.expire_time = Time.now + 60 * 60 * 7
44
+ # backup.save
45
+ #
46
+ # # Delete
47
+ # backup.delete
48
+ #
49
+ class Backup
50
+ # @private
51
+ # The gRPC Service object.
52
+ attr_accessor :service
53
+
54
+ ##
55
+ # @private A list of attributes that were updated.
56
+ attr_reader :updates
57
+
58
+ # @private
59
+ #
60
+ # Creates a new Backup instance.
61
+ def initialize grpc, service
62
+ @grpc = grpc
63
+ @service = service
64
+ end
65
+
66
+ ##
67
+ # The unique identifier for the project to which the backup belongs.
68
+ #
69
+ # @return [String]
70
+ #
71
+ def project_id
72
+ @grpc.name.split("/")[1]
73
+ end
74
+
75
+ ##
76
+ # The unique identifier for the instance to which the backup belongs.
77
+ #
78
+ # @return [String]
79
+ #
80
+ def instance_id
81
+ @grpc.name.split("/")[3]
82
+ end
83
+
84
+ ##
85
+ # The unique identifier for the cluster to which the backup belongs.
86
+ #
87
+ # @return [String]
88
+ #
89
+ def cluster_id
90
+ @grpc.name.split("/")[5]
91
+ end
92
+
93
+ ##
94
+ # The unique identifier for the backup.
95
+ #
96
+ # @return [String]
97
+ #
98
+ def backup_id
99
+ @grpc.name.split("/")[7]
100
+ end
101
+
102
+ ##
103
+ # The unique name of the backup. Value in the form
104
+ # `projects/<project>/instances/<instance>/clusters/<cluster>/backups/<backup>`.
105
+ #
106
+ # @return [String]
107
+ #
108
+ def path
109
+ @grpc.name
110
+ end
111
+
112
+ ##
113
+ # The table from which this backup was created.
114
+ #
115
+ # @param perform_lookup [Boolean] Creates table object without verifying that the table resource exists. Calls
116
+ # made on this object will raise errors if the table does not exist. Default value is `false`. Optional. Helps
117
+ # to reduce admin API calls.
118
+ # @param view [Symbol] Table view type. Default view type is `:SCHEMA_VIEW`. Valid view types are:
119
+ #
120
+ # * `:NAME_ONLY` - Only populates `name`.
121
+ # * `:SCHEMA_VIEW` - Only populates `name` and fields related to the table's schema.
122
+ # * `:REPLICATION_VIEW` - Only populates `name` and fields related to the table's replication state.
123
+ # * `:FULL` - Populates all fields.
124
+ #
125
+ # @return [Table]
126
+ #
127
+ def source_table perform_lookup: nil, view: nil
128
+ table = Table.from_path @grpc.source_table, service
129
+ return table.reload! view: view if perform_lookup
130
+ table
131
+ end
132
+
133
+ ##
134
+ # The expiration time of the backup, with microseconds granularity that must be at least 6 hours and at most 30
135
+ # days from the time the request is received. Once the expire time has passed, Cloud Bigtable will delete the
136
+ # backup and free the resources used by the backup.
137
+ #
138
+ # @return [Time]
139
+ #
140
+ def expire_time
141
+ Convert.timestamp_to_time @grpc.expire_time
142
+ end
143
+
144
+ ##
145
+ # Sets the expiration time of the backup, with microseconds granularity that must be at least 6 hours and at
146
+ # most 30 days from the time the request is received. Once the {#expire_time} has passed, Cloud Bigtable will
147
+ # delete the backup and free the resources used by the backup.
148
+ #
149
+ # @param [Time] new_expire_time The new expiration time of the backup.
150
+ #
151
+ def expire_time= new_expire_time
152
+ @grpc.expire_time = Convert.time_to_timestamp new_expire_time
153
+ end
154
+
155
+ ##
156
+ # The time that the backup was started (i.e. approximately the time the `CreateBackup` request is received). The
157
+ # row data in this backup will be no older than this timestamp.
158
+ #
159
+ # @return [Time]
160
+ #
161
+ def start_time
162
+ Convert.timestamp_to_time @grpc.start_time
163
+ end
164
+
165
+ ##
166
+ # The time that the backup was finished. The row data in the backup will be no newer than this timestamp.
167
+ #
168
+ # @return [Time]
169
+ #
170
+ def end_time
171
+ Convert.timestamp_to_time @grpc.end_time
172
+ end
173
+
174
+ ##
175
+ # The size of the backup in bytes.
176
+ #
177
+ # @return [Integer]
178
+ #
179
+ def size_bytes
180
+ @grpc.size_bytes
181
+ end
182
+
183
+ ##
184
+ # The current state of the backup. Possible values are `:CREATING` and `:READY`.
185
+ #
186
+ # @return [Symbol]
187
+ #
188
+ def state
189
+ @grpc.state
190
+ end
191
+
192
+ ##
193
+ # The backup is currently being created, and may be destroyed if the creation process encounters an error.
194
+ #
195
+ # @return [Boolean]
196
+ #
197
+ def creating?
198
+ state == :CREATING
199
+ end
200
+
201
+ ##
202
+ # The backup has been successfully created and is ready to serve requests.
203
+ #
204
+ # @return [Boolean]
205
+ #
206
+ def ready?
207
+ state == :READY
208
+ end
209
+
210
+ ##
211
+ # Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
212
+ # policy for the backup.
213
+ #
214
+ # @see https://cloud.google.com/bigtable/docs/access-control
215
+ #
216
+ # @yield [policy] A block for updating the policy. The latest policy
217
+ # will be read from the Bigtable service and passed to the block. After
218
+ # the block completes, the modified policy will be written to the
219
+ # service.
220
+ # @yieldparam [Policy] policy the current Cloud IAM Policy for this
221
+ # backup.
222
+ #
223
+ # @return [Policy] The current Cloud IAM Policy for the backup.
224
+ #
225
+ # @example
226
+ # require "google/cloud/bigtable"
227
+ #
228
+ # bigtable = Google::Cloud::Bigtable.new
229
+ # instance = bigtable.instance("my-instance")
230
+ # cluster = instance.cluster("my-cluster")
231
+ #
232
+ # backup = cluster.backup("my-backup")
233
+ #
234
+ # policy = backup.policy
235
+ #
236
+ # @example Update the policy by passing a block.
237
+ # require "google/cloud/bigtable"
238
+ #
239
+ # bigtable = Google::Cloud::Bigtable.new
240
+ # instance = bigtable.instance("my-instance")
241
+ # cluster = instance.cluster("my-cluster")
242
+ #
243
+ # backup = cluster.backup("my-backup")
244
+ #
245
+ # backup.policy do |p|
246
+ # p.add("roles/owner", "user:owner@example.com")
247
+ # end # 2 API calls
248
+ #
249
+ def policy
250
+ ensure_service!
251
+ grpc = service.get_backup_policy instance_id, cluster_id, backup_id
252
+ policy = Policy.from_grpc grpc
253
+ return policy unless block_given?
254
+ yield policy
255
+ update_policy policy
256
+ end
257
+
258
+ ##
259
+ # Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
260
+ # policy for the backup. The policy should be read from {#policy}.
261
+ # See {Google::Cloud::Bigtable::Policy} for an explanation of the policy
262
+ # `etag` property and how to modify policies.
263
+ #
264
+ # You can also update the policy by passing a block to {#policy}, which
265
+ # will call this method internally after the block completes.
266
+ #
267
+ # @param new_policy [Policy] a new or modified Cloud IAM Policy for this
268
+ # backup
269
+ #
270
+ # @return [Policy] The policy returned by the API update operation.
271
+ #
272
+ # @example
273
+ # require "google/cloud/bigtable"
274
+ #
275
+ # bigtable = Google::Cloud::Bigtable.new
276
+ # instance = bigtable.instance("my-instance")
277
+ # cluster = instance.cluster("my-cluster")
278
+ #
279
+ # backup = cluster.backup("my-backup")
280
+ #
281
+ # policy = backup.policy
282
+ # policy.add("roles/owner", "user:owner@example.com")
283
+ # updated_policy = backup.update_policy(policy)
284
+ #
285
+ # puts updated_policy.roles
286
+ #
287
+ def update_policy new_policy
288
+ ensure_service!
289
+ grpc = service.set_backup_policy instance_id, cluster_id, backup_id, new_policy.to_grpc
290
+ Policy.from_grpc grpc
291
+ end
292
+ alias policy= update_policy
293
+
294
+ ##
295
+ # Tests the specified permissions against the [Cloud
296
+ # IAM](https://cloud.google.com/iam/) access control policy.
297
+ #
298
+ # @see https://cloud.google.com/iam/docs/managing-policies Managing Policies
299
+ # @see https://cloud.google.com/bigtable/docs/access-control Access Control
300
+ #
301
+ # @param permissions [String, Array<String>] permissions The set of permissions to
302
+ # check access for. Permissions with wildcards (such as `*` or `bigtable.*`) are
303
+ # not allowed.
304
+ # See [Access Control](https://cloud.google.com/bigtable/docs/access-control).
305
+ #
306
+ # @return [Array<String>] The permissions that are configured for the policy.
307
+ #
308
+ # @example
309
+ # require "google/cloud/bigtable"
310
+ #
311
+ # bigtable = Google::Cloud::Bigtable.new
312
+ # instance = bigtable.instance("my-instance")
313
+ # cluster = instance.cluster("my-cluster")
314
+ #
315
+ # backup = cluster.backup("my-backup")
316
+ #
317
+ # permissions = backup.test_iam_permissions(
318
+ # "bigtable.backups.delete",
319
+ # "bigtable.backups.get"
320
+ # )
321
+ # permissions.include? "bigtable.backups.delete" #=> false
322
+ # permissions.include? "bigtable.backups.get" #=> true
323
+ #
324
+ def test_iam_permissions *permissions
325
+ ensure_service!
326
+ grpc = service.test_backup_permissions instance_id, cluster_id, backup_id, permissions.flatten
327
+ grpc.permissions.to_a
328
+ end
329
+
330
+ ##
331
+ # Creates a new table by restoring from a completed backup.
332
+ #
333
+ # @param table_id [String] The table ID for the new table. This table must not yet exist. Required.
334
+ #
335
+ # @return [Google::Cloud::Bigtable::Table::RestoreJob] The job representing the long-running, asynchronous
336
+ # processing of a backup restore table operation.
337
+ #
338
+ # @example
339
+ # require "google/cloud/bigtable"
340
+ #
341
+ # bigtable = Google::Cloud::Bigtable.new
342
+ # instance = bigtable.instance("my-instance")
343
+ # cluster = instance.cluster("my-cluster")
344
+ #
345
+ # backup = cluster.backup("my-backup")
346
+ #
347
+ # job = backup.restore("my-new-table")
348
+ #
349
+ # job.wait_until_done!
350
+ # job.done? #=> true
351
+ #
352
+ # if job.error?
353
+ # status = job.error
354
+ # else
355
+ # table = job.table
356
+ # optimized = job.optimize_table_operation_name
357
+ # end
358
+ #
359
+ def restore table_id
360
+ grpc = service.restore_table table_id, instance_id, cluster_id, backup_id
361
+ Table::RestoreJob.from_grpc grpc, service
362
+ end
363
+
364
+ ##
365
+ # Updates the backup.
366
+ #
367
+ # `expire_time` is the only updatable field.
368
+ #
369
+ # @return [Boolean] Returns `true` if the update succeeded.
370
+ #
371
+ # @example
372
+ # require "google/cloud/bigtable"
373
+ #
374
+ # bigtable = Google::Cloud::Bigtable.new
375
+ # instance = bigtable.instance("my-instance")
376
+ # cluster = instance.cluster("my-cluster")
377
+ #
378
+ # backup = cluster.backup("my-backup")
379
+ #
380
+ # # Update
381
+ # backup.expire_time = Time.now + 60 * 60 * 7
382
+ # backup.save
383
+ #
384
+ def save
385
+ ensure_service!
386
+ @grpc = service.update_backup @grpc, [:expire_time]
387
+ true
388
+ end
389
+ alias update save
390
+
391
+ ##
392
+ # Reloads backup data.
393
+ #
394
+ # @return [Google::Cloud::Bigtable::Backup]
395
+ #
396
+ def reload!
397
+ @grpc = service.get_backup instance_id, cluster_id, backup_id
398
+ self
399
+ end
400
+
401
+ ##
402
+ # Permanently deletes the backup.
403
+ #
404
+ # @return [Boolean] Returns `true` if the backup was deleted.
405
+ #
406
+ # @example
407
+ # require "google/cloud/bigtable"
408
+ #
409
+ # bigtable = Google::Cloud::Bigtable.new
410
+ # instance = bigtable.instance("my-instance")
411
+ # cluster = instance.cluster("my-cluster")
412
+ #
413
+ # backup = cluster.backup("my-backup")
414
+ #
415
+ # backup.delete
416
+ #
417
+ def delete
418
+ ensure_service!
419
+ service.delete_backup instance_id, cluster_id, backup_id
420
+ true
421
+ end
422
+
423
+ # @private
424
+ #
425
+ # Creates a new Backup instance from a Google::Cloud::Bigtable::Admin::V2::Backup.
426
+ #
427
+ # @param grpc [Google::Cloud::Bigtable::Admin::V2::Backup]
428
+ # @param service [Google::Cloud::Bigtable::Service]
429
+ # @return [Google::Cloud::Bigtable::Backup]
430
+ def self.from_grpc grpc, service
431
+ new grpc, service
432
+ end
433
+
434
+ protected
435
+
436
+ # @private
437
+ #
438
+ # Raise an error unless an active connection to the service is available.
439
+ def ensure_service!
440
+ raise "Must have active connection to service" unless service
441
+ end
442
+ end
443
+ end
444
+ end
445
+ end