forked from googleapis/google-cloud-python
- Notifications
You must be signed in to change notification settings - Fork 0
Bigtable: Add transport as wrapper for channel#2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sangramql
wants to merge
2
commits into
masterChoose a base branch
from
bigtable_client_implement_transport
base:master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Uh oh!
There was an error while loading. Please reload this page.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -35,6 +35,11 @@ | ||
| from google.cloud import bigtable_v2 | ||
| from google.cloud import bigtable_admin_v2 | ||
| from google.cloud.bigtable_v2.gapic.transports import bigtable_grpc_transport | ||
| from google.cloud.bigtable_admin_v2.gapic.transports import ( | ||
| bigtable_instance_admin_grpc_transport, | ||
| bigtable_table_admin_grpc_transport, | ||
| ) | ||
| from google.cloud.bigtable import __version__ | ||
| from google.cloud.bigtable.instance import Instance | ||
| @@ -61,11 +66,29 @@ | ||
| def _create_gapic_client(client_class): | ||
| def inner(self): | ||
| def inner(self, transport_class=None): | ||
| if self._emulator_host is None: | ||
| return client_class( | ||
| credentials=self._credentials, client_info=self._client_info | ||
| ) | ||
| if transport_class is not None: | ||
| if self._channel is not None: | ||
| # Use transport with channel | ||
| transport_obj = _transport( | ||
| channel=self._channel, default_class=transport_class | ||
| ) | ||
| return client_class( | ||
| transport=transport_obj, client_info=self._client_info | ||
| ) | ||
| else: | ||
| # Use transport as pointer to function with credentials | ||
| return client_class( | ||
| transport=_transport, | ||
| credentials=self._credentials, | ||
| client_info=self._client_info, | ||
| ) | ||
| else: | ||
| # Use credentials | ||
| return client_class( | ||
| credentials=self._credentials, client_info=self._client_info | ||
| ) | ||
| else: | ||
| return client_class( | ||
| channel=self._emulator_channel, client_info=self._client_info | ||
| @@ -74,6 +97,29 @@ def inner(self): | ||
| return inner | ||
| def _transport(channel=None, credentials=None, default_class=None): | ||
| """ Returns a object for gRPC class passed in argument default_class. | ||
| Args: | ||
| channel (grpc.Channel): A ``Channel`` instance through | ||
| which to make calls. If not passed, it's None. | ||
| credentials (google.auth.credentials.Credentials): The | ||
| authorization credentials to attach to requests. These | ||
| credentials identify this application to the service. If not passed, it's None. | ||
| default_class (GrpcTransport): A transport | ||
| instance, responsible for actually making the API calls. | ||
| The default transport uses the gRPC protocol.. Defaults to None. | ||
| """ | ||
| if default_class is not None: | ||
| if channel is not None: | ||
| return default_class(channel=channel) | ||
| elif credentials is not None: | ||
| return default_class(credentials=credentials) | ||
| return None | ||
sangramql marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| class Client(ClientWithProject): | ||
| """Client for interacting with Google Cloud Bigtable API. | ||
| @@ -122,6 +168,8 @@ class Client(ClientWithProject): | ||
| _table_data_client = None | ||
| _table_admin_client = None | ||
| _instance_admin_client = None | ||
| _admin_transport = None | ||
| _data_transport = None | ||
| def __init__( | ||
| self, | ||
| @@ -140,6 +188,7 @@ def __init__( | ||
| # NOTE: We set the scopes **before** calling the parent constructor. | ||
| # It **may** use those scopes in ``with_scopes_if_required``. | ||
| self._read_only = bool(read_only) | ||
| self._credentials = credentials | ||
| self._admin = bool(admin) | ||
| self._client_info = client_info | ||
| self._emulator_host = os.getenv(BIGTABLE_EMULATOR) | ||
| @@ -213,8 +262,13 @@ def table_data_client(self): | ||
| :returns: A BigtableClient object. | ||
| """ | ||
| if self._table_data_client is None: | ||
| if self._data_transport is not None: | ||
| transport_class = bigtable_grpc_transport.BigtableGrpcTransport | ||
| else: | ||
| transport_class = None | ||
| self._table_data_client = _create_gapic_client(bigtable_v2.BigtableClient)( | ||
| self | ||
| self, transport_class=transport_class | ||
| ) | ||
| return self._table_data_client | ||
| @@ -237,9 +291,16 @@ def table_admin_client(self): | ||
| if self._table_admin_client is None: | ||
| if not self._admin: | ||
| raise ValueError("Client is not an admin client.") | ||
| if self._admin_transport is not None: | ||
| transport_class = ( | ||
| bigtable_table_admin_grpc_transport.BigtableTableAdminGrpcTransport | ||
| ) | ||
| else: | ||
| transport_class = None | ||
| self._table_admin_client = _create_gapic_client( | ||
| bigtable_admin_v2.BigtableTableAdminClient | ||
| )(self) | ||
| )(self, transport_class=transport_class) | ||
| return self._table_admin_client | ||
| @property | ||
| @@ -261,11 +322,35 @@ def instance_admin_client(self): | ||
| if self._instance_admin_client is None: | ||
| if not self._admin: | ||
| raise ValueError("Client is not an admin client.") | ||
| if self._admin_transport is not None: | ||
| transport_class = ( | ||
| bigtable_instance_admin_grpc_transport.BigtableInstanceAdminGrpcTransport | ||
| ) | ||
| else: | ||
| transport_class = None | ||
| self._instance_admin_client = _create_gapic_client( | ||
| bigtable_admin_v2.BigtableInstanceAdminClient | ||
| )(self) | ||
| )(self, transport_class=transport_class) | ||
| return self._instance_admin_client | ||
| def data_transport(self, channel=None): | ||
| if self._data_transport is None: | ||
| self._data_transport = _transport | ||
| self._channel = channel | ||
| return self._data_transport | ||
| def admin_transport(self, channel=None): | ||
| if self._admin_transport is None: | ||
| if not self._admin: | ||
| raise ValueError("Client is not an admin client.") | ||
| self._admin_transport = _transport | ||
| self._channel = channel | ||
| return self._admin_transport | ||
| def instance(self, instance_id, display_name=None, instance_type=None, labels=None): | ||
| """Factory to create a instance associated with this client. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.