google-cloud-bigtable 0.6.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +4 -26
  3. data/CHANGELOG.md +85 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/OVERVIEW.md +388 -19
  6. data/lib/google-cloud-bigtable.rb +19 -22
  7. data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +1 -1
  8. data/lib/google/bigtable/v2/bigtable_pb.rb +3 -0
  9. data/lib/google/bigtable/v2/bigtable_services_pb.rb +1 -1
  10. data/lib/google/cloud/bigtable.rb +11 -17
  11. data/lib/google/cloud/bigtable/admin.rb +1 -1
  12. data/lib/google/cloud/bigtable/admin/v2.rb +1 -1
  13. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1 -1
  14. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +42 -21
  15. data/lib/google/cloud/bigtable/app_profile.rb +162 -96
  16. data/lib/google/cloud/bigtable/app_profile/job.rb +5 -8
  17. data/lib/google/cloud/bigtable/app_profile/list.rb +18 -12
  18. data/lib/google/cloud/bigtable/chunk_processor.rb +24 -36
  19. data/lib/google/cloud/bigtable/cluster.rb +45 -18
  20. data/lib/google/cloud/bigtable/cluster/job.rb +3 -7
  21. data/lib/google/cloud/bigtable/cluster/list.rb +22 -20
  22. data/lib/google/cloud/bigtable/column_family.rb +18 -231
  23. data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
  24. data/lib/google/cloud/bigtable/column_range.rb +15 -7
  25. data/lib/google/cloud/bigtable/convert.rb +12 -4
  26. data/lib/google/cloud/bigtable/errors.rb +4 -1
  27. data/lib/google/cloud/bigtable/gc_rule.rb +188 -69
  28. data/lib/google/cloud/bigtable/instance.rb +209 -189
  29. data/lib/google/cloud/bigtable/instance/cluster_map.rb +17 -13
  30. data/lib/google/cloud/bigtable/instance/job.rb +6 -5
  31. data/lib/google/cloud/bigtable/instance/list.rb +18 -13
  32. data/lib/google/cloud/bigtable/longrunning_job.rb +7 -1
  33. data/lib/google/cloud/bigtable/mutation_entry.rb +36 -39
  34. data/lib/google/cloud/bigtable/mutation_operations.rb +90 -73
  35. data/lib/google/cloud/bigtable/policy.rb +9 -5
  36. data/lib/google/cloud/bigtable/project.rb +87 -196
  37. data/lib/google/cloud/bigtable/read_modify_write_rule.rb +15 -10
  38. data/lib/google/cloud/bigtable/read_operations.rb +42 -59
  39. data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
  40. data/lib/google/cloud/bigtable/row.rb +32 -21
  41. data/lib/google/cloud/bigtable/row_filter.rb +80 -35
  42. data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +119 -68
  43. data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +8 -2
  44. data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +117 -66
  45. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +24 -9
  46. data/lib/google/cloud/bigtable/row_range.rb +5 -0
  47. data/lib/google/cloud/bigtable/rows_mutator.rb +14 -21
  48. data/lib/google/cloud/bigtable/rows_reader.rb +23 -18
  49. data/lib/google/cloud/bigtable/sample_row_key.rb +6 -3
  50. data/lib/google/cloud/bigtable/service.rb +200 -253
  51. data/lib/google/cloud/bigtable/status.rb +76 -0
  52. data/lib/google/cloud/bigtable/table.rb +158 -262
  53. data/lib/google/cloud/bigtable/table/cluster_state.rb +17 -6
  54. data/lib/google/cloud/bigtable/table/list.rb +16 -9
  55. data/lib/google/cloud/bigtable/v2.rb +1 -1
  56. data/lib/google/cloud/bigtable/v2/bigtable_client.rb +12 -12
  57. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +16 -13
  58. data/lib/google/cloud/bigtable/value_range.rb +19 -13
  59. data/lib/google/cloud/bigtable/version.rb +1 -1
  60. metadata +67 -25
  61. data/lib/google/cloud/bigtable/table/column_family_map.rb +0 -70
@@ -26,6 +26,7 @@ require "google/cloud/config"
26
26
 
27
27
  module Google
28
28
  module Cloud
29
+ ##
29
30
  # Creates a new object for connecting to the Cloud Bigtable service.
30
31
  #
31
32
  # For more information on connecting to Google Cloud Platform, see the
@@ -39,7 +40,8 @@ module Google
39
40
  # updater_proc is supplied.
40
41
  # @param timeout [Integer]
41
42
  # The default timeout, in seconds, for calls made through this client.
42
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
43
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel,
44
+ # GRPC::Core::ChannelCredentials, Proc]
43
45
  # Provides the means for authenticating requests made by the client. This parameter can
44
46
  # be one of the following types.
45
47
  # `Google::Auth::Credentials` uses the properties of its represented keyfile for
@@ -61,23 +63,23 @@ module Google
61
63
  # @return [Google::Cloud::Bigtable::Project]
62
64
  #
63
65
  # @example
64
- # require "google/cloud"
66
+ # require "google/cloud/bigtable"
65
67
  #
66
68
  # gcloud = Google::Cloud.new
67
69
  #
68
70
  # bigtable = gcloud.bigtable
69
71
  #
70
-
71
72
  def bigtable scope: nil, timeout: nil, credentials: nil, client_config: nil
72
73
  Google::Cloud.bigtable(
73
- project_id: @project,
74
- credentials: (credentials || @keyfile),
75
- scope: scope,
76
- timeout: (timeout || @timeout),
74
+ project_id: @project,
75
+ credentials: (credentials || @keyfile),
76
+ scope: scope,
77
+ timeout: (timeout || @timeout),
77
78
  client_config: client_config
78
79
  )
79
80
  end
80
81
 
82
+ ##
81
83
  # Creates a Cloud Bigtable client instance for data, table admin and instance admin
82
84
  # operations.
83
85
  #
@@ -85,7 +87,8 @@ module Google
85
87
  # Project identifier for the Bigtable service you
86
88
  # are connecting to. If not present, the default project for the
87
89
  # credentials is used.
88
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
90
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel,
91
+ # GRPC::Core::ChannelCredentials, Proc]
89
92
  # The means for authenticating requests made by the client. This parameter can
90
93
  # be one of the following types.
91
94
  # `Google::Auth::Credentials` uses the properties of its represented keyfile for
@@ -99,7 +102,6 @@ module Google
99
102
  # should already be composed with a `GRPC::Core::CallCredentials` object.
100
103
  # `Proc` will be used as an updater_proc for the gRPC channel. The proc transforms the
101
104
  # metadata for requests, generally, to give OAuth credentials.
102
- # @param timeout [Integer]
103
105
  # @param scope [Array<String>]
104
106
  # The OAuth 2.0 scopes controlling the set of resources and operations
105
107
  # that the connection can access. See [Using OAuth 2.0 to Access Google
@@ -116,22 +118,17 @@ module Google
116
118
  # @return [Google::Cloud::Bigtable::Project]
117
119
  #
118
120
  # @example
119
- # require "google/cloud"
121
+ # require "google/cloud/bigtable"
120
122
  #
121
123
  # bigtable = Google::Cloud.bigtable
122
-
123
- def self.bigtable \
124
- project_id: nil,
125
- credentials: nil,
126
- scope: nil,
127
- timeout: nil,
128
- client_config: nil
124
+ #
125
+ def self.bigtable project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil
129
126
  require "google/cloud/bigtable"
130
127
  Google::Cloud::Bigtable.new(
131
- project_id: project_id,
132
- credentials: credentials,
133
- scope: scope,
134
- timeout: timeout,
128
+ project_id: project_id,
129
+ credentials: credentials,
130
+ scope: scope,
131
+ timeout: timeout,
135
132
  client_config: client_config
136
133
  )
137
134
  end
@@ -156,7 +153,7 @@ Google::Cloud.configure.add_config! :bigtable do |config|
156
153
  config.add_field! :project_id, default_project, match: String, allow_nil: true
157
154
  config.add_alias! :project, :project_id
158
155
  config.add_field! :credentials, default_creds,
159
- match: [
156
+ match: [
160
157
  String,
161
158
  Hash,
162
159
  Google::Auth::Credentials,
@@ -109,7 +109,7 @@ module Google
109
109
  # recommended for production use. It is not subject to any SLA or deprecation
110
110
  # policy.
111
111
  rpc :DeleteSnapshot, DeleteSnapshotRequest, Google::Protobuf::Empty
112
- # Gets the access control policy for an instance resource. Returns an empty
112
+ # Gets the access control policy for a table resource. Returns an empty
113
113
  # policy if an table exists but does not have a policy set.
114
114
  rpc :GetIamPolicy, Google::Iam::V1::GetIamPolicyRequest, Google::Iam::V1::Policy
115
115
  # Sets the access control policy on a table resource. Replaces any existing
@@ -5,6 +5,9 @@
5
5
  require 'google/protobuf'
6
6
 
7
7
  require 'google/api/annotations_pb'
8
+ require 'google/api/client_pb'
9
+ require 'google/api/field_behavior_pb'
10
+ require 'google/api/resource_pb'
8
11
  require 'google/bigtable/v2/data_pb'
9
12
  require 'google/protobuf/wrappers_pb'
10
13
  require 'google/rpc/status_pb'
@@ -1,7 +1,7 @@
1
1
  # Generated by the protocol buffer compiler. DO NOT EDIT!
2
2
  # Source: google/bigtable/v2/bigtable.proto for package 'google.bigtable.v2'
3
3
  # Original file comments:
4
- # Copyright 2018 Google Inc.
4
+ # Copyright 2019 Google LLC.
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
7
7
  # you may not use this file except in compliance with the License.
@@ -21,18 +21,21 @@ require "google/cloud/bigtable/project"
21
21
 
22
22
  module Google
23
23
  module Cloud
24
+ ##
24
25
  # Cloud Bigtable
25
26
  #
26
27
  # See {file:OVERVIEW.md Bigtable Overview}.
27
28
  #
28
29
  module Bigtable
30
+ ##
29
31
  # Service for managing Cloud Bigtable instances and tables and for reading from and
30
32
  # writing to Bigtable tables.
31
33
  #
32
34
  # @param project_id [String]
33
35
  # Project identifier for the Bigtable service you are connecting to.
34
36
  # If not present, the default project for the credentials is used.
35
- # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel, GRPC::Core::ChannelCredentials, Proc]
37
+ # @param credentials [Google::Auth::Credentials, String, Hash, GRPC::Core::Channel,
38
+ # GRPC::Core::ChannelCredentials, Proc]
36
39
  # Provides the means for authenticating requests made by the client. This parameter can
37
40
  # be one of the following types:
38
41
  # `Google::Auth::Credentials` uses the properties of its represented keyfile for
@@ -70,14 +73,8 @@ module Google
70
73
  #
71
74
  # client = Google::Cloud::Bigtable.new
72
75
  #
73
- def self.new \
74
- project_id: nil,
75
- credentials: nil,
76
- emulator_host: nil,
77
- scope: nil,
78
- client_config: nil,
79
- endpoint: nil,
80
- timeout: nil
76
+ def self.new project_id: nil, credentials: nil, emulator_host: nil, scope: nil, client_config: nil, endpoint: nil,
77
+ timeout: nil
81
78
  project_id ||= default_project_id
82
79
  scope ||= configure.scope
83
80
  timeout ||= configure.timeout
@@ -98,9 +95,10 @@ module Google
98
95
  project_id, credentials,
99
96
  host: endpoint, timeout: timeout, client_config: client_config
100
97
  )
101
- Bigtable::Project.new(service)
98
+ Bigtable::Project.new service
102
99
  end
103
100
 
101
+ ##
104
102
  # Configure the Google Cloud Bigtable library.
105
103
  #
106
104
  # The following Bigtable configuration parameters are supported:
@@ -151,10 +149,8 @@ module Google
151
149
  #
152
150
  def self.resolve_credentials given_credentials, scope
153
151
  credentials = given_credentials || default_credentials(scope: scope)
154
- unless credentials.is_a? Google::Auth::Credentials
155
- credentials = Bigtable::Credentials.new credentials, scope: scope
156
- end
157
- credentials
152
+ return credentials if credentials.is_a? Google::Auth::Credentials
153
+ Bigtable::Credentials.new credentials, scope: scope
158
154
  end
159
155
 
160
156
  # @private
@@ -162,9 +158,7 @@ module Google
162
158
  #
163
159
  def self.resolve_project_id given_project_id, credentials
164
160
  project_id = given_project_id || default_project_id
165
- if credentials.respond_to? :project_id
166
- project_id ||= credentials.project_id
167
- end
161
+ project_id ||= credentials.project_id if credentials.respond_to? :project_id
168
162
  project_id.to_s # Always cast to a string
169
163
  end
170
164
 
@@ -22,7 +22,7 @@ module Google
22
22
  # rubocop:disable LineLength
23
23
 
24
24
  ##
25
- # # Ruby Client for Cloud Bigtable Admin API ([Beta](https://github.com/googleapis/google-cloud-ruby#versioning))
25
+ # # Ruby Client for Cloud Bigtable Admin API ([GA](https://github.com/googleapis/google-cloud-ruby#versioning))
26
26
  #
27
27
  # [Cloud Bigtable Admin API][Product Documentation]:
28
28
  #
@@ -25,7 +25,7 @@ module Google
25
25
  # rubocop:disable LineLength
26
26
 
27
27
  ##
28
- # # Ruby Client for Cloud Bigtable Admin API ([Beta](https://github.com/googleapis/google-cloud-ruby#versioning))
28
+ # # Ruby Client for Cloud Bigtable Admin API ([GA](https://github.com/googleapis/google-cloud-ruby#versioning))
29
29
  #
30
30
  # [Cloud Bigtable Admin API][Product Documentation]:
31
31
  #
@@ -870,7 +870,7 @@ module Google
870
870
  @check_consistency.call(req, options, &block)
871
871
  end
872
872
 
873
- # Gets the access control policy for an instance resource. Returns an empty
873
+ # Gets the access control policy for a table resource. Returns an empty
874
874
  # policy if an table exists but does not have a policy set.
875
875
  #
876
876
  # @param resource [String]
@@ -20,27 +20,36 @@ module Google
20
20
  # specify access control policies for Cloud Platform resources.
21
21
  #
22
22
  #
23
- # A `Policy` consists of a list of `bindings`. A `binding` binds a list of
24
- # `members` to a `role`, where the members can be user accounts, Google groups,
25
- # Google domains, and service accounts. A `role` is a named list of permissions
26
- # defined by IAM.
23
+ # A `Policy` is a collection of `bindings`. A `binding` binds one or more
24
+ # `members` to a single `role`. Members can be user accounts, service accounts,
25
+ # Google groups, and domains (such as G Suite). A `role` is a named list of
26
+ # permissions (defined by IAM or configured by users). A `binding` can
27
+ # optionally specify a `condition`, which is a logic expression that further
28
+ # constrains the role binding based on attributes about the request and/or
29
+ # target resource.
27
30
  #
28
31
  # **JSON Example**
29
32
  #
30
33
  # {
31
34
  # "bindings": [
32
35
  # {
33
- # "role": "roles/owner",
36
+ # "role": "roles/resourcemanager.organizationAdmin",
34
37
  # "members": [
35
38
  # "user:mike@example.com",
36
39
  # "group:admins@example.com",
37
40
  # "domain:google.com",
38
- # "serviceAccount:my-other-app@appspot.gserviceaccount.com"
41
+ # "serviceAccount:my-project-id@appspot.gserviceaccount.com"
39
42
  # ]
40
43
  # },
41
44
  # {
42
- # "role": "roles/viewer",
43
- # "members": ["user:sean@example.com"]
45
+ # "role": "roles/resourcemanager.organizationViewer",
46
+ # "members": ["user:eve@example.com"],
47
+ # "condition": {
48
+ # "title": "expirable access",
49
+ # "description": "Does not grant access after Sep 2020",
50
+ # "expression": "request.time <
51
+ # timestamp('2020-10-01T00:00:00.000Z')",
52
+ # }
44
53
  # }
45
54
  # ]
46
55
  # }
@@ -52,15 +61,18 @@ module Google
52
61
  # * user:mike@example.com
53
62
  # * group:admins@example.com
54
63
  # * domain:google.com
55
- # * serviceAccount:my-other-app@appspot.gserviceaccount.com
56
- # role: roles/owner
64
+ # * serviceAccount:my-project-id@appspot.gserviceaccount.com
65
+ # role: roles/resourcemanager.organizationAdmin
57
66
  # * members:
58
- # * user:sean@example.com
59
- # role: roles/viewer
60
- #
61
- #
62
- # For a description of IAM and its features, see the
63
- # [IAM developer's guide](https://cloud.google.com/iam/docs).
67
+ # * user:eve@example.com
68
+ # role: roles/resourcemanager.organizationViewer
69
+ # condition:
70
+ # title: expirable access
71
+ # description: Does not grant access after Sep 2020
72
+ # expression: request.time < timestamp('2020-10-01T00:00:00.000Z')
73
+ #
74
+ # For a description of IAM and its features, see the
75
+ # [IAM developer's guide](https://cloud.google.com/iam/docs).
64
76
  # @!attribute [rw] version
65
77
  # @return [Integer]
66
78
  # Specifies the format of the policy.
@@ -68,12 +80,19 @@ module Google
68
80
  # Valid values are 0, 1, and 3. Requests specifying an invalid value will be
69
81
  # rejected.
70
82
  #
71
- # Policies with any conditional bindings must specify version 3. Policies
72
- # without any conditional bindings may specify any valid value or leave the
73
- # field unset.
83
+ # Operations affecting conditional bindings must specify version 3. This can
84
+ # be either setting a conditional policy, modifying a conditional binding,
85
+ # or removing a binding (conditional or unconditional) from the stored
86
+ # conditional policy.
87
+ # Operations on non-conditional policies may specify any valid value or
88
+ # leave the field unset.
89
+ #
90
+ # If no etag is provided in the call to `setIamPolicy`, version compliance
91
+ # checks against the stored policy is skipped.
74
92
  # @!attribute [rw] bindings
75
93
  # @return [Array<Google::Iam::V1::Binding>]
76
- # Associates a list of `members` to a `role`.
94
+ # Associates a list of `members` to a `role`. Optionally may specify a
95
+ # `condition` that determines when binding is in effect.
77
96
  # `bindings` with no members will result in an error.
78
97
  # @!attribute [rw] etag
79
98
  # @return [String]
@@ -86,7 +105,9 @@ module Google
86
105
  # ensure that their change will be applied to the same version of the policy.
87
106
  #
88
107
  # If no `etag` is provided in the call to `setIamPolicy`, then the existing
89
- # policy is overwritten.
108
+ # policy is overwritten. Due to blind-set semantics of an etag-less policy,
109
+ # 'setIamPolicy' will not fail even if the incoming policy version does not
110
+ # meet the requirements for modifying the stored policy.
90
111
  class Policy; end
91
112
 
92
113
  # Associates `members` with a `role`.
@@ -17,10 +17,12 @@
17
17
 
18
18
  require "google/cloud/bigtable/app_profile/list"
19
19
  require "google/cloud/bigtable/app_profile/job"
20
+ require "google/cloud/bigtable/routing_policy"
20
21
 
21
22
  module Google
22
23
  module Cloud
23
24
  module Bigtable
25
+ ##
24
26
  # # AppProfile
25
27
  #
26
28
  # A configuration object describing how Cloud Bigtable should treat traffic
@@ -33,7 +35,7 @@ module Google
33
35
  #
34
36
  # instance = bigtable.instance("my-instance")
35
37
  #
36
- # app_profile = bigtable.app_profile("my-instance", "my-app-profile")
38
+ # app_profile = instance.app_profile("my-app-profile")
37
39
  #
38
40
  # # Update
39
41
  # app_profile.description = "User data instance app profile"
@@ -58,88 +60,115 @@ module Google
58
60
  @changed_fields = {}
59
61
  end
60
62
 
61
- # The unique identifier for the project.
63
+ ##
64
+ # The unique identifier for the project to which the app profile belongs.
62
65
  #
63
66
  # @return [String]
67
+ #
64
68
  def project_id
65
69
  @grpc.name.split("/")[1]
66
70
  end
67
71
 
68
- # The unique identifier for the instance.
72
+ ##
73
+ # The unique identifier for the instance to which the app profile belongs.
69
74
  #
70
75
  # @return [String]
76
+ #
71
77
  def instance_id
72
78
  @grpc.name.split("/")[3]
73
79
  end
74
80
 
81
+ ##
75
82
  # The unique identifier for the app profile.
76
83
  #
77
84
  # @return [String]
85
+ #
78
86
  def name
79
87
  @grpc.name.split("/")[5]
80
88
  end
81
89
 
82
- # The full path for the instance resource. Values are of the form
83
- # `projects/<project_id>/instances/<instance_id>`.
90
+ ##
91
+ # The full path for the app profile resource. Values are of the form:
92
+ # `projects/<project_id>/instances/<instance_id>/appProfiles/<app_profile_name>`.
84
93
  #
85
94
  # @return [String]
95
+ #
86
96
  def path
87
97
  @grpc.name
88
98
  end
89
99
 
100
+ ##
90
101
  # Etag for optimistic concurrency control.
91
102
  #
92
103
  # @return [String]
104
+ #
93
105
  def etag
94
106
  @grpc.etag
95
107
  end
96
108
 
97
- # Description of the AppProfile.
109
+ ##
110
+ # Description of the app profile.
98
111
  #
99
112
  # @return [String]
113
+ #
100
114
  def description
101
115
  @grpc.description
102
116
  end
103
117
 
104
- # Set description of the AppProfile.
118
+ ##
119
+ # Sets the description of the app profile.
105
120
  #
106
121
  # @param text [String] Description text
122
+ #
107
123
  def description= text
108
124
  @grpc.description = text
109
125
  @changed_fields["description"] = "description"
110
126
  end
111
127
 
112
- # Get value of multi-cluster routing policy.
128
+ ##
129
+ # Gets the multi-cluster routing policy, if present.
130
+ #
131
+ # @return [Google::Cloud::Bigtable::MultiClusterRoutingUseAny, nil]
113
132
  #
114
- # @return [Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny]
115
133
  def multi_cluster_routing
116
- @grpc.multi_cluster_routing_use_any
134
+ return nil unless @grpc.multi_cluster_routing_use_any
135
+
136
+ Google::Cloud::Bigtable::MultiClusterRoutingUseAny.new
117
137
  end
118
138
 
119
- # Get value of single cluster routing policy.
139
+ ##
140
+ # Gets the single cluster routing policy, if present.
141
+ #
142
+ # @return [Google::Cloud::Bigtable::SingleClusterRouting, nil]
120
143
  #
121
- # @return [Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting]
122
144
  def single_cluster_routing
123
- @grpc.single_cluster_routing
145
+ return nil unless @grpc.single_cluster_routing
146
+
147
+ Google::Cloud::Bigtable::SingleClusterRouting.new(
148
+ @grpc.single_cluster_routing.cluster_id,
149
+ @grpc.single_cluster_routing.allow_transactional_writes
150
+ )
124
151
  end
125
152
 
126
- # Set routing policy.
153
+ ##
154
+ # Sets the routing policy for the app profile.
127
155
  #
128
- # @param policy [Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting | Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny]
129
- # The routing policy for all read/write requests that use this app profile.
130
- # A value must be explicitly set.
156
+ # @param policy [Google::Cloud::Bigtable::RoutingPolicy]
157
+ # The routing policy for all read/write requests that use this app profile. A value must be explicitly set.
131
158
  #
132
159
  # Routing Policies:
133
- # * `multi_cluster_routing` - Read/write requests may be routed to any
134
- # cluster in the instance and will fail over to another cluster in the event
135
- # of transient errors or delays. Choosing this option sacrifices
136
- # read-your-writes consistency to improve availability.
137
- # * `single_cluster_routing` - Unconditionally routes all read/write requests
138
- # to a specific cluster. This option preserves read-your-writes consistency
139
- # but does not improve availability.
140
- # The value contains `cluster_id` and optional field `allow_transactional_writes`.
141
- #
142
- # @example Set multi cluster routing policy
160
+ # * {Google::Cloud::Bigtable::MultiClusterRoutingUseAny} - Read/write
161
+ # requests may be routed to any cluster in the instance and will
162
+ # fail over to another cluster in the event of transient errors or
163
+ # delays. Choosing this option sacrifices read-your-writes
164
+ # consistency to improve availability.
165
+ # * {Google::Cloud::Bigtable::SingleClusterRouting} - Unconditionally
166
+ # routes all read/write requests to a specific cluster. This option
167
+ # preserves read-your-writes consistency but does not improve
168
+ # availability. Value contains `cluster_id` and optional field
169
+ # `allow_transactional_writes`.
170
+ #
171
+ # @example Set multi cluster routing policy.
143
172
  # require "google/cloud/bigtable"
144
173
  #
145
174
  # bigtable = Google::Cloud::Bigtable.new
@@ -149,7 +178,7 @@ module Google
149
178
  # routing_policy = Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
150
179
  # app_profile.routing_policy = routing_policy
151
180
  #
152
- # @example Set single cluster routing policy
181
+ # @example Set single cluster routing policy.
153
182
  # require "google/cloud/bigtable"
154
183
  #
155
184
  # bigtable = Google::Cloud::Bigtable.new
@@ -157,31 +186,62 @@ module Google
157
186
  # app_profile = instance.app_profile("my-app-profile")
158
187
  #
159
188
  # routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
160
- # "my-instance-cluster-1"
189
+ # "my-instance-cluster-1",
161
190
  # allow_transactional_writes: true
162
191
  # )
163
192
  # app_profile.routing_policy = routing_policy
164
193
  #
165
194
  def routing_policy= policy
166
- if policy.is_a?(Google::Bigtable::Admin::V2::AppProfile:: \
167
- SingleClusterRouting)
168
- @grpc.single_cluster_routing = policy
195
+ routing_policy_grpc = policy.to_grpc
196
+ if routing_policy_grpc.is_a? Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting
197
+ @grpc.single_cluster_routing = routing_policy_grpc
169
198
  @changed_fields["routing_policy"] = "single_cluster_routing"
170
199
  else
171
- @grpc.multi_cluster_routing_use_any = policy
200
+ @grpc.multi_cluster_routing_use_any = routing_policy_grpc
172
201
  @changed_fields["routing_policy"] = "multi_cluster_routing_use_any"
173
202
  end
174
203
  end
175
204
 
176
- # Get routing policy.
205
+ ##
206
+ # Gets the routing policy for all read/write requests that use the app
207
+ # profile.
208
+ #
209
+ # Routing Policies:
210
+ # * {Google::Cloud::Bigtable::MultiClusterRoutingUseAny} - Read/write
211
+ # requests may be routed to any cluster in the instance and will
212
+ # fail over to another cluster in the event of transient errors or
213
+ # delays. Choosing this option sacrifices read-your-writes
214
+ # consistency to improve availability.
215
+ # * {Google::Cloud::Bigtable::SingleClusterRouting} - Unconditionally
216
+ # routes all read/write requests to a specific cluster. This option
217
+ # preserves read-your-writes consistency but does not improve
218
+ # availability. Value contains `cluster_id` and optional field
219
+ # `allow_transactional_writes`.
220
+ #
221
+ # @return [Google::Cloud::Bigtable::RoutingPolicy]
222
+ #
223
+ # @example
224
+ # require "google/cloud/bigtable"
225
+ #
226
+ # bigtable = Google::Cloud::Bigtable.new
227
+ #
228
+ # instance = bigtable.instance("my-instance")
229
+ #
230
+ # routing_policy = Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
177
231
  #
178
- # @return [Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting, Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny]
232
+ # app_profile = instance.create_app_profile(
233
+ # "my-app-profile",
234
+ # routing_policy,
235
+ # description: "App profile for user data instance"
236
+ # )
237
+ # puts app_profile.routing_policy
179
238
  #
180
239
  def routing_policy
181
- @grpc.single_cluster_routing || @grpc.multi_cluster_routing_use_any
240
+ single_cluster_routing || multi_cluster_routing
182
241
  end
183
242
 
184
- # Delete app profile.
243
+ ##
244
+ # Deletes the app profile.
185
245
  #
186
246
  # @param ignore_warnings [Boolean]
187
247
  # Default value is false. If true, ignore safety checks when deleting
@@ -194,7 +254,8 @@ module Google
194
254
  # bigtable = Google::Cloud::Bigtable.new
195
255
  #
196
256
  # instance = bigtable.instance("my-instance")
197
- # app_profile = bigtable.instance("my-app-profile")
257
+ #
258
+ # app_profile = instance.app_profile("my-app-profile")
198
259
  #
199
260
  # app_profile.delete(ignore_warnings: true) # Ignore warnings.
200
261
  #
@@ -203,27 +264,26 @@ module Google
203
264
  #
204
265
  def delete ignore_warnings: false
205
266
  ensure_service!
206
- service.delete_app_profile(
207
- instance_id,
208
- name,
209
- ignore_warnings: ignore_warnings
210
- )
267
+ service.delete_app_profile instance_id, name, ignore_warnings: ignore_warnings
211
268
  true
212
269
  end
213
270
 
214
- # Update app profile.
271
+ ##
272
+ # Updates the app profile.
215
273
  #
216
274
  # @param ignore_warnings [Boolean]
217
275
  # Default value is false. If true, ignore safety checks when updating
218
276
  # the app profile.
219
277
  # @return [Google::Cloud::Bigtable::AppProfile::Job]
220
278
  #
221
- # @example Update
279
+ # @example
222
280
  # require "google/cloud/bigtable"
223
281
  #
224
282
  # bigtable = Google::Cloud::Bigtable.new
225
283
  #
226
- # app_profile = bigtable.app_profile("my-app-profile")
284
+ # instance = bigtable.instance("my-instance")
285
+ #
286
+ # app_profile = instance.app_profile("my-app-profile")
227
287
  #
228
288
  # app_profile.description = "User data instance app profile"
229
289
  # app_profile.routing_policy = \
@@ -238,17 +298,13 @@ module Google
238
298
  # app_profile = job.app_profile
239
299
  # end
240
300
  #
241
- # # OR - Update with ignoring warnings.
242
- # job = app_profile.save(ignore_warnings: true)
243
- # job.wait_until_done!
244
- #
245
- # @example Update with single cluster routing
301
+ # @example Update with single cluster routing.
246
302
  # require "google/cloud/bigtable"
247
303
  #
248
304
  # bigtable = Google::Cloud::Bigtable.new
249
305
  #
250
306
  # instance = bigtable.instance("my-instance")
251
- # app_profile = bigtable.instance("my-app-profile")
307
+ # app_profile = instance.app_profile("my-app-profile")
252
308
  #
253
309
  # app_profile.description = "User data instance app profile"
254
310
  # routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
@@ -261,10 +317,6 @@ module Google
261
317
  #
262
318
  # job.done? #=> false
263
319
  # job.reload!
264
- # job.done? #=> false
265
- #
266
- # # Reload job until completion.
267
- # job.wait_until_done!
268
320
  # job.done? #=> true
269
321
  #
270
322
  # if job.error?
@@ -273,52 +325,62 @@ module Google
273
325
  # app_profile = job.app_profile
274
326
  # puts app_profile.name
275
327
  # end
276
-
328
+ #
277
329
  def save ignore_warnings: false
278
330
  ensure_service!
279
- update_mask = Google::Protobuf::FieldMask.new(
280
- paths: @changed_fields.values
281
- )
282
- grpc = service.update_app_profile(
283
- @grpc,
284
- update_mask,
285
- ignore_warnings: ignore_warnings
286
- )
331
+ update_mask = Google::Protobuf::FieldMask.new paths: @changed_fields.values
332
+ grpc = service.update_app_profile @grpc, update_mask, ignore_warnings: ignore_warnings
287
333
  @changed_fields.clear
288
- AppProfile::Job.from_grpc(grpc, service)
334
+ AppProfile::Job.from_grpc grpc, service
289
335
  end
290
336
  alias update save
291
337
 
292
- # Reload app profile information.
338
+ ##
339
+ # Reloads the app profile data.
293
340
  #
294
341
  # @return [Google::Cloud::Bigtable::AppProfile]
295
-
342
+ #
296
343
  def reload!
297
- @grpc = service.get_app_profile(instance_id, name)
344
+ @grpc = service.get_app_profile instance_id, name
298
345
  self
299
346
  end
300
347
 
301
- # Create instance of multi cluster routing policy.
348
+ ##
349
+ # Creates an instance of the multi cluster routing policy.
350
+ #
351
+ # Read/write requests may be routed to any cluster in the instance and
352
+ # will fail over to another cluster in the event of transient errors or
353
+ # delays. Choosing this option sacrifices read-your-writes consistency
354
+ # to improve availability.
302
355
  #
303
- # Read/write requests may be routed to any cluster in the instance and will
304
- # fail over to another cluster in the event of transient errors or delays.
305
- # Choosing this option sacrifices read-your-writes consistency to improve
306
- # availability.
307
- # @return [Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny]
356
+ # @return [Google::Cloud::Bigtable::MultiClusterRoutingUseAny]
357
+ #
358
+ # @example
359
+ # require "google/cloud/bigtable"
308
360
  #
309
- # @example Create instance of multi cluster routing
361
+ # bigtable = Google::Cloud::Bigtable.new
310
362
  #
311
- # Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
363
+ # instance = bigtable.instance("my-instance")
364
+ #
365
+ # routing_policy = Google::Cloud::Bigtable::AppProfile.multi_cluster_routing
366
+ #
367
+ # app_profile = instance.create_app_profile(
368
+ # "my-app-profile",
369
+ # routing_policy,
370
+ # description: "App profile for user data instance"
371
+ # )
372
+ # puts app_profile.routing_policy
312
373
  #
313
374
  def self.multi_cluster_routing
314
- Google::Bigtable::Admin::V2::AppProfile::MultiClusterRoutingUseAny.new
375
+ Google::Cloud::Bigtable::MultiClusterRoutingUseAny.new
315
376
  end
316
377
 
317
- # Create instance of single cluster routing.
378
+ ##
379
+ # Creates an instance of the single cluster routing policy.
318
380
  #
319
381
  # Unconditionally routes all read/write requests to a specific cluster.
320
- # This option preserves read-your-writes consistency but does not improve
321
- # availability.
382
+ # This option preserves read-your-writes consistency but does not
383
+ # improve availability.
322
384
  #
323
385
  # @param cluster_id [String]
324
386
  # The cluster to which read/write requests should be routed.
@@ -327,25 +389,29 @@ module Google
327
389
  # allowed by this app profile. It is unsafe to send these requests to
328
390
  # the same table/row/column in multiple clusters.
329
391
  # Default value is false.
330
- # @return [Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting]
392
+ # @return [Google::Cloud::Bigtable::SingleClusterRouting]
331
393
  #
332
- # @example Create instance of single cluster routing
394
+ # @example
395
+ # require "google/cloud/bigtable"
333
396
  #
334
- # Google::Cloud::Bigtable::AppProfile.single_cluster_routing("my-cluster")
397
+ # bigtable = Google::Cloud::Bigtable.new
335
398
  #
336
- # # With allowed transactional writes
337
- # Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
338
- # "my-cluster",
399
+ # instance = bigtable.instance("my-instance")
400
+ #
401
+ # routing_policy = Google::Cloud::Bigtable::AppProfile.single_cluster_routing(
402
+ # "my-instance-cluster-1",
339
403
  # allow_transactional_writes: true
340
404
  # )
341
-
342
- def self.single_cluster_routing \
343
- cluster_id,
344
- allow_transactional_writes: false
345
- Google::Bigtable::Admin::V2::AppProfile::SingleClusterRouting.new(
346
- cluster_id: cluster_id,
347
- allow_transactional_writes: allow_transactional_writes
348
- )
405
+ #
406
+ # app_profile = instance.create_app_profile(
407
+ # "my-app-profile",
408
+ # routing_policy,
409
+ # description: "App profile for user data instance"
410
+ # )
411
+ # puts app_profile.routing_policy
412
+ #
413
+ def self.single_cluster_routing cluster_id, allow_transactional_writes: false
414
+ Google::Cloud::Bigtable::SingleClusterRouting.new cluster_id, allow_transactional_writes
349
415
  end
350
416
 
351
417
  # @private
@@ -356,7 +422,7 @@ module Google
356
422
  # @param service [Google::Cloud::Bigtable::Service]
357
423
  # @return [Google::Cloud::Bigtable::Table]
358
424
  def self.from_grpc grpc, service
359
- new(grpc, service)
425
+ new grpc, service
360
426
  end
361
427
 
362
428
  protected