Skip to content

Commit

Permalink
Merge branch 'main' into remove_custom_routing_metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-sanche committed Nov 7, 2024
2 parents 034e7d7 + a8286d2 commit 1b2be56
Show file tree
Hide file tree
Showing 22 changed files with 23,462 additions and 17,014 deletions.
14 changes: 12 additions & 2 deletions google/cloud/bigtable/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def get_encryption_info(self):
for cluster_id, value_pb in table_pb.cluster_states.items()
}

def read_row(self, row_key, filter_=None):
def read_row(self, row_key, filter_=None, retry=DEFAULT_RETRY_READ_ROWS):
"""Read a single row from this table.
For example:
Expand All @@ -550,6 +550,14 @@ def read_row(self, row_key, filter_=None):
:param filter_: (Optional) The filter to apply to the contents of the
row. If unset, returns the entire row.
:type retry: :class:`~google.api_core.retry.Retry`
:param retry:
(Optional) Retry delay and deadline arguments. To override, the
default value :attr:`DEFAULT_RETRY_READ_ROWS` can be used and
modified with the :meth:`~google.api_core.retry.Retry.with_delay`
method or the :meth:`~google.api_core.retry.Retry.with_deadline`
method.
:rtype: :class:`.PartialRowData`, :data:`NoneType <types.NoneType>`
:returns: The contents of the row if any chunks were returned in
the response, otherwise :data:`None`.
Expand All @@ -558,7 +566,9 @@ def read_row(self, row_key, filter_=None):
"""
row_set = RowSet()
row_set.add_row_key(row_key)
result_iter = iter(self.read_rows(filter_=filter_, row_set=row_set))
result_iter = iter(
self.read_rows(filter_=filter_, row_set=row_set, retry=retry)
)
row = next(result_iter, None)
if next(result_iter, None) is not None:
raise ValueError("More than one row was returned.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -586,36 +586,6 @@ def _get_universe_domain(
raise ValueError("Universe Domain cannot be an empty string.")
return universe_domain

@staticmethod
def _compare_universes(
client_universe: str, credentials: ga_credentials.Credentials
) -> bool:
"""Returns True iff the universe domains used by the client and credentials match.
Args:
client_universe (str): The universe domain configured via the client options.
credentials (ga_credentials.Credentials): The credentials being used in the client.
Returns:
bool: True iff client_universe matches the universe in credentials.
Raises:
ValueError: when client_universe does not match the universe in credentials.
"""

default_universe = BigtableInstanceAdminClient._DEFAULT_UNIVERSE
credentials_universe = getattr(credentials, "universe_domain", default_universe)

if client_universe != credentials_universe:
raise ValueError(
"The configured universe domain "
f"({client_universe}) does not match the universe domain "
f"found in the credentials ({credentials_universe}). "
"If you haven't configured the universe domain explicitly, "
f"`{default_universe}` is the default."
)
return True

def _validate_universe_domain(self):
"""Validates client's and credentials' universe domains are consistent.
Expand All @@ -625,13 +595,9 @@ def _validate_universe_domain(self):
Raises:
ValueError: If the configured universe domain is not valid.
"""
self._is_universe_domain_valid = (
self._is_universe_domain_valid
or BigtableInstanceAdminClient._compare_universes(
self.universe_domain, self.transport._credentials
)
)
return self._is_universe_domain_valid

# NOTE (b/349488459): universe validation is disabled until further notice.
return True

@property
def api_endpoint(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

transport inheritance structure
_______________________________

`BigtableInstanceAdminTransport` is the ABC for all transports.
- public child `BigtableInstanceAdminGrpcTransport` for sync gRPC transport (defined in `grpc.py`).
- public child `BigtableInstanceAdminGrpcAsyncIOTransport` for async gRPC transport (defined in `grpc_asyncio.py`).
- private child `_BaseBigtableInstanceAdminRestTransport` for base REST transport with inner classes `_BaseMETHOD` (defined in `rest_base.py`).
- public child `BigtableInstanceAdminRestTransport` for sync REST transport with inner classes `METHOD` derived from the parent's corresponding `_BaseMETHOD` classes (defined in `rest.py`).
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
import inspect
import warnings
from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union

Expand Down Expand Up @@ -237,6 +238,9 @@ def __init__(
)

# Wrap messages. This must be done after self._grpc_channel exists
self._wrap_with_kind = (
"kind" in inspect.signature(gapic_v1.method_async.wrap_method).parameters
)
self._prep_wrapped_messages(client_info)

@property
Expand Down Expand Up @@ -898,12 +902,12 @@ def list_hot_tablets(
def _prep_wrapped_messages(self, client_info):
"""Precompute the wrapped methods, overriding the base class method to use async wrappers."""
self._wrapped_methods = {
self.create_instance: gapic_v1.method_async.wrap_method(
self.create_instance: self._wrap_method(
self.create_instance,
default_timeout=300.0,
client_info=client_info,
),
self.get_instance: gapic_v1.method_async.wrap_method(
self.get_instance: self._wrap_method(
self.get_instance,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -918,7 +922,7 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.list_instances: gapic_v1.method_async.wrap_method(
self.list_instances: self._wrap_method(
self.list_instances,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -933,7 +937,7 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.update_instance: gapic_v1.method_async.wrap_method(
self.update_instance: self._wrap_method(
self.update_instance,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -948,7 +952,7 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.partial_update_instance: gapic_v1.method_async.wrap_method(
self.partial_update_instance: self._wrap_method(
self.partial_update_instance,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -963,17 +967,17 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.delete_instance: gapic_v1.method_async.wrap_method(
self.delete_instance: self._wrap_method(
self.delete_instance,
default_timeout=60.0,
client_info=client_info,
),
self.create_cluster: gapic_v1.method_async.wrap_method(
self.create_cluster: self._wrap_method(
self.create_cluster,
default_timeout=60.0,
client_info=client_info,
),
self.get_cluster: gapic_v1.method_async.wrap_method(
self.get_cluster: self._wrap_method(
self.get_cluster,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -988,7 +992,7 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.list_clusters: gapic_v1.method_async.wrap_method(
self.list_clusters: self._wrap_method(
self.list_clusters,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -1003,7 +1007,7 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.update_cluster: gapic_v1.method_async.wrap_method(
self.update_cluster: self._wrap_method(
self.update_cluster,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -1018,22 +1022,22 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.partial_update_cluster: gapic_v1.method_async.wrap_method(
self.partial_update_cluster: self._wrap_method(
self.partial_update_cluster,
default_timeout=None,
client_info=client_info,
),
self.delete_cluster: gapic_v1.method_async.wrap_method(
self.delete_cluster: self._wrap_method(
self.delete_cluster,
default_timeout=60.0,
client_info=client_info,
),
self.create_app_profile: gapic_v1.method_async.wrap_method(
self.create_app_profile: self._wrap_method(
self.create_app_profile,
default_timeout=60.0,
client_info=client_info,
),
self.get_app_profile: gapic_v1.method_async.wrap_method(
self.get_app_profile: self._wrap_method(
self.get_app_profile,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -1048,7 +1052,7 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.list_app_profiles: gapic_v1.method_async.wrap_method(
self.list_app_profiles: self._wrap_method(
self.list_app_profiles,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -1063,7 +1067,7 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.update_app_profile: gapic_v1.method_async.wrap_method(
self.update_app_profile: self._wrap_method(
self.update_app_profile,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -1078,12 +1082,12 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.delete_app_profile: gapic_v1.method_async.wrap_method(
self.delete_app_profile: self._wrap_method(
self.delete_app_profile,
default_timeout=60.0,
client_info=client_info,
),
self.get_iam_policy: gapic_v1.method_async.wrap_method(
self.get_iam_policy: self._wrap_method(
self.get_iam_policy,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -1098,12 +1102,12 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.set_iam_policy: gapic_v1.method_async.wrap_method(
self.set_iam_policy: self._wrap_method(
self.set_iam_policy,
default_timeout=60.0,
client_info=client_info,
),
self.test_iam_permissions: gapic_v1.method_async.wrap_method(
self.test_iam_permissions: self._wrap_method(
self.test_iam_permissions,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -1118,7 +1122,7 @@ def _prep_wrapped_messages(self, client_info):
default_timeout=60.0,
client_info=client_info,
),
self.list_hot_tablets: gapic_v1.method_async.wrap_method(
self.list_hot_tablets: self._wrap_method(
self.list_hot_tablets,
default_retry=retries.AsyncRetry(
initial=1.0,
Expand All @@ -1135,8 +1139,17 @@ def _prep_wrapped_messages(self, client_info):
),
}

def _wrap_method(self, func, *args, **kwargs):
if self._wrap_with_kind: # pragma: NO COVER
kwargs["kind"] = self.kind
return gapic_v1.method_async.wrap_method(func, *args, **kwargs)

def close(self):
return self.grpc_channel.close()

@property
def kind(self) -> str:
return "grpc_asyncio"


__all__ = ("BigtableInstanceAdminGrpcAsyncIOTransport",)
Loading

0 comments on commit 1b2be56

Please sign in to comment.