Google Cloud Bigtable C++ Client  1.1.0
A C++ Client Library for Google Cloud Bigtable
instance_admin_client.cc
Go to the documentation of this file.
1 // Copyright 2018 Google Inc.
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 #include "google/cloud/bigtable/instance_admin_client.h"
16 #include "google/cloud/bigtable/internal/common_client.h"
17 #include <google/longrunning/operations.grpc.pb.h>
18 
19 namespace google {
20 namespace cloud {
21 namespace bigtable {
22 inline namespace BIGTABLE_CLIENT_NS {
23 namespace internal {
24 /// Define what endpoint in ClientOptions is used for the InstanceAdminClient.
25 struct InstanceAdminTraits {
26  static std::string const& Endpoint(ClientOptions& options) {
27  return options.instance_admin_endpoint();
28  }
29 };
30 } // namespace internal
31 
32 namespace {
33 /**
34  * An AdminClient for single-threaded programs that refreshes credentials on all
35  * gRPC errors.
36  *
37  * This class should not be used by multiple threads, it makes no attempt to
38  * protect its critical sections. While it is rare that the admin interface
39  * will be used by multiple threads, we should use the same approach here and in
40  * the regular client to support multi-threaded programs.
41  *
42  * The class also aggressively reconnects on any gRPC errors. A future version
43  * should only reconnect on those errors that indicate the credentials or
44  * connections need refreshing.
45  */
46 class DefaultInstanceAdminClient : public InstanceAdminClient {
47  private:
48  // Introduce an early `private:` section because this type is used to define
49  // the public interface, it should not be part of the public interface.
50  using Impl = internal::CommonClient<
51  internal::InstanceAdminTraits,
52  ::google::bigtable::admin::v2::BigtableInstanceAdmin>;
53 
54  public:
55  using AdminStubPtr = Impl::StubPtr;
56 
57  DefaultInstanceAdminClient(std::string project, ClientOptions options)
58  : project_(std::move(project)), impl_(std::move(options)) {}
59 
60  std::string const& project() const override { return project_; }
61  Impl::ChannelPtr Channel() override { return impl_.Channel(); }
62  void reset() override { return impl_.reset(); }
63 
64  grpc::Status ListInstances(
65  grpc::ClientContext* context,
66  google::bigtable::admin::v2::ListInstancesRequest const& request,
67  google::bigtable::admin::v2::ListInstancesResponse* response) override {
68  return impl_.Stub()->ListInstances(context, request, response);
69  }
70 
71  grpc::Status CreateInstance(
72  grpc::ClientContext* context,
73  google::bigtable::admin::v2::CreateInstanceRequest const& request,
74  google::longrunning::Operation* response) override {
75  return impl_.Stub()->CreateInstance(context, request, response);
76  }
77 
78  grpc::Status UpdateInstance(
79  grpc::ClientContext* context,
80  google::bigtable::admin::v2::PartialUpdateInstanceRequest const& request,
81  google::longrunning::Operation* response) override {
82  return impl_.Stub()->PartialUpdateInstance(context, request, response);
83  }
84 
85  grpc::Status GetOperation(
86  grpc::ClientContext* context,
87  google::longrunning::GetOperationRequest const& request,
88  google::longrunning::Operation* response) override {
89  auto stub = google::longrunning::Operations::NewStub(Channel());
90  return stub->GetOperation(context, request, response);
91  }
92 
93  grpc::Status GetInstance(
94  grpc::ClientContext* context,
95  google::bigtable::admin::v2::GetInstanceRequest const& request,
96  google::bigtable::admin::v2::Instance* response) override {
97  return impl_.Stub()->GetInstance(context, request, response);
98  }
99 
100  grpc::Status DeleteInstance(
101  grpc::ClientContext* context,
102  google::bigtable::admin::v2::DeleteInstanceRequest const& request,
103  google::protobuf::Empty* response) override {
104  return impl_.Stub()->DeleteInstance(context, request, response);
105  }
106 
107  grpc::Status ListClusters(
108  grpc::ClientContext* context,
109  google::bigtable::admin::v2::ListClustersRequest const& request,
110  google::bigtable::admin::v2::ListClustersResponse* response) override {
111  return impl_.Stub()->ListClusters(context, request, response);
112  }
113 
114  grpc::Status GetCluster(
115  grpc::ClientContext* context,
116  google::bigtable::admin::v2::GetClusterRequest const& request,
117  google::bigtable::admin::v2::Cluster* response) override {
118  return impl_.Stub()->GetCluster(context, request, response);
119  }
120 
121  grpc::Status DeleteCluster(
122  grpc::ClientContext* context,
123  google::bigtable::admin::v2::DeleteClusterRequest const& request,
124  google::protobuf::Empty* response) override {
125  return impl_.Stub()->DeleteCluster(context, request, response);
126  }
127 
128  grpc::Status CreateCluster(
129  grpc::ClientContext* context,
130  google::bigtable::admin::v2::CreateClusterRequest const& request,
131  google::longrunning::Operation* response) override {
132  return impl_.Stub()->CreateCluster(context, request, response);
133  }
134 
135  grpc::Status UpdateCluster(
136  grpc::ClientContext* context,
137  google::bigtable::admin::v2::Cluster const& request,
138  google::longrunning::Operation* response) override {
139  return impl_.Stub()->UpdateCluster(context, request, response);
140  }
141 
142  grpc::Status CreateAppProfile(
143  grpc::ClientContext* context,
144  google::bigtable::admin::v2::CreateAppProfileRequest const& request,
145  google::bigtable::admin::v2::AppProfile* response) override {
146  return impl_.Stub()->CreateAppProfile(context, request, response);
147  }
148 
149  grpc::Status GetAppProfile(
150  grpc::ClientContext* context,
151  google::bigtable::admin::v2::GetAppProfileRequest const& request,
152  google::bigtable::admin::v2::AppProfile* response) override {
153  return impl_.Stub()->GetAppProfile(context, request, response);
154  }
155 
156  grpc::Status ListAppProfiles(
157  grpc::ClientContext* context,
158  google::bigtable::admin::v2::ListAppProfilesRequest const& request,
159  google::bigtable::admin::v2::ListAppProfilesResponse* response) override {
160  return impl_.Stub()->ListAppProfiles(context, request, response);
161  }
162 
163  grpc::Status UpdateAppProfile(
164  grpc::ClientContext* context,
165  google::bigtable::admin::v2::UpdateAppProfileRequest const& request,
166  google::longrunning::Operation* response) override {
167  return impl_.Stub()->UpdateAppProfile(context, request, response);
168  }
169 
170  grpc::Status DeleteAppProfile(
171  grpc::ClientContext* context,
172  google::bigtable::admin::v2::DeleteAppProfileRequest const& request,
173  google::protobuf::Empty* response) override {
174  return impl_.Stub()->DeleteAppProfile(context, request, response);
175  }
176 
177  grpc::Status GetIamPolicy(grpc::ClientContext* context,
178  google::iam::v1::GetIamPolicyRequest const& request,
179  google::iam::v1::Policy* response) override {
180  return impl_.Stub()->GetIamPolicy(context, request, response);
181  }
182 
183  grpc::Status SetIamPolicy(grpc::ClientContext* context,
184  google::iam::v1::SetIamPolicyRequest const& request,
185  google::iam::v1::Policy* response) override {
186  return impl_.Stub()->SetIamPolicy(context, request, response);
187  }
188 
189  grpc::Status TestIamPermissions(
190  grpc::ClientContext* context,
191  google::iam::v1::TestIamPermissionsRequest const& request,
192  google::iam::v1::TestIamPermissionsResponse* response) override {
193  return impl_.Stub()->TestIamPermissions(context, request, response);
194  }
195 
196  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
197  google::bigtable::admin::v2::ListInstancesResponse>>
198  AsyncListInstances(
199  grpc::ClientContext* context,
200  google::bigtable::admin::v2::ListInstancesRequest const& request,
201  grpc::CompletionQueue* cq) override {
202  return impl_.Stub()->AsyncListInstances(context, request, cq);
203  }
204 
205  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
206  google::bigtable::admin::v2::Instance>>
207  AsyncGetInstance(
208  grpc::ClientContext* context,
209  google::bigtable::admin::v2::GetInstanceRequest const& request,
210  grpc::CompletionQueue* cq) override {
211  return impl_.Stub()->AsyncGetInstance(context, request, cq);
212  }
213 
214  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
215  google::bigtable::admin::v2::Cluster>>
216  AsyncGetCluster(grpc::ClientContext* context,
217  google::bigtable::admin::v2::GetClusterRequest const& request,
218  grpc::CompletionQueue* cq) override {
219  return impl_.Stub()->AsyncGetCluster(context, request, cq);
220  }
221 
222  std::unique_ptr<
223  grpc::ClientAsyncResponseReaderInterface<google::protobuf::Empty>>
224  AsyncDeleteCluster(
225  grpc::ClientContext* context,
226  google::bigtable::admin::v2::DeleteClusterRequest const& request,
227  grpc::CompletionQueue* cq) override {
228  return impl_.Stub()->AsyncDeleteCluster(context, request, cq);
229  }
230 
231  std::unique_ptr<
232  grpc::ClientAsyncResponseReaderInterface<google::longrunning::Operation>>
233  AsyncCreateCluster(
234  grpc::ClientContext* context,
235  const google::bigtable::admin::v2::CreateClusterRequest& request,
236  grpc::CompletionQueue* cq) override {
237  return impl_.Stub()->AsyncCreateCluster(context, request, cq);
238  }
239 
240  std::unique_ptr<
241  grpc::ClientAsyncResponseReaderInterface<google::longrunning::Operation>>
242  AsyncCreateInstance(
243  grpc::ClientContext* context,
244  const google::bigtable::admin::v2::CreateInstanceRequest& request,
245  grpc::CompletionQueue* cq) override {
246  return impl_.Stub()->AsyncCreateInstance(context, request, cq);
247  }
248 
249  std::unique_ptr<
250  grpc::ClientAsyncResponseReaderInterface<google::longrunning::Operation>>
251  AsyncUpdateInstance(
252  grpc::ClientContext* context,
253  const google::bigtable::admin::v2::PartialUpdateInstanceRequest& request,
254  grpc::CompletionQueue* cq) override {
255  return impl_.Stub()->AsyncPartialUpdateInstance(context, request, cq);
256  }
257 
258  std::unique_ptr<
259  grpc::ClientAsyncResponseReaderInterface<google::longrunning::Operation>>
260  AsyncUpdateCluster(grpc::ClientContext* context,
261  const google::bigtable::admin::v2::Cluster& request,
262  grpc::CompletionQueue* cq) override {
263  return impl_.Stub()->AsyncUpdateCluster(context, request, cq);
264  }
265 
266  std::unique_ptr<
267  grpc::ClientAsyncResponseReaderInterface<google::protobuf::Empty>>
268  AsyncDeleteInstance(
269  grpc::ClientContext* context,
270  google::bigtable::admin::v2::DeleteInstanceRequest const& request,
271  grpc::CompletionQueue* cq) override {
272  return impl_.Stub()->AsyncDeleteInstance(context, request, cq);
273  }
274 
275  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
276  google::bigtable::admin::v2::ListClustersResponse>>
277  AsyncListClusters(
278  grpc::ClientContext* context,
279  const google::bigtable::admin::v2::ListClustersRequest& request,
280  grpc::CompletionQueue* cq) override {
281  return impl_.Stub()->AsyncListClusters(context, request, cq);
282  }
283 
284  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
285  google::bigtable::admin::v2::AppProfile>>
286  AsyncGetAppProfile(
287  grpc::ClientContext* context,
288  google::bigtable::admin::v2::GetAppProfileRequest const& request,
289  grpc::CompletionQueue* cq) override {
290  return impl_.Stub()->AsyncGetAppProfile(context, request, cq);
291  }
292 
293  std::unique_ptr<
294  grpc::ClientAsyncResponseReaderInterface<google::protobuf::Empty>>
295  AsyncDeleteAppProfile(
296  grpc::ClientContext* context,
297  google::bigtable::admin::v2::DeleteAppProfileRequest const& request,
298  grpc::CompletionQueue* cq) override {
299  return impl_.Stub()->AsyncDeleteAppProfile(context, request, cq);
300  }
301 
302  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
303  google::bigtable::admin::v2::AppProfile>>
304  AsyncCreateAppProfile(
305  grpc::ClientContext* context,
306  google::bigtable::admin::v2::CreateAppProfileRequest const& request,
307  grpc::CompletionQueue* cq) override {
308  return impl_.Stub()->AsyncCreateAppProfile(context, request, cq);
309  }
310 
311  std::unique_ptr<
312  grpc::ClientAsyncResponseReaderInterface<google::longrunning::Operation>>
313  AsyncUpdateAppProfile(
314  grpc::ClientContext* context,
315  const google::bigtable::admin::v2::UpdateAppProfileRequest& request,
316  grpc::CompletionQueue* cq) override {
317  return impl_.Stub()->AsyncUpdateAppProfile(context, request, cq);
318  }
319 
320  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
321  google::bigtable::admin::v2::ListAppProfilesResponse>>
322  AsyncListAppProfiles(
323  grpc::ClientContext* context,
324  const google::bigtable::admin::v2::ListAppProfilesRequest& request,
325  grpc::CompletionQueue* cq) override {
326  return impl_.Stub()->AsyncListAppProfiles(context, request, cq);
327  }
328 
329  std::unique_ptr<
330  grpc::ClientAsyncResponseReaderInterface<google::iam::v1::Policy>>
331  AsyncGetIamPolicy(grpc::ClientContext* context,
332  google::iam::v1::GetIamPolicyRequest const& request,
333  grpc::CompletionQueue* cq) override {
334  return impl_.Stub()->AsyncGetIamPolicy(context, request, cq);
335  }
336 
337  std::unique_ptr<
338  grpc::ClientAsyncResponseReaderInterface<google::iam::v1::Policy>>
339  AsyncSetIamPolicy(grpc::ClientContext* context,
340  google::iam::v1::SetIamPolicyRequest const& request,
341  grpc::CompletionQueue* cq) override {
342  return impl_.Stub()->AsyncSetIamPolicy(context, request, cq);
343  }
344 
345  std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
346  google::iam::v1::TestIamPermissionsResponse>>
347  AsyncTestIamPermissions(
348  grpc::ClientContext* context,
349  google::iam::v1::TestIamPermissionsRequest const& request,
350  grpc::CompletionQueue* cq) override {
351  return impl_.Stub()->AsyncTestIamPermissions(context, request, cq);
352  }
353 
354  std::unique_ptr<
355  grpc::ClientAsyncResponseReaderInterface<google::longrunning::Operation>>
356  AsyncGetOperation(grpc::ClientContext* context,
357  const google::longrunning::GetOperationRequest& request,
358  grpc::CompletionQueue* cq) override {
359  auto stub = google::longrunning::Operations::NewStub(Channel());
360  return std::unique_ptr<grpc::ClientAsyncResponseReaderInterface<
361  google::longrunning::Operation>>(
362  stub->AsyncGetOperation(context, request, cq).release());
363  }
364 
365  DefaultInstanceAdminClient(DefaultInstanceAdminClient const&) = delete;
366  DefaultInstanceAdminClient& operator=(DefaultInstanceAdminClient const&) =
367  delete;
368 
369  private:
370  std::string project_;
371  Impl impl_;
372 };
373 } // anonymous namespace
374 
375 std::shared_ptr<InstanceAdminClient> CreateDefaultInstanceAdminClient(
376  std::string project, ClientOptions options) {
377  return std::make_shared<DefaultInstanceAdminClient>(std::move(project),
378  std::move(options));
379 }
380 
381 } // namespace BIGTABLE_CLIENT_NS
382 } // namespace bigtable
383 } // namespace cloud
384 } // namespace google
#define BIGTABLE_CLIENT_NS
Definition: version.h:22
Configuration options for the Bigtable Client.
Contains all the Cloud Bigtable C++ client APIs.