Google Cloud Bigtable C++ Client  1.42.0
A C++ Client Library for Google Cloud Bigtable
instance_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_INSTANCE_CONFIG_H
16 #define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_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 <string>
24 
25 namespace google {
26 namespace cloud {
27 namespace bigtable {
29 /// Specify the initial configuration for a new instance.
31  public:
32  InstanceConfig(std::string instance_id, std::string display_name,
33  std::map<std::string, ClusterConfig> clusters) {
34  proto_.set_instance_id(std::move(instance_id));
35  proto_.mutable_instance()->set_display_name(std::move(display_name));
36  for (auto& kv : clusters) {
37  (*proto_.mutable_clusters())[kv.first] = std::move(kv.second).as_proto();
38  }
39  }
40  //@{
41  /// @name Convenient shorthands for the instance types.
42  using InstanceType = ::google::bigtable::admin::v2::Instance::Type;
43  // NOLINTNEXTLINE(readability-identifier-naming)
44  constexpr static InstanceType TYPE_UNSPECIFIED =
45  google::bigtable::admin::v2::Instance::TYPE_UNSPECIFIED;
46  // NOLINTNEXTLINE(readability-identifier-naming)
47  constexpr static InstanceType PRODUCTION =
48  google::bigtable::admin::v2::Instance::PRODUCTION;
49  // NOLINTNEXTLINE(readability-identifier-naming)
50  constexpr static InstanceType DEVELOPMENT =
51  google::bigtable::admin::v2::Instance::DEVELOPMENT;
52  //@}
53 
54  InstanceConfig& set_type(InstanceType type) {
55  proto_.mutable_instance()->set_type(type);
56  return *this;
57  }
58 
59  InstanceConfig& insert_label(std::string const& key,
60  std::string const& value) {
61  (*proto_.mutable_instance()->mutable_labels())[key] = value;
62  return *this;
63  }
64 
65  InstanceConfig& emplace_label(std::string const& key, std::string value) {
66  (*proto_.mutable_instance()->mutable_labels())[key] = std::move(value);
67  return *this;
68  }
69 
70  // NOLINT: accessors can (and should) be snake_case.
71  google::bigtable::admin::v2::CreateInstanceRequest const& as_proto() const& {
72  return proto_;
73  }
74 
75  // NOLINT: accessors can (and should) be snake_case.
76  google::bigtable::admin::v2::CreateInstanceRequest&& as_proto() && {
77  return std::move(proto_);
78  }
79 
80  private:
81  google::bigtable::admin::v2::CreateInstanceRequest proto_;
82 };
83 
85 } // namespace bigtable
86 } // namespace cloud
87 } // namespace google
88 
89 #endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_CONFIG_H