Google Cloud Bigtable C++ Client  1.40.2
A C++ Client Library for Google Cloud Bigtable
app_profile_config.h
Go to the documentation of this file.
1 // Copyright 2018 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_APP_PROFILE_CONFIG_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_APP_PROFILE_CONFIG_H
17 
18 #include "google/cloud/bigtable/version.h"
19 #include <google/bigtable/admin/v2/bigtable_instance_admin.pb.h>
20 #include <string>
21 
22 namespace google {
23 namespace cloud {
24 namespace bigtable {
26 /// Specify the initial configuration for an application profile.
28  public:
29  explicit AppProfileConfig(
30  google::bigtable::admin::v2::CreateAppProfileRequest proto)
31  : proto_(std::move(proto)) {}
32 
33  /**
34  * Create an AppProfile that uses multi-cluster routing.
35  *
36  * Read/write requests are routed to the nearest cluster in the instance,
37  * and will fail over to the nearest cluster that is available in the event of
38  * transient errors or delays. Clusters in a region are considered
39  * equidistant. Choosing this option sacrifices read-your-writes consistency
40  * to improve availability.
41  *
42  * @param profile_id The unique name of the AppProfile.
43  * @param cluster_ids The set of clusters to route to. The order is
44  * ignored; clusters will be tried in order of distance. If left empty,
45  * all clusters are eligible.
46  */
48  std::string profile_id, std::vector<std::string> cluster_ids = {});
49 
50  /**
51  * Create an AppProfile that uses single cluster routing.
52  *
53  * Unconditionally routes all read/write requests to a specific cluster. This
54  * option preserves read-your-writes consistency but does not improve
55  * availability.
56  *
57  * @param profile_id The unique name of the AppProfile.
58  * @param cluster_id The cluster to which read/write requests are routed.
59  * @param allow_transactional_writes Whether or not `CheckAndMutateRow` and
60  * `ReadModifyWriteRow` requests are allowed by this app profile. It is
61  * unsafe to send these requests to the same table/row/column in multiple
62  * clusters.
63  */
65  std::string profile_id, std::string cluster_id,
66  bool allow_transactional_writes = false);
67 
69  proto_.set_ignore_warnings(value);
70  return *this;
71  }
72 
73  AppProfileConfig& set_description(std::string description) {
74  proto_.mutable_app_profile()->set_description(std::move(description));
75  return *this;
76  }
77 
78  AppProfileConfig& set_etag(std::string etag) {
79  proto_.mutable_app_profile()->set_etag(std::move(etag));
80  return *this;
81  }
82 
83  google::bigtable::admin::v2::CreateAppProfileRequest const& as_proto()
84  const& {
85  return proto_;
86  }
87 
88  google::bigtable::admin::v2::CreateAppProfileRequest&& as_proto() && {
89  return std::move(proto_);
90  }
91 
92  private:
93  AppProfileConfig() = default;
94 
95  google::bigtable::admin::v2::CreateAppProfileRequest proto_;
96 };
97 
98 /// Build a proto to update an Application Profile configuration.
100  public:
102 
104  proto_.set_ignore_warnings(value);
105  return *this;
106  }
107  AppProfileUpdateConfig& set_description(std::string description) {
108  proto_.mutable_app_profile()->set_description(std::move(description));
109  AddPathIfNotPresent("description");
110  return *this;
111  }
112  AppProfileUpdateConfig& set_etag(std::string etag) {
113  proto_.mutable_app_profile()->set_etag(std::move(etag));
114  AddPathIfNotPresent("etag");
115  return *this;
116  }
118  std::vector<std::string> cluster_ids = {}) {
119  auto& mc_routing =
120  *proto_.mutable_app_profile()->mutable_multi_cluster_routing_use_any();
121  for (auto&& cluster_id : cluster_ids) {
122  mc_routing.add_cluster_ids(std::move(cluster_id));
123  }
124  RemoveIfPresent("single_cluster_routing");
125  AddPathIfNotPresent("multi_cluster_routing_use_any");
126  return *this;
127  }
129  std::string const& cluster_id, bool allow_transactional_writes = false) {
130  proto_.mutable_app_profile()
131  ->mutable_single_cluster_routing()
132  ->set_cluster_id(cluster_id);
133  proto_.mutable_app_profile()
134  ->mutable_single_cluster_routing()
135  ->set_allow_transactional_writes(allow_transactional_writes);
136  RemoveIfPresent("multi_cluster_routing_use_any");
137  AddPathIfNotPresent("single_cluster_routing");
138  return *this;
139  }
140 
141  google::bigtable::admin::v2::UpdateAppProfileRequest const& as_proto()
142  const& {
143  return proto_;
144  }
145 
146  google::bigtable::admin::v2::UpdateAppProfileRequest&& as_proto() && {
147  return std::move(proto_);
148  }
149 
150  private:
151  void AddPathIfNotPresent(std::string field_name);
152  void RemoveIfPresent(std::string const& field_name);
153 
154  google::bigtable::admin::v2::UpdateAppProfileRequest proto_;
155 };
156 
158 } // namespace bigtable
159 } // namespace cloud
160 } // namespace google
161 
162 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_APP_PROFILE_CONFIG_H