Skip to content

Commit 38e7711

Browse files
committed
feat(spanner): add deprecation warnings; add field_mask to get_instance; add endpoint_uris to Instance proto; update timeouts; make mutations optional for commits (via synth)
1 parent de73e45 commit 38e7711

22 files changed

+636
-473
lines changed

spanner/docs/_static/custom.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
div#python2-eol {
22
border-color: red;
33
border-width: medium;
4-
}
4+
}

spanner/docs/_templates/layout.html

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
{% extends "!layout.html" %}
23
{%- block content %}
34
{%- if theme_fixed_sidebar|lower == 'true' %}

spanner/google/cloud/spanner_admin_database_v1/gapic/database_admin_client.py

+122-109
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@ def from_service_account_file(cls, filename, *args, **kwargs):
8888

8989
@classmethod
9090
def database_path(cls, project, instance, database):
91-
"""Return a fully-qualified database string."""
91+
"""DEPRECATED. Return a fully-qualified database string."""
92+
warnings.warn(
93+
"Resource name helper functions are deprecated.",
94+
PendingDeprecationWarning,
95+
stacklevel=1,
96+
)
9297
return google.api_core.path_template.expand(
9398
"projects/{project}/instances/{instance}/databases/{database}",
9499
project=project,
@@ -98,7 +103,12 @@ def database_path(cls, project, instance, database):
98103

99104
@classmethod
100105
def instance_path(cls, project, instance):
101-
"""Return a fully-qualified instance string."""
106+
"""DEPRECATED. Return a fully-qualified instance string."""
107+
warnings.warn(
108+
"Resource name helper functions are deprecated.",
109+
PendingDeprecationWarning,
110+
stacklevel=1,
111+
)
102112
return google.api_core.path_template.expand(
103113
"projects/{project}/instances/{instance}",
104114
project=project,
@@ -218,110 +228,6 @@ def __init__(
218228
self._inner_api_calls = {}
219229

220230
# Service calls
221-
def list_databases(
222-
self,
223-
parent,
224-
page_size=None,
225-
retry=google.api_core.gapic_v1.method.DEFAULT,
226-
timeout=google.api_core.gapic_v1.method.DEFAULT,
227-
metadata=None,
228-
):
229-
"""
230-
Lists Cloud Spanner databases.
231-
232-
Example:
233-
>>> from google.cloud import spanner_admin_database_v1
234-
>>>
235-
>>> client = spanner_admin_database_v1.DatabaseAdminClient()
236-
>>>
237-
>>> parent = client.instance_path('[PROJECT]', '[INSTANCE]')
238-
>>>
239-
>>> # Iterate over all results
240-
>>> for element in client.list_databases(parent):
241-
... # process element
242-
... pass
243-
>>>
244-
>>>
245-
>>> # Alternatively:
246-
>>>
247-
>>> # Iterate over results one page at a time
248-
>>> for page in client.list_databases(parent).pages:
249-
... for element in page:
250-
... # process element
251-
... pass
252-
253-
Args:
254-
parent (str): Required. The instance whose databases should be listed. Values are of
255-
the form ``projects/<project>/instances/<instance>``.
256-
page_size (int): The maximum number of resources contained in the
257-
underlying API response. If page streaming is performed per-
258-
resource, this parameter does not affect the return value. If page
259-
streaming is performed per-page, this determines the maximum number
260-
of resources in a page.
261-
retry (Optional[google.api_core.retry.Retry]): A retry object used
262-
to retry requests. If ``None`` is specified, requests will
263-
be retried using a default configuration.
264-
timeout (Optional[float]): The amount of time, in seconds, to wait
265-
for the request to complete. Note that if ``retry`` is
266-
specified, the timeout applies to each individual attempt.
267-
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
268-
that is provided to the method.
269-
270-
Returns:
271-
A :class:`~google.api_core.page_iterator.PageIterator` instance.
272-
An iterable of :class:`~google.cloud.spanner_admin_database_v1.types.Database` instances.
273-
You can also iterate over the pages of the response
274-
using its `pages` property.
275-
276-
Raises:
277-
google.api_core.exceptions.GoogleAPICallError: If the request
278-
failed for any reason.
279-
google.api_core.exceptions.RetryError: If the request failed due
280-
to a retryable error and retry attempts failed.
281-
ValueError: If the parameters are invalid.
282-
"""
283-
# Wrap the transport method to add retry and timeout logic.
284-
if "list_databases" not in self._inner_api_calls:
285-
self._inner_api_calls[
286-
"list_databases"
287-
] = google.api_core.gapic_v1.method.wrap_method(
288-
self.transport.list_databases,
289-
default_retry=self._method_configs["ListDatabases"].retry,
290-
default_timeout=self._method_configs["ListDatabases"].timeout,
291-
client_info=self._client_info,
292-
)
293-
294-
request = spanner_database_admin_pb2.ListDatabasesRequest(
295-
parent=parent, page_size=page_size
296-
)
297-
if metadata is None:
298-
metadata = []
299-
metadata = list(metadata)
300-
try:
301-
routing_header = [("parent", parent)]
302-
except AttributeError:
303-
pass
304-
else:
305-
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
306-
routing_header
307-
)
308-
metadata.append(routing_metadata)
309-
310-
iterator = google.api_core.page_iterator.GRPCIterator(
311-
client=None,
312-
method=functools.partial(
313-
self._inner_api_calls["list_databases"],
314-
retry=retry,
315-
timeout=timeout,
316-
metadata=metadata,
317-
),
318-
request=request,
319-
items_field="databases",
320-
request_token_field="page_token",
321-
response_token_field="next_page_token",
322-
)
323-
return iterator
324-
325231
def create_database(
326232
self,
327233
parent,
@@ -769,7 +675,8 @@ def set_iam_policy(
769675
>>>
770676
>>> client = spanner_admin_database_v1.DatabaseAdminClient()
771677
>>>
772-
>>> resource = client.database_path('[PROJECT]', '[INSTANCE]', '[DATABASE]')
678+
>>> # TODO: Initialize `resource`:
679+
>>> resource = ''
773680
>>>
774681
>>> # TODO: Initialize `policy`:
775682
>>> policy = {}
@@ -854,7 +761,8 @@ def get_iam_policy(
854761
>>>
855762
>>> client = spanner_admin_database_v1.DatabaseAdminClient()
856763
>>>
857-
>>> resource = client.database_path('[PROJECT]', '[INSTANCE]', '[DATABASE]')
764+
>>> # TODO: Initialize `resource`:
765+
>>> resource = ''
858766
>>>
859767
>>> response = client.get_iam_policy(resource)
860768
@@ -938,7 +846,8 @@ def test_iam_permissions(
938846
>>>
939847
>>> client = spanner_admin_database_v1.DatabaseAdminClient()
940848
>>>
941-
>>> resource = client.database_path('[PROJECT]', '[INSTANCE]', '[DATABASE]')
849+
>>> # TODO: Initialize `resource`:
850+
>>> resource = ''
942851
>>>
943852
>>> # TODO: Initialize `permissions`:
944853
>>> permissions = []
@@ -1001,3 +910,107 @@ def test_iam_permissions(
1001910
return self._inner_api_calls["test_iam_permissions"](
1002911
request, retry=retry, timeout=timeout, metadata=metadata
1003912
)
913+
914+
def list_databases(
915+
self,
916+
parent,
917+
page_size=None,
918+
retry=google.api_core.gapic_v1.method.DEFAULT,
919+
timeout=google.api_core.gapic_v1.method.DEFAULT,
920+
metadata=None,
921+
):
922+
"""
923+
Lists Cloud Spanner databases.
924+
925+
Example:
926+
>>> from google.cloud import spanner_admin_database_v1
927+
>>>
928+
>>> client = spanner_admin_database_v1.DatabaseAdminClient()
929+
>>>
930+
>>> parent = client.instance_path('[PROJECT]', '[INSTANCE]')
931+
>>>
932+
>>> # Iterate over all results
933+
>>> for element in client.list_databases(parent):
934+
... # process element
935+
... pass
936+
>>>
937+
>>>
938+
>>> # Alternatively:
939+
>>>
940+
>>> # Iterate over results one page at a time
941+
>>> for page in client.list_databases(parent).pages:
942+
... for element in page:
943+
... # process element
944+
... pass
945+
946+
Args:
947+
parent (str): Required. The instance whose databases should be listed. Values are of
948+
the form ``projects/<project>/instances/<instance>``.
949+
page_size (int): The maximum number of resources contained in the
950+
underlying API response. If page streaming is performed per-
951+
resource, this parameter does not affect the return value. If page
952+
streaming is performed per-page, this determines the maximum number
953+
of resources in a page.
954+
retry (Optional[google.api_core.retry.Retry]): A retry object used
955+
to retry requests. If ``None`` is specified, requests will
956+
be retried using a default configuration.
957+
timeout (Optional[float]): The amount of time, in seconds, to wait
958+
for the request to complete. Note that if ``retry`` is
959+
specified, the timeout applies to each individual attempt.
960+
metadata (Optional[Sequence[Tuple[str, str]]]): Additional metadata
961+
that is provided to the method.
962+
963+
Returns:
964+
A :class:`~google.api_core.page_iterator.PageIterator` instance.
965+
An iterable of :class:`~google.cloud.spanner_admin_database_v1.types.Database` instances.
966+
You can also iterate over the pages of the response
967+
using its `pages` property.
968+
969+
Raises:
970+
google.api_core.exceptions.GoogleAPICallError: If the request
971+
failed for any reason.
972+
google.api_core.exceptions.RetryError: If the request failed due
973+
to a retryable error and retry attempts failed.
974+
ValueError: If the parameters are invalid.
975+
"""
976+
# Wrap the transport method to add retry and timeout logic.
977+
if "list_databases" not in self._inner_api_calls:
978+
self._inner_api_calls[
979+
"list_databases"
980+
] = google.api_core.gapic_v1.method.wrap_method(
981+
self.transport.list_databases,
982+
default_retry=self._method_configs["ListDatabases"].retry,
983+
default_timeout=self._method_configs["ListDatabases"].timeout,
984+
client_info=self._client_info,
985+
)
986+
987+
request = spanner_database_admin_pb2.ListDatabasesRequest(
988+
parent=parent, page_size=page_size
989+
)
990+
if metadata is None:
991+
metadata = []
992+
metadata = list(metadata)
993+
try:
994+
routing_header = [("parent", parent)]
995+
except AttributeError:
996+
pass
997+
else:
998+
routing_metadata = google.api_core.gapic_v1.routing_header.to_grpc_metadata(
999+
routing_header
1000+
)
1001+
metadata.append(routing_metadata)
1002+
1003+
iterator = google.api_core.page_iterator.GRPCIterator(
1004+
client=None,
1005+
method=functools.partial(
1006+
self._inner_api_calls["list_databases"],
1007+
retry=retry,
1008+
timeout=timeout,
1009+
metadata=metadata,
1010+
),
1011+
request=request,
1012+
items_field="databases",
1013+
request_token_field="page_token",
1014+
response_token_field="next_page_token",
1015+
)
1016+
return iterator

spanner/google/cloud/spanner_admin_database_v1/gapic/database_admin_client_config.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
}
1818
},
1919
"methods": {
20-
"ListDatabases": {
21-
"timeout_millis": 30000,
22-
"retry_codes_name": "idempotent",
23-
"retry_params_name": "default",
24-
},
2520
"CreateDatabase": {
2621
"timeout_millis": 3600000,
2722
"retry_codes_name": "non_idempotent",
@@ -62,6 +57,11 @@
6257
"retry_codes_name": "non_idempotent",
6358
"retry_params_name": "default",
6459
},
60+
"ListDatabases": {
61+
"timeout_millis": 60000,
62+
"retry_codes_name": "idempotent",
63+
"retry_params_name": "default",
64+
},
6565
},
6666
}
6767
}

spanner/google/cloud/spanner_admin_database_v1/gapic/transports/database_admin_grpc_transport.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,6 @@ def channel(self):
120120
"""
121121
return self._channel
122122

123-
@property
124-
def list_databases(self):
125-
"""Return the gRPC stub for :meth:`DatabaseAdminClient.list_databases`.
126-
127-
Lists Cloud Spanner databases.
128-
129-
Returns:
130-
Callable: A callable which accepts the appropriate
131-
deserialized request object and returns a
132-
deserialized response object.
133-
"""
134-
return self._stubs["database_admin_stub"].ListDatabases
135-
136123
@property
137124
def create_database(self):
138125
"""Return the gRPC stub for :meth:`DatabaseAdminClient.create_database`.
@@ -262,3 +249,16 @@ def test_iam_permissions(self):
262249
deserialized response object.
263250
"""
264251
return self._stubs["database_admin_stub"].TestIamPermissions
252+
253+
@property
254+
def list_databases(self):
255+
"""Return the gRPC stub for :meth:`DatabaseAdminClient.list_databases`.
256+
257+
Lists Cloud Spanner databases.
258+
259+
Returns:
260+
Callable: A callable which accepts the appropriate
261+
deserialized request object and returns a
262+
deserialized response object.
263+
"""
264+
return self._stubs["database_admin_stub"].ListDatabases

0 commit comments

Comments
 (0)