Skip to content

Commit

Permalink
Upgrading Bigtable package to use gRPC beta.
Browse files Browse the repository at this point in the history
  • Loading branch information
dhermes committed Nov 25, 2015
1 parent 4ad2926 commit 1523be4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
2 changes: 1 addition & 1 deletion gcloud/bigtable/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def make_stub(client, stub_factory, host, port):
:type port: int
:param port: The port for the service.
:rtype: :class:`grpc.early_adopter.implementations._Stub`
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
:returns: The stub object used to make gRPC requests to a given API.
"""
custom_metadata_transformer = MetadataTransformer(client)
Expand Down
26 changes: 12 additions & 14 deletions gcloud/bigtable/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def project_name(self):
def _data_stub(self):
"""Getter for the gRPC stub used for the Data API.
:rtype: :class:`grpc.early_adopter.implementations._Stub`
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
:returns: A gRPC stub object.
:raises: :class:`ValueError <exceptions.ValueError>` if the current
client has not been :meth:`start`-ed.
Expand All @@ -220,7 +220,7 @@ def _data_stub(self):
def _cluster_stub(self):
"""Getter for the gRPC stub used for the Cluster Admin API.
:rtype: :class:`grpc.early_adopter.implementations._Stub`
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
:returns: A gRPC stub object.
:raises: :class:`ValueError <exceptions.ValueError>` if the current
client is not an admin client or if it has not been
Expand All @@ -236,7 +236,7 @@ def _cluster_stub(self):
def _operations_stub(self):
"""Getter for the gRPC stub used for the Operations API.
:rtype: :class:`grpc.early_adopter.implementations._Stub`
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
:returns: A gRPC stub object.
:raises: :class:`ValueError <exceptions.ValueError>` if the current
client is not an admin client or if it has not been
Expand All @@ -252,7 +252,7 @@ def _operations_stub(self):
def _table_stub(self):
"""Getter for the gRPC stub used for the Table Admin API.
:rtype: :class:`grpc.early_adopter.implementations._Stub`
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
:returns: A gRPC stub object.
:raises: :class:`ValueError <exceptions.ValueError>` if the current
client is not an admin client or if it has not been
Expand All @@ -267,7 +267,7 @@ def _table_stub(self):
def _make_data_stub(self):
"""Creates gRPC stub to make requests to the Data API.
:rtype: :class:`grpc.early_adopter.implementations._Stub`
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
:returns: A gRPC stub object.
"""
return make_stub(self, DATA_STUB_FACTORY,
Expand All @@ -276,7 +276,7 @@ def _make_data_stub(self):
def _make_cluster_stub(self):
"""Creates gRPC stub to make requests to the Cluster Admin API.
:rtype: :class:`grpc.early_adopter.implementations._Stub`
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
:returns: A gRPC stub object.
"""
return make_stub(self, CLUSTER_STUB_FACTORY,
Expand All @@ -288,7 +288,7 @@ def _make_operations_stub(self):
These are for long-running operations of the Cluster Admin API,
hence the host and port matching.
:rtype: :class:`grpc.early_adopter.implementations._Stub`
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
:returns: A gRPC stub object.
"""
return make_stub(self, OPERATIONS_STUB_FACTORY,
Expand All @@ -297,7 +297,7 @@ def _make_operations_stub(self):
def _make_table_stub(self):
"""Creates gRPC stub to make requests to the Table Admin API.
:rtype: :class:`grpc.early_adopter.implementations._Stub`
:rtype: :class:`grpc.beta._stub._AutoIntermediary`
:returns: A gRPC stub object.
"""
return make_stub(self, TABLE_STUB_FACTORY,
Expand Down Expand Up @@ -388,10 +388,9 @@ def list_zones(self):
zones is not in ``OK`` state.
"""
request_pb = messages_pb2.ListZonesRequest(name=self.project_name)
response = self._cluster_stub.ListZones.async(request_pb,
self.timeout_seconds)
# We expect a `.messages_pb2.ListZonesResponse`
list_zones_response = response.result()
list_zones_response = self._cluster_stub.ListZones(
request_pb, self.timeout_seconds)

result = []
for zone in list_zones_response.zones:
Expand All @@ -410,10 +409,9 @@ def list_clusters(self):
zones in the request).
"""
request_pb = messages_pb2.ListClustersRequest(name=self.project_name)
response = self._cluster_stub.ListClusters.async(request_pb,
self.timeout_seconds)
# We expect a `.messages_pb2.ListClustersResponse`
list_clusters_response = response.result()
list_clusters_response = self._cluster_stub.ListClusters(
request_pb, self.timeout_seconds)

failed_zones = [zone.display_name
for zone in list_clusters_response.failed_zones]
Expand Down
27 changes: 8 additions & 19 deletions gcloud/bigtable/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,30 +651,19 @@ def __getattr__(self, name):


class _MethodMock(object):
"""Mock for :class:`grpc.framework.alpha._reexport._UnaryUnarySyncAsync`.
"""Mock for API method attached to a gRPC stub.
May need to be callable and needs to (in our use) have an
``async`` method.
In the beta implementation, these are of type.
:class:`grpc.framework.crust.implementations._UnaryUnaryMultiCallable`
"""

def __init__(self, name, factory):
self._name = name
self._factory = factory

def async(self, *args, **kwargs):
"""Async method meant to mock a gRPC stub request."""
def __call__(self, *args, **kwargs):
"""Sync method meant to mock a gRPC stub request."""
self._factory.method_calls.append((self._name, args, kwargs))
curr_result, self._factory.results = (self._factory.results[0],
self._factory.results[1:])
return _AsyncResult(curr_result)


class _AsyncResult(object):
"""Result returned from a ``_MethodMock.async`` call."""

def __init__(self, result):
self._result = result

def result(self):
"""Result method on an asyc object."""
return self._result
curr_result = self._factory.results[0]
self._factory.results = self._factory.results[1:]
return curr_result

0 comments on commit 1523be4

Please sign in to comment.