Google Cloud Spanner C++ Client  1.32.0
A C++ Client Library for Google Cloud Spanner
update_instance_request_builder.h
Go to the documentation of this file.
1 // Copyright 2019 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_SPANNER_UPDATE_INSTANCE_REQUEST_BUILDER_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_UPDATE_INSTANCE_REQUEST_BUILDER_H
17 
18 #include "google/cloud/spanner/instance.h"
19 #include "google/cloud/spanner/version.h"
20 #include <google/protobuf/util/field_mask_util.h>
21 #include <google/spanner/admin/instance/v1/spanner_instance_admin.pb.h>
22 #include <map>
23 #include <string>
24 
25 namespace google {
26 namespace cloud {
27 namespace spanner {
28 inline namespace SPANNER_CLIENT_NS {
29 
30 /**
31  * UpdateInstanceRequestBuilder is a builder class for
32  * `google::spanner::admin::instance::v1::UpdateInstanceRequest`
33  *
34  * This is useful when calling
35  * `google::cloud::spanner::InstanceAdminClient::UpdateInstance()` function.
36  *
37  * @par Example
38  * @snippet samples.cc update-instance
39  */
41  public:
42  /**
43  * Constructs a `UpdateInstanceRequestBuilder`.
44  */
46 
47  // Copy and move.
51  default;
53  default;
54 
55  explicit UpdateInstanceRequestBuilder(std::string instance_name) {
56  request_.mutable_instance()->set_name(std::move(instance_name));
57  }
58  explicit UpdateInstanceRequestBuilder(Instance const& in) {
59  request_.mutable_instance()->set_name(in.FullName());
60  }
61 
62  /**
63  * Constructs `UpdateInstanceRequestBuilder` with
64  * google::spanner::admin::instance::v1::Instance. It's particularly useful
65  * if you want to add some labels to existing instances.
66  */
68  google::spanner::admin::instance::v1::Instance in) {
69  *request_.mutable_instance() = std::move(in);
70  }
71 
72  UpdateInstanceRequestBuilder& SetName(std::string name) & {
73  request_.mutable_instance()->set_name(std::move(name));
74  return *this;
75  }
76  UpdateInstanceRequestBuilder&& SetName(std::string name) && {
77  request_.mutable_instance()->set_name(std::move(name));
78  return std::move(*this);
79  }
80  UpdateInstanceRequestBuilder& SetDisplayName(std::string display_name) & {
81  SetDisplayNameImpl(std::move(display_name));
82  return *this;
83  }
84  UpdateInstanceRequestBuilder&& SetDisplayName(std::string display_name) && {
85  SetDisplayNameImpl(std::move(display_name));
86  return std::move(*this);
87  }
89  SetNodeCountImpl(node_count);
90  return *this;
91  }
93  SetNodeCountImpl(node_count);
94  return std::move(*this);
95  }
97  SetProcessingUnitsImpl(processing_units);
98  return *this;
99  }
101  SetProcessingUnitsImpl(processing_units);
102  return std::move(*this);
103  }
105  std::map<std::string, std::string> const& labels) & {
106  AddLabelsImpl(labels);
107  return *this;
108  }
110  std::map<std::string, std::string> const& labels) && {
111  AddLabelsImpl(labels);
112  return std::move(*this);
113  }
115  std::map<std::string, std::string> const& labels) & {
116  request_.mutable_instance()->clear_labels();
117  AddLabelsImpl(labels);
118  return *this;
119  }
121  std::map<std::string, std::string> const& labels) && {
122  request_.mutable_instance()->clear_labels();
123  AddLabelsImpl(labels);
124  return std::move(*this);
125  }
126  google::spanner::admin::instance::v1::UpdateInstanceRequest& Build() & {
127  return request_;
128  }
129  google::spanner::admin::instance::v1::UpdateInstanceRequest&& Build() && {
130  return std::move(request_);
131  }
132 
133  private:
134  google::spanner::admin::instance::v1::UpdateInstanceRequest request_;
135  void SetDisplayNameImpl(std::string display_name) {
136  if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
137  "display_name", request_.field_mask())) {
138  request_.mutable_field_mask()->add_paths("display_name");
139  }
140  request_.mutable_instance()->set_display_name(std::move(display_name));
141  }
142  void SetNodeCountImpl(int node_count) {
143  if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
144  "node_count", request_.field_mask())) {
145  request_.mutable_field_mask()->add_paths("node_count");
146  }
147  request_.mutable_instance()->set_node_count(node_count);
148  }
149  void SetProcessingUnitsImpl(int processing_units) {
150  if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
151  "processing_units", request_.field_mask())) {
152  request_.mutable_field_mask()->add_paths("processing_units");
153  }
154  request_.mutable_instance()->set_processing_units(processing_units);
155  }
156  void AddLabelsImpl(std::map<std::string, std::string> const& labels) {
157  if (!google::protobuf::util::FieldMaskUtil::IsPathInFieldMask(
158  "labels", request_.field_mask())) {
159  request_.mutable_field_mask()->add_paths("labels");
160  }
161  for (auto const& pair : labels) {
162  request_.mutable_instance()->mutable_labels()->insert(
163  {pair.first, pair.second});
164  }
165  }
166 };
167 
168 } // namespace SPANNER_CLIENT_NS
169 } // namespace spanner
170 } // namespace cloud
171 } // namespace google
172 
173 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_UPDATE_INSTANCE_REQUEST_BUILDER_H