Google Cloud Bigtable C++ Client 2.13.0
A C++ Client Library for Google Cloud Bigtable
Loading...
Searching...
No Matches
instance_update_config.h
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_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/cloud/internal/algorithm.h"
21#include <google/bigtable/admin/v2/bigtable_instance_admin.pb.h>
22#include <google/bigtable/admin/v2/common.pb.h>
23#include <map>
24#include <string>
25
26namespace google {
27namespace cloud {
28namespace bigtable {
29GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
30using Instance = ::google::bigtable::admin::v2::Instance;
31
32/// Specify the initial configuration for updating an instance.
34 public:
35 // NOLINTNEXTLINE(google-explicit-constructor)
36 InstanceUpdateConfig(Instance instance) {
37 proto_.mutable_instance()->Swap(&instance);
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 ///@{
55 /// @name Convenient shorthands for the instance state.
56 using StateType = ::google::bigtable::admin::v2::Instance::State;
57 // NOLINTNEXTLINE(readability-identifier-naming)
58 constexpr static StateType STATE_NOT_KNOWN =
59 google::bigtable::admin::v2::Instance::STATE_NOT_KNOWN;
60 // NOLINTNEXTLINE(readability-identifier-naming)
61 constexpr static StateType READY =
62 google::bigtable::admin::v2::Instance::READY;
63 // NOLINTNEXTLINE(readability-identifier-naming)
64 constexpr static StateType CREATING =
65 google::bigtable::admin::v2::Instance::CREATING;
66 ///@}
67
68 InstanceUpdateConfig& set_type(InstanceType type) {
69 proto_.mutable_instance()->set_type(std::move(type));
70 AddPathIfNotPresent("type");
71 return *this;
72 }
73
74 InstanceUpdateConfig& set_state(StateType state) {
75 proto_.mutable_instance()->set_state(std::move(state));
76 AddPathIfNotPresent("state");
77 return *this;
78 }
79
80 InstanceUpdateConfig& set_name(std::string name) {
81 proto_.mutable_instance()->set_name(std::move(name));
82 AddPathIfNotPresent("name");
83 return *this;
84 }
85
86 InstanceUpdateConfig& set_display_name(std::string display_name) {
87 proto_.mutable_instance()->set_display_name(std::move(display_name));
88 AddPathIfNotPresent("display_name");
89 return *this;
90 }
91
92 InstanceUpdateConfig& insert_label(std::string const& key,
93 std::string const& value) {
94 (*proto_.mutable_instance()->mutable_labels())[key] = value;
95 AddPathIfNotPresent("labels");
96 return *this;
97 }
98
99 InstanceUpdateConfig& emplace_label(std::string const& key,
100 std::string value) {
101 (*proto_.mutable_instance()->mutable_labels())[key] = std::move(value);
102 AddPathIfNotPresent("labels");
103 return *this;
104 }
105
106 // NOLINT: accessors can (and should) be snake_case.
107 google::bigtable::admin::v2::PartialUpdateInstanceRequest const& as_proto()
108 const& {
109 return proto_;
110 }
111
112 // NOLINT: accessors can (and should) be snake_case.
113 google::bigtable::admin::v2::PartialUpdateInstanceRequest&& as_proto() && {
114 return std::move(proto_);
115 }
116
117 std::string const& GetName() { return proto_.mutable_instance()->name(); }
118
119 private:
120 void AddPathIfNotPresent(std::string const& field_name) {
121 if (!google::cloud::internal::Contains(proto_.update_mask().paths(),
122 field_name)) {
123 proto_.mutable_update_mask()->add_paths(field_name);
124 }
125 }
126
127 google::bigtable::admin::v2::PartialUpdateInstanceRequest proto_;
128};
129
130GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
131} // namespace bigtable
132} // namespace cloud
133} // namespace google
134
135#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_BIGTABLE_INSTANCE_UPDATE_CONFIG_H
Specify the initial configuration for updating an instance.
Definition: instance_update_config.h:33
static constexpr InstanceType DEVELOPMENT
Definition: instance_update_config.h:50
InstanceUpdateConfig & set_state(StateType state)
Definition: instance_update_config.h:74
std::string const & GetName()
Definition: instance_update_config.h:117
google::bigtable::admin::v2::PartialUpdateInstanceRequest && as_proto() &&
Definition: instance_update_config.h:113
InstanceUpdateConfig & set_display_name(std::string display_name)
Definition: instance_update_config.h:86
static constexpr StateType STATE_NOT_KNOWN
Definition: instance_update_config.h:58
InstanceUpdateConfig & set_type(InstanceType type)
Definition: instance_update_config.h:68
static constexpr InstanceType PRODUCTION
Definition: instance_update_config.h:47
InstanceUpdateConfig & set_name(std::string name)
Definition: instance_update_config.h:80
static constexpr StateType CREATING
Definition: instance_update_config.h:64
InstanceUpdateConfig(Instance instance)
Definition: instance_update_config.h:36
static constexpr StateType READY
Definition: instance_update_config.h:61
static constexpr InstanceType TYPE_UNSPECIFIED
Definition: instance_update_config.h:44
google::bigtable::admin::v2::PartialUpdateInstanceRequest const & as_proto() const &
Definition: instance_update_config.h:107
InstanceUpdateConfig & insert_label(std::string const &key, std::string const &value)
Definition: instance_update_config.h:92
InstanceUpdateConfig & emplace_label(std::string const &key, std::string value)
Definition: instance_update_config.h:99
Contains all the Cloud Bigtable C++ client APIs.
Definition: admin_client.h:28