Google Cloud Bigtable C++ Client  1.1.0
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 // http://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 
21 namespace google {
22 namespace cloud {
23 namespace bigtable {
24 inline namespace BIGTABLE_CLIENT_NS {
25 /// Specify the initial configuration for an application profile.
26 class AppProfileConfig {
27  public:
28  explicit AppProfileConfig(
29  google::bigtable::admin::v2::CreateAppProfileRequest proto)
30  : proto_(std::move(proto)) {}
31 
32  static AppProfileConfig MultiClusterUseAny(std::string profile_id);
33  static AppProfileConfig SingleClusterRouting(
34  std::string profile_id, std::string cluster_id,
35  bool allow_transactional_writes = false);
36 
37  AppProfileConfig& set_ignore_warnings(bool value) {
38  proto_.set_ignore_warnings(value);
39  return *this;
40  }
41 
42  AppProfileConfig& set_description(std::string description) {
43  proto_.mutable_app_profile()->set_description(std::move(description));
44  return *this;
45  }
46 
47  AppProfileConfig& set_etag(std::string etag) {
48  proto_.mutable_app_profile()->set_etag(std::move(etag));
49  return *this;
50  }
51 
52  // NOLINT: accessors can (and should) be snake_case.
53  google::bigtable::admin::v2::CreateAppProfileRequest const& as_proto()
54  const& {
55  return proto_;
56  }
57 
58  // NOLINT: accessors can (and should) be snake_case.
59  google::bigtable::admin::v2::CreateAppProfileRequest&& as_proto() && {
60  return std::move(proto_);
61  }
62 
63  private:
64  AppProfileConfig() : proto_() {}
65 
66  private:
67  google::bigtable::admin::v2::CreateAppProfileRequest proto_;
68 };
69 
70 /// Build a proto to update an Application Profile configuration.
71 class AppProfileUpdateConfig {
72  public:
74 
75  AppProfileUpdateConfig& set_ignore_warnings(bool value) {
76  proto_.set_ignore_warnings(value);
77  return *this;
78  }
79  AppProfileUpdateConfig& set_description(std::string description) {
80  proto_.mutable_app_profile()->set_description(std::move(description));
81  AddPathIfNotPresent("description");
82  return *this;
83  }
84  AppProfileUpdateConfig& set_etag(std::string etag) {
85  proto_.mutable_app_profile()->set_etag(std::move(etag));
86  AddPathIfNotPresent("etag");
87  return *this;
88  }
89  AppProfileUpdateConfig& set_multi_cluster_use_any() {
90  *proto_.mutable_app_profile()->mutable_multi_cluster_routing_use_any() = {};
91  RemoveIfPresent("single_cluster_routing");
92  AddPathIfNotPresent("multi_cluster_routing_use_any");
93  return *this;
94  }
95  AppProfileUpdateConfig& set_single_cluster_routing(
96  std::string const& cluster_id, bool allow_transactional_writes = false) {
97  proto_.mutable_app_profile()
98  ->mutable_single_cluster_routing()
99  ->set_cluster_id(cluster_id);
100  proto_.mutable_app_profile()
101  ->mutable_single_cluster_routing()
102  ->set_allow_transactional_writes(allow_transactional_writes);
103  RemoveIfPresent("multi_cluster_routing_use_any");
104  AddPathIfNotPresent("single_cluster_routing");
105  return *this;
106  }
107 
108  // NOLINT: accessors can (and should) be snake_case.
109  google::bigtable::admin::v2::UpdateAppProfileRequest const& as_proto()
110  const& {
111  return proto_;
112  }
113 
114  // NOLINT: accessors can (and should) be snake_case.
115  google::bigtable::admin::v2::UpdateAppProfileRequest&& as_proto() && {
116  return std::move(proto_);
117  }
118 
119  private:
120  void AddPathIfNotPresent(std::string field_name);
121  void RemoveIfPresent(std::string const& field_name);
122 
123  google::bigtable::admin::v2::UpdateAppProfileRequest proto_;
124 };
125 
126 } // namespace BIGTABLE_CLIENT_NS
127 } // namespace bigtable
128 } // namespace cloud
129 } // namespace google
130 
131 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_APP_PROFILE_CONFIG_H_
AppProfileConfig(google::bigtable::admin::v2::CreateAppProfileRequest proto)
AppProfileUpdateConfig & set_ignore_warnings(bool value)
AppProfileUpdateConfig & set_description(std::string description)
AppProfileConfig & set_ignore_warnings(bool value)
AppProfileUpdateConfig & set_single_cluster_routing(std::string const &cluster_id, bool allow_transactional_writes=false)
AppProfileConfig & set_description(std::string description)
static AppProfileConfig MultiClusterUseAny(std::string profile_id)
#define BIGTABLE_CLIENT_NS
Definition: version.h:22
static AppProfileConfig SingleClusterRouting(std::string profile_id, std::string cluster_id, bool allow_transactional_writes=false)
AppProfileUpdateConfig & set_etag(std::string etag)
AppProfileConfig & set_etag(std::string etag)
Contains all the Cloud Bigtable C++ client APIs.