Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
instance_update_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_INSTANCE_UPDATE_CONFIG_H_
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_UPDATE_CONFIG_H_
17 
18 #include "google/cloud/bigtable/cluster_config.h"
19 #include "google/cloud/bigtable/version.h"
20 #include <google/bigtable/admin/v2/bigtable_instance_admin.pb.h>
21 #include <google/bigtable/admin/v2/common.pb.h>
22 #include <map>
23 #include <vector>
24 
25 namespace google {
26 namespace cloud {
27 namespace bigtable {
28 inline namespace BIGTABLE_CLIENT_NS {
29 using Instance = ::google::bigtable::admin::v2::Instance;
30 
31 /// Specify the initial configuration for updating an instance.
32 class InstanceUpdateConfig {
33  public:
34  InstanceUpdateConfig(Instance instance) {
35  proto_.mutable_instance()->Swap(&instance);
36  }
37 
38  //@{
39  /// @name Convenient shorthands for the instance types.
40  using InstanceType = google::bigtable::admin::v2::Instance::Type;
41  constexpr static InstanceType TYPE_UNSPECIFIED =
42  google::bigtable::admin::v2::Instance::TYPE_UNSPECIFIED;
43  constexpr static InstanceType PRODUCTION =
44  google::bigtable::admin::v2::Instance::PRODUCTION;
45  constexpr static InstanceType DEVELOPMENT =
46  google::bigtable::admin::v2::Instance::DEVELOPMENT;
47  //@}
48 
49  //@{
50  /// @name Convenient shorthands for the instance state.
51  using StateType = google::bigtable::admin::v2::Instance::State;
52  constexpr static StateType STATE_NOT_KNOWN =
53  google::bigtable::admin::v2::Instance::STATE_NOT_KNOWN;
54  constexpr static StateType READY =
55  google::bigtable::admin::v2::Instance::READY;
56  constexpr static StateType CREATING =
57  google::bigtable::admin::v2::Instance::CREATING;
58  //@}
59 
60  InstanceUpdateConfig& set_type(InstanceType type) {
61  proto_.mutable_instance()->set_type(std::move(type));
62  AddPathIfNotPresent("type");
63  return *this;
64  }
65 
66  InstanceUpdateConfig& set_state(StateType state) {
67  proto_.mutable_instance()->set_state(std::move(state));
68  AddPathIfNotPresent("state");
69  return *this;
70  }
71 
72  InstanceUpdateConfig& set_name(std::string name) {
73  proto_.mutable_instance()->set_name(std::move(name));
74  AddPathIfNotPresent("name");
75  return *this;
76  }
77 
78  InstanceUpdateConfig& set_display_name(std::string display_name) {
79  proto_.mutable_instance()->set_display_name(std::move(display_name));
80  AddPathIfNotPresent("display_name");
81  return *this;
82  }
83 
84  InstanceUpdateConfig& insert_label(std::string const& key,
85  std::string const& value) {
86  (*proto_.mutable_instance()->mutable_labels())[key] = value;
87  AddPathIfNotPresent("labels");
88  return *this;
89  }
90 
91  InstanceUpdateConfig& emplace_label(std::string const& key,
92  std::string value) {
93  (*proto_.mutable_instance()->mutable_labels())[key] = std::move(value);
94  AddPathIfNotPresent("labels");
95  return *this;
96  }
97 
98  // NOLINT: accessors can (and should) be snake_case.
99  google::bigtable::admin::v2::PartialUpdateInstanceRequest const& as_proto()
100  const& {
101  return proto_;
102  }
103 
104  // NOLINT: accessors can (and should) be snake_case.
105  google::bigtable::admin::v2::PartialUpdateInstanceRequest&& as_proto() && {
106  return std::move(proto_);
107  }
108 
109  std::string const& GetName() { return proto_.mutable_instance()->name(); }
110 
111  private:
112  void AddPathIfNotPresent(std::string const& field_name) {
113  auto is_present = proto_.update_mask().paths().end() !=
114  std::find(proto_.update_mask().paths().begin(),
115  proto_.update_mask().paths().end(), field_name);
116  if (!is_present) {
117  proto_.mutable_update_mask()->add_paths(field_name);
118  }
119  }
120 
121  google::bigtable::admin::v2::PartialUpdateInstanceRequest proto_;
122 };
123 
124 } // namespace BIGTABLE_CLIENT_NS
125 } // namespace bigtable
126 } // namespace cloud
127 } // namespace google
128 
129 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_UPDATE_CONFIG_H_
#define BIGTABLE_CLIENT_NS
Definition: version.h:22