Skip to content

Commit 32c0ca7

Browse files
authored
Merge pull request #2642 from dhermes/register-type-optional
Make type_url optional when registering types.
2 parents 1c4526c + 58b8440 commit 32c0ca7

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

packages/google-cloud-bigtable/google/cloud/bigtable/cluster.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@
2222
from google.cloud.bigtable._generated import (
2323
bigtable_instance_admin_pb2 as messages_v2_pb2)
2424
from google.cloud.operation import Operation
25-
from google.cloud.operation import _compute_type_url
26-
from google.cloud.operation import register_type_url
25+
from google.cloud.operation import register_type
2726

2827

2928
_CLUSTER_NAME_RE = re.compile(r'^projects/(?P<project>[^/]+)/'
@@ -34,10 +33,7 @@
3433
"""Default number of nodes to use when creating a cluster."""
3534

3635

37-
_UPDATE_CLUSTER_METADATA_URL = _compute_type_url(
38-
messages_v2_pb2.UpdateClusterMetadata)
39-
register_type_url(
40-
_UPDATE_CLUSTER_METADATA_URL, messages_v2_pb2.UpdateClusterMetadata)
36+
register_type(messages_v2_pb2.UpdateClusterMetadata)
4137

4238

4339
def _prepare_create_request(cluster):

packages/google-cloud-bigtable/google/cloud/bigtable/instance.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,16 @@
2727
from google.cloud.bigtable.cluster import DEFAULT_SERVE_NODES
2828
from google.cloud.bigtable.table import Table
2929
from google.cloud.operation import Operation
30-
from google.cloud.operation import _compute_type_url
31-
from google.cloud.operation import register_type_url
30+
from google.cloud.operation import register_type
3231

3332

3433
_EXISTING_INSTANCE_LOCATION_ID = 'see-existing-cluster'
3534
_INSTANCE_NAME_RE = re.compile(r'^projects/(?P<project>[^/]+)/'
3635
r'instances/(?P<instance_id>[a-z][-a-z0-9]*)$')
3736

3837

39-
_CREATE_INSTANCE_METADATA_URL = _compute_type_url(
40-
messages_v2_pb2.CreateInstanceMetadata)
41-
register_type_url(
42-
_CREATE_INSTANCE_METADATA_URL, messages_v2_pb2.CreateInstanceMetadata)
43-
_INSTANCE_METADATA_URL = _compute_type_url(data_v2_pb2.Instance)
44-
register_type_url(_INSTANCE_METADATA_URL, data_v2_pb2.Instance)
38+
register_type(messages_v2_pb2.CreateInstanceMetadata)
39+
register_type(data_v2_pb2.Instance)
4540

4641

4742
def _prepare_create_request(instance):

packages/google-cloud-bigtable/unit_tests/test_cluster.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,6 @@ def test_update(self):
283283
from google.cloud.bigtable._generated import (
284284
bigtable_instance_admin_pb2 as messages_v2_pb2)
285285
from unit_tests._testing import _FakeStub
286-
from google.cloud.bigtable.cluster import _UPDATE_CLUSTER_METADATA_URL
287286

288287
NOW = datetime.datetime.utcnow()
289288
NOW_PB = _datetime_to_pb_timestamp(NOW)
@@ -307,10 +306,12 @@ def test_update(self):
307306
'operations/projects/%s/instances/%s/clusters/%s/operations/%d' %
308307
(self.PROJECT, self.INSTANCE_ID, self.CLUSTER_ID, OP_ID))
309308
metadata = messages_v2_pb2.UpdateClusterMetadata(request_time=NOW_PB)
309+
type_url = 'type.googleapis.com/%s' % (
310+
messages_v2_pb2.UpdateClusterMetadata.DESCRIPTOR.full_name,)
310311
response_pb = operations_pb2.Operation(
311312
name=OP_NAME,
312313
metadata=Any(
313-
type_url=_UPDATE_CLUSTER_METADATA_URL,
314+
type_url=type_url,
314315
value=metadata.SerializeToString()
315316
)
316317
)

packages/google-cloud-bigtable/unit_tests/test_instance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@ def test_create(self):
236236
from unit_tests._testing import _FakeStub
237237
from google.cloud.operation import Operation
238238
from google.cloud.bigtable.cluster import DEFAULT_SERVE_NODES
239-
from google.cloud.bigtable.instance import (
240-
_CREATE_INSTANCE_METADATA_URL)
241239

242240
NOW = datetime.datetime.utcnow()
243241
NOW_PB = _datetime_to_pb_timestamp(NOW)
@@ -247,10 +245,12 @@ def test_create(self):
247245

248246
# Create response_pb
249247
metadata = messages_v2_pb2.CreateInstanceMetadata(request_time=NOW_PB)
248+
type_url = 'type.googleapis.com/%s' % (
249+
messages_v2_pb2.CreateInstanceMetadata.DESCRIPTOR.full_name,)
250250
response_pb = operations_pb2.Operation(
251251
name=self.OP_NAME,
252252
metadata=Any(
253-
type_url=_CREATE_INSTANCE_METADATA_URL,
253+
type_url=type_url,
254254
value=metadata.SerializeToString(),
255255
)
256256
)

0 commit comments

Comments
 (0)