Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
create_instance_request_builder.h
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// 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_SPANNER_CREATE_INSTANCE_REQUEST_BUILDER_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_CREATE_INSTANCE_REQUEST_BUILDER_H
17
18#include "google/cloud/spanner/instance.h"
19#include "google/cloud/spanner/version.h"
20#include <google/protobuf/util/message_differencer.h>
21#include <google/spanner/admin/instance/v1/spanner_instance_admin.pb.h>
22#include <map>
23#include <string>
24
25namespace google {
26namespace cloud {
27namespace spanner {
28GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
29
30/**
31 * CreateInstanceRequestBuilder is a builder class for
32 * `google::spanner::admin::instance::v1::CreateInstanceRequest`
33 *
34 * This is useful when calling the `InstanceAdminClient::CreateInstance()`
35 * function.
36 *
37 * @par Example
38 * @snippet samples.cc create-instance
39 */
41 public:
42 // Copy and move.
46 default;
48 default;
49
50 friend bool operator==(CreateInstanceRequestBuilder const& a,
51 CreateInstanceRequestBuilder const& b) noexcept {
52 return google::protobuf::util::MessageDifferencer::Equivalent(a.request_,
53 b.request_);
54 }
55 friend bool operator!=(CreateInstanceRequestBuilder const& a,
56 CreateInstanceRequestBuilder const& b) noexcept {
57 return !(a == b);
58 }
59
60 /**
61 * Constructor requires Instance and Cloud Spanner instance config name.
62 * The display_name is set to a default value of in.instance_id().
63 */
64 CreateInstanceRequestBuilder(Instance const& in, std::string config) {
65 request_.set_parent(in.project().FullName());
66 request_.set_instance_id(in.instance_id());
67 request_.mutable_instance()->set_name(in.FullName());
68 request_.mutable_instance()->set_display_name(in.instance_id());
69 request_.mutable_instance()->set_config(std::move(config));
70 }
71
72 CreateInstanceRequestBuilder& SetDisplayName(std::string display_name) & {
73 request_.mutable_instance()->set_display_name(std::move(display_name));
74 return *this;
75 }
76
77 CreateInstanceRequestBuilder&& SetDisplayName(std::string display_name) && {
78 request_.mutable_instance()->set_display_name(std::move(display_name));
79 return std::move(*this);
80 }
81
83 request_.mutable_instance()->set_node_count(node_count);
84 return *this;
85 }
86
87 CreateInstanceRequestBuilder&& SetNodeCount(int node_count) && {
88 request_.mutable_instance()->set_node_count(node_count);
89 return std::move(*this);
90 }
91
92 CreateInstanceRequestBuilder& SetProcessingUnits(int processing_units) & {
93 request_.mutable_instance()->set_processing_units(processing_units);
94 return *this;
95 }
96
97 CreateInstanceRequestBuilder&& SetProcessingUnits(int processing_units) && {
98 request_.mutable_instance()->set_processing_units(processing_units);
99 return std::move(*this);
100 }
101
103 std::map<std::string, std::string> const& labels) & {
104 for (auto const& pair : labels) {
105 request_.mutable_instance()->mutable_labels()->insert(
106 {pair.first, pair.second});
107 }
108 return *this;
109 }
110
112 std::map<std::string, std::string> const& labels) && {
113 for (auto const& pair : labels) {
114 request_.mutable_instance()->mutable_labels()->insert(
115 {pair.first, pair.second});
116 }
117 return std::move(*this);
118 }
119
120 google::spanner::admin::instance::v1::CreateInstanceRequest& Build() & {
121 // Preserve original behavior of defaulting node_count to 1.
122 if (request_.instance().processing_units() == 0) {
123 if (request_.instance().node_count() == 0) {
124 request_.mutable_instance()->set_node_count(1);
125 }
126 }
127 return request_;
128 }
129 google::spanner::admin::instance::v1::CreateInstanceRequest&& Build() && {
130 // Preserve original behavior of defaulting node_count to 1.
131 if (request_.instance().processing_units() == 0) {
132 if (request_.instance().node_count() == 0) {
133 request_.mutable_instance()->set_node_count(1);
134 }
135 }
136 return std::move(request_);
137 }
138
139 private:
140 google::spanner::admin::instance::v1::CreateInstanceRequest request_;
141};
142
143GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
144} // namespace spanner
145} // namespace cloud
146} // namespace google
147
148#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_CREATE_INSTANCE_REQUEST_BUILDER_H
std::string FullName() const
CreateInstanceRequestBuilder is a builder class for google::spanner::admin::instance::v1::CreateInsta...
Definition: create_instance_request_builder.h:40
CreateInstanceRequestBuilder && SetNodeCount(int node_count) &&
Definition: create_instance_request_builder.h:87
CreateInstanceRequestBuilder(CreateInstanceRequestBuilder &&)=default
CreateInstanceRequestBuilder(CreateInstanceRequestBuilder const &)=default
CreateInstanceRequestBuilder & SetNodeCount(int node_count) &
Definition: create_instance_request_builder.h:82
CreateInstanceRequestBuilder(Instance const &in, std::string config)
Constructor requires Instance and Cloud Spanner instance config name.
Definition: create_instance_request_builder.h:64
CreateInstanceRequestBuilder & SetLabels(std::map< std::string, std::string > const &labels) &
Definition: create_instance_request_builder.h:102
CreateInstanceRequestBuilder && SetLabels(std::map< std::string, std::string > const &labels) &&
Definition: create_instance_request_builder.h:111
CreateInstanceRequestBuilder & SetProcessingUnits(int processing_units) &
Definition: create_instance_request_builder.h:92
CreateInstanceRequestBuilder && SetProcessingUnits(int processing_units) &&
Definition: create_instance_request_builder.h:97
CreateInstanceRequestBuilder & operator=(CreateInstanceRequestBuilder const &)=default
CreateInstanceRequestBuilder & operator=(CreateInstanceRequestBuilder &&)=default
friend bool operator==(CreateInstanceRequestBuilder const &a, CreateInstanceRequestBuilder const &b) noexcept
Definition: create_instance_request_builder.h:50
google::spanner::admin::instance::v1::CreateInstanceRequest & Build() &
Definition: create_instance_request_builder.h:120
CreateInstanceRequestBuilder && SetDisplayName(std::string display_name) &&
Definition: create_instance_request_builder.h:77
CreateInstanceRequestBuilder & SetDisplayName(std::string display_name) &
Definition: create_instance_request_builder.h:72
friend bool operator!=(CreateInstanceRequestBuilder const &a, CreateInstanceRequestBuilder const &b) noexcept
Definition: create_instance_request_builder.h:55
google::spanner::admin::instance::v1::CreateInstanceRequest && Build() &&
Definition: create_instance_request_builder.h:129
This class identifies a Cloud Spanner Instance.
Definition: instance.h:42
std::string FullName() const
Returns the fully qualified instance name as a string of the form: "projects/<project-id>/instances/<...
Project const & project() const
Returns the Project containing this instance.
Definition: instance.h:68
std::string const & instance_id() const
Returns the Instance ID.
Definition: instance.h:72
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23