Google Cloud Spanner C++ Client 2.13.0
A C++ Client Library for Google Cloud Spanner
Loading...
Searching...
No Matches
instance_admin_connection.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_INSTANCE_ADMIN_CONNECTION_H
16#define GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INSTANCE_ADMIN_CONNECTION_H
17
18#include "google/cloud/spanner/backoff_policy.h"
19#include "google/cloud/spanner/internal/instance_admin_stub.h"
20#include "google/cloud/spanner/polling_policy.h"
21#include "google/cloud/spanner/retry_policy.h"
22#include "google/cloud/spanner/version.h"
23#include "google/cloud/backoff_policy.h"
24#include "google/cloud/internal/pagination_range.h"
25#include "google/cloud/options.h"
26#include <google/spanner/admin/instance/v1/spanner_instance_admin.pb.h>
27#include <map>
28#include <string>
29#include <vector>
30
31namespace google {
32namespace cloud {
33namespace spanner {
34GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
35
36/**
37 * An input range to stream all the instances in a Cloud project.
38 *
39 * This type models an [input range][cppref-input-range] of
40 * `google::spanner::admin::v1::Instance` objects. Applications can make a
41 * single pass through the results.
42 *
43 * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
44 */
45using ListInstancesRange = ::google::cloud::internal::PaginationRange<
46 google::spanner::admin::instance::v1::Instance>;
47
48/**
49 * An input range to stream all the instance configs in a Cloud project.
50 *
51 * This type models an [input range][cppref-input-range] of
52 * `google::spanner::admin::v1::Instance` objects. Applications can make a
53 * single pass through the results.
54 *
55 * [cppref-input-range]: https://en.cppreference.com/w/cpp/ranges/input_range
56 */
57using ListInstanceConfigsRange = ::google::cloud::internal::PaginationRange<
58 google::spanner::admin::instance::v1::InstanceConfig>;
59
60/**
61 * A connection to the Cloud Spanner instance administration service.
62 *
63 * @deprecated Please use #google::cloud::spanner_admin::InstanceAdminClient
64 * and #google::cloud::spanner_admin::InstanceAdminConnection instead.
65 *
66 * This interface defines pure-virtual methods for each of the user-facing
67 * overload sets in `InstanceAdminClient`. This allows users to inject custom
68 * behavior (e.g., with a Google Mock object) in a `InstanceAdminClient` object
69 * for use in their own tests.
70 *
71 * To create a concrete instance that connects you to a real Cloud Spanner
72 * instance administration service, see `MakeInstanceAdminConnection()`.
73 */
74class GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED("InstanceAdminConnection")
76 public:
77 virtual ~InstanceAdminConnection() = 0;
78
79 ///@{
80 /**
81 * @name Define the arguments for each member function.
82 *
83 * Applications may define classes derived from `InstanceAdminConnection`,
84 * for example, because they want to mock the class. To avoid breaking all
85 * such derived classes when we change the number or type of the arguments
86 * to the member functions we define light weight structures to pass the
87 * arguments.
88 */
89 /// Wrap the arguments for `GetInstance()`.
90 struct GetInstanceParams {
91 /// The full name of the instance in
92 /// `projects/<project-id>/instances/<instance-id>` format.
93 std::string instance_name;
94 };
95
96 /// Wrap the arguments for `CreateInstance()`.
98 google::spanner::admin::instance::v1::CreateInstanceRequest request;
99 };
100
101 /// Wrap the arguments for `UpdateInstance()`.
102 struct UpdateInstanceParams {
103 google::spanner::admin::instance::v1::UpdateInstanceRequest request;
104 };
105
106 /// Wrap the arguments for `DeleteInstance()`.
107 struct DeleteInstanceParams {
108 std::string instance_name;
109 };
110
111 /// Wrap the arguments for `GetInstanceConfig()`.
113 std::string instance_config_name;
114 };
115
116 /// Wrap the arguments for `ListInstanceConfigs()`.
118 std::string project_id;
119 };
120
121 /**
122 * Wrap the arguments for `ListInstances()`.
123 */
124 struct ListInstancesParams {
125 /**
126 * Query the instances in this project.
127 *
128 * This is a required value, it must be non-empty.
129 */
130 std::string project_id;
131
132 /**
133 * A filtering expression to restrict the set of instances included in the
134 * response.
135 *
136 * @see The [RPC reference documentation][1] for the format of the filtering
137 * expression.
138 *
139 * [1]:
140 * https://cloud.google.com/spanner/docs/reference/rpc/google.spanner.admin.instance.v1#google.spanner.admin.instance.v1.ListInstancesRequest
141 */
142 std::string filter;
143 };
144
145 /// Wrap the arguments for `GetIamPolicy()`.
146 struct GetIamPolicyParams {
147 std::string instance_name;
148 };
149
150 /// Wrap the arguments for `SetIamPolicy()`.
151 struct SetIamPolicyParams {
152 std::string instance_name;
153 google::iam::v1::Policy policy;
154 };
155
156 /// Wrap the arguments for `TestIamPermissions()`.
158 std::string instance_name;
159 std::vector<std::string> permissions;
160 };
161 ///@}
162
163 virtual Options options() { return Options{}; }
164
165 /// Return the metadata for the given instance.
166 virtual StatusOr<google::spanner::admin::instance::v1::Instance> GetInstance(
168
169 virtual future<StatusOr<google::spanner::admin::instance::v1::Instance>>
171
172 virtual future<StatusOr<google::spanner::admin::instance::v1::Instance>>
174
176
177 /// Return the InstanceConfig with the given name.
178 virtual StatusOr<google::spanner::admin::instance::v1::InstanceConfig>
180
181 /**
182 * Returns a one-pass input range with all the instance configs.
183 */
184 virtual ListInstanceConfigsRange ListInstanceConfigs(
186
187 /**
188 * Returns a one-pass input range with all the instances meeting the
189 * requirements in @p params
190 */
191 virtual ListInstancesRange ListInstances(ListInstancesParams params) = 0;
192
193 /// Define the interface for a
194 /// google.spanner.v1.DatabaseAdmin.GetIamPolicy RPC.
195 virtual StatusOr<google::iam::v1::Policy> GetIamPolicy(
197
198 /// Define the interface for a
199 /// google.spanner.v1.DatabaseAdmin.SetIamPolicy RPC.
200 virtual StatusOr<google::iam::v1::Policy> SetIamPolicy(
202
203 /// Define the interface for a
204 /// google.spanner.v1.DatabaseAdmin.TestIamPermissions RPC.
205 virtual StatusOr<google::iam::v1::TestIamPermissionsResponse>
207};
208
209/**
210 * Returns an InstanceAdminConnection object that can be used for interacting
211 * with Cloud Spanner's admin APIs.
212 *
213 * The returned connection object should not be used directly; instead it
214 * should be given to a `InstanceAdminClient` instance.
215 *
216 * The optional @p opts argument may be used to configure aspects of the
217 * returned `InstanceAdminConnection`. Expected options are any of the types in
218 * the following option lists.
219 *
220 * - `google::cloud::CommonOptionList`
221 * - `google::cloud::GrpcOptionList`
222 * - `google::cloud::SpannerPolicyOptionList`
223 *
224 * @see `InstanceAdminConnection`
225 *
226 * @param opts (optional) configure the `InstanceAdminConnection` created by
227 * this function.
228 */
229GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED("MakeInstanceAdminConnection()")
231 Options opts = {});
232
233/**
234 * Returns an InstanceAdminConnection object that can be used for interacting
235 * with Cloud Spanner's admin APIs.
236 *
237 * The returned connection object should not be used directly, rather it should
238 * be given to a `InstanceAdminClient` instance.
239 *
240 * @note Prefer using the `MakeInstanceAdminConnection()` overload that accepts
241 * `google::cloud::Options`.
242 *
243 * @see `InstanceAdminConnection`
244 *
245 * @param options configure the `InstanceAdminConnection` created by this
246 * function.
247 */
248GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED("MakeInstanceAdminConnection()")
250 ConnectionOptions const& options);
251
252/**
253 * Returns an InstanceAdminConnection object that can be used for interacting
254 * with Cloud Spanner's admin APIs.
255 *
256 * The returned connection object should not be used directly, rather it should
257 * be given to a `InstanceAdminClient` instance.
258 *
259 * @note Prefer using the `MakeInstanceAdminConnection()` overload that accepts
260 * `google::cloud::Options`.
261 *
262 * @param options configure the `InstanceAdminConnection` created by this
263 * function.
264 * @param retry_policy control for how long (or how many times) are retryable
265 * RPCs attempted
266 * @param backoff_policy controls the backoff behavior between retry attempts,
267 * typically some form of exponential backoff with jitter
268 * @param polling_policy controls for how often, and how quickly, are long
269 * running checked for completion
270 *
271 * @par Example
272 * @snippet samples.cc custom-instance-admin-policies
273 */
274GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED("MakeInstanceAdminConnection()")
276 ConnectionOptions const& options, std::unique_ptr<RetryPolicy> retry_policy,
277 std::unique_ptr<BackoffPolicy> backoff_policy,
278 std::unique_ptr<PollingPolicy> polling_policy);
279
280GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
281} // namespace spanner
282
283namespace spanner_internal {
284GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_BEGIN
285
286/// Internal-only factory that allows us to inject mock stubs for testing.
287std::shared_ptr<spanner::InstanceAdminConnection>
288MakeInstanceAdminConnectionForTesting(
289 std::shared_ptr<InstanceAdminStub> base_stub, Options opts);
290
291GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
292} // namespace spanner_internal
293
294} // namespace cloud
295} // namespace google
296
297#endif // GOOGLE_CLOUD_CPP_GOOGLE_CLOUD_SPANNER_INSTANCE_ADMIN_CONNECTION_H
friend friend class future
A connection to the Cloud Spanner instance administration service.
Definition: instance_admin_connection.h:75
virtual ListInstancesRange ListInstances(ListInstancesParams params)=0
Returns a one-pass input range with all the instances meeting the requirements in params.
virtual StatusOr< google::spanner::admin::instance::v1::Instance > GetInstance(GetInstanceParams)=0
Return the metadata for the given instance.
virtual StatusOr< google::spanner::admin::instance::v1::InstanceConfig > GetInstanceConfig(GetInstanceConfigParams)=0
Return the InstanceConfig with the given name.
virtual future< StatusOr< google::spanner::admin::instance::v1::Instance > > CreateInstance(CreateInstanceParams p)=0
virtual ListInstanceConfigsRange ListInstanceConfigs(ListInstanceConfigsParams)=0
Returns a one-pass input range with all the instance configs.
virtual Status DeleteInstance(DeleteInstanceParams p)=0
virtual StatusOr< google::iam::v1::Policy > SetIamPolicy(SetIamPolicyParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.SetIamPolicy RPC.
virtual StatusOr< google::iam::v1::TestIamPermissionsResponse > TestIamPermissions(TestIamPermissionsParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.TestIamPermissions RPC.
virtual Options options()
Definition: instance_admin_connection.h:163
virtual StatusOr< google::iam::v1::Policy > GetIamPolicy(GetIamPolicyParams)=0
Define the interface for a google.spanner.v1.DatabaseAdmin.GetIamPolicy RPC.
virtual future< StatusOr< google::spanner::admin::instance::v1::Instance > > UpdateInstance(UpdateInstanceParams p)=0
Contains all the Cloud Spanner C++ client types and functions.
Definition: backoff_policy.h:23
std::shared_ptr< spanner::InstanceAdminConnection > MakeInstanceAdminConnection(Options opts={})
Returns an InstanceAdminConnection object that can be used for interacting with Cloud Spanner's admin...
std::shared_ptr< InstanceAdminConnection > MakeInstanceAdminConnection(ConnectionOptions const &options)
Returns an InstanceAdminConnection object that can be used for interacting with Cloud Spanner's admin...
std::shared_ptr< InstanceAdminConnection > MakeInstanceAdminConnection(ConnectionOptions const &options, std::unique_ptr< RetryPolicy > retry_policy, std::unique_ptr< BackoffPolicy > backoff_policy, std::unique_ptr< PollingPolicy > polling_policy)
Returns an InstanceAdminConnection object that can be used for interacting with Cloud Spanner's admin...
Wrap the arguments for CreateInstance().
Definition: instance_admin_connection.h:97
google::spanner::admin::instance::v1::CreateInstanceRequest request
Definition: instance_admin_connection.h:98
Wrap the arguments for DeleteInstance().
Definition: instance_admin_connection.h:107
std::string instance_name
Definition: instance_admin_connection.h:108
Wrap the arguments for GetIamPolicy().
Definition: instance_admin_connection.h:146
std::string instance_name
Definition: instance_admin_connection.h:147
Wrap the arguments for GetInstanceConfig().
Definition: instance_admin_connection.h:112
std::string instance_config_name
Definition: instance_admin_connection.h:113
Wrap the arguments for GetInstance().
Definition: instance_admin_connection.h:90
std::string instance_name
The full name of the instance in projects/<project-id>/instances/<instance-id> format.
Definition: instance_admin_connection.h:93
Wrap the arguments for ListInstanceConfigs().
Definition: instance_admin_connection.h:117
std::string project_id
Definition: instance_admin_connection.h:118
Wrap the arguments for ListInstances().
Definition: instance_admin_connection.h:124
std::string filter
A filtering expression to restrict the set of instances included in the response.
Definition: instance_admin_connection.h:142
std::string project_id
Query the instances in this project.
Definition: instance_admin_connection.h:130
Wrap the arguments for SetIamPolicy().
Definition: instance_admin_connection.h:151
std::string instance_name
Definition: instance_admin_connection.h:152
google::iam::v1::Policy policy
Definition: instance_admin_connection.h:153
Wrap the arguments for TestIamPermissions().
Definition: instance_admin_connection.h:157
std::vector< std::string > permissions
Definition: instance_admin_connection.h:159
std::string instance_name
Definition: instance_admin_connection.h:158
Wrap the arguments for UpdateInstance().
Definition: instance_admin_connection.h:102
google::spanner::admin::instance::v1::UpdateInstanceRequest request
Definition: instance_admin_connection.h:103
#define GOOGLE_CLOUD_CPP_SPANNER_ADMIN_API_DEPRECATED(name)
Definition: version.h:23