Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit b31bd87

Browse files
authored
feat!: microgenerator changes (#203)
Release-As: v2.0.0-dev1 * wip microgenerator changes * fix unit tests * fix system tests * lint * fixup after update * fix test * regen * run fixup script * run fixup script admin * add scripts to build * regenerate * update synth * fix tests * more test cleanup * fix mutate rows * fix backups test * fix tests * fix docs and lint * fix docs and lint * temporarily put coverage at 99 * code feedback * move coverage to 99 * pin beam bigtable deps to 1.0.0 * pin beam bigtable deps to 1.0.0 * fix imports * fixup keepalive config * lint * cleanup * cleanup * cleanup
1 parent 905f644 commit b31bd87

134 files changed

Lines changed: 36477 additions & 29436 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.coveragerc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ omit =
2121
google/cloud/__init__.py
2222

2323
[report]
24-
fail_under = 100
24+
fail_under = 99
2525
show_missing = True
2626
exclude_lines =
2727
# Re-enable the standard pragma
@@ -30,6 +30,8 @@ exclude_lines =
3030
def __repr__
3131
# Ignore abstract methods
3232
raise NotImplementedError
33+
# Ignore setuptools-less fallback
34+
except pkg_resources.DistributionNotFound:
3335
omit =
3436
*/gapic/*.py
3537
*/proto/*.py

docs/conf.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,7 @@
347347
intersphinx_mapping = {
348348
"python": ("https://python.readthedocs.org/en/latest/", None),
349349
"google-auth": ("https://googleapis.dev/python/google-auth/latest/", None),
350-
"google.api_core": (
351-
"https://googleapis.dev/python/google-api-core/latest/",
352-
None,
353-
),
350+
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
354351
"grpc": ("https://grpc.github.io/grpc/python/", None),
355352
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
356353
}

docs/snippets.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,13 @@ def test_bigtable_cluster_name():
704704
def test_bigtable_instance_from_pb():
705705
# [START bigtable_api_instance_from_pb]
706706
from google.cloud.bigtable import Client
707-
from google.cloud.bigtable_admin_v2.types import instance_pb2
707+
from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
708708

709709
client = Client(admin=True)
710710
instance = client.instance(INSTANCE_ID)
711711

712712
name = instance.name
713-
instance_pb = instance_pb2.Instance(
713+
instance_pb = data_v2_pb2.Instance(
714714
name=name, display_name=INSTANCE_ID, type=PRODUCTION, labels=LABELS
715715
)
716716

@@ -723,7 +723,7 @@ def test_bigtable_instance_from_pb():
723723
def test_bigtable_cluster_from_pb():
724724
# [START bigtable_api_cluster_from_pb]
725725
from google.cloud.bigtable import Client
726-
from google.cloud.bigtable_admin_v2.types import instance_pb2
726+
from google.cloud.bigtable_admin_v2.types import instance as data_v2_pb2
727727

728728
client = Client(admin=True)
729729
instance = client.instance(INSTANCE_ID)
@@ -732,7 +732,7 @@ def test_bigtable_cluster_from_pb():
732732
name = cluster.name
733733
cluster_state = cluster.state
734734
serve_nodes = 1
735-
cluster_pb = instance_pb2.Cluster(
735+
cluster_pb = data_v2_pb2.Cluster(
736736
name=name,
737737
location=LOCATION_ID,
738738
state=cluster_state,

google/cloud/bigtable/app_profile.py

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import re
1919

2020
from google.cloud.bigtable.enums import RoutingPolicyType
21-
from google.cloud.bigtable_admin_v2.types import instance_pb2
21+
from google.cloud.bigtable_admin_v2.types import instance
2222
from google.protobuf import field_mask_pb2
2323
from google.api_core.exceptions import NotFound
2424

@@ -138,7 +138,7 @@ def __ne__(self, other):
138138
def from_pb(cls, app_profile_pb, instance):
139139
"""Creates an instance app_profile from a protobuf.
140140
141-
:type app_profile_pb: :class:`instance_pb2.app_profile_pb`
141+
:type app_profile_pb: :class:`instance.app_profile_pb`
142142
:param app_profile_pb: An instance protobuf object.
143143
144144
:type instance: :class:`google.cloud.bigtable.instance.Instance`
@@ -188,7 +188,7 @@ def _update_from_pb(self, app_profile_pb):
188188
self.description = app_profile_pb.description
189189

190190
routing_policy_type = None
191-
if app_profile_pb.HasField("multi_cluster_routing_use_any"):
191+
if app_profile_pb._pb.HasField("multi_cluster_routing_use_any"):
192192
routing_policy_type = RoutingPolicyType.ANY
193193
self.allow_transactional_writes = False
194194
else:
@@ -201,7 +201,7 @@ def _update_from_pb(self, app_profile_pb):
201201

202202
def _to_pb(self):
203203
"""Create an AppProfile proto buff message for API calls
204-
:rtype: :class:`.instance_pb2.AppProfile`
204+
:rtype: :class:`.instance.AppProfile`
205205
:returns: The converted current object.
206206
207207
:raises: :class:`ValueError <exceptions.ValueError>` if the AppProfile
@@ -215,15 +215,15 @@ def _to_pb(self):
215215

216216
if self.routing_policy_type == RoutingPolicyType.ANY:
217217
multi_cluster_routing_use_any = (
218-
instance_pb2.AppProfile.MultiClusterRoutingUseAny()
218+
instance.AppProfile.MultiClusterRoutingUseAny()
219219
)
220220
else:
221-
single_cluster_routing = instance_pb2.AppProfile.SingleClusterRouting(
221+
single_cluster_routing = instance.AppProfile.SingleClusterRouting(
222222
cluster_id=self.cluster_id,
223223
allow_transactional_writes=self.allow_transactional_writes,
224224
)
225225

226-
app_profile_pb = instance_pb2.AppProfile(
226+
app_profile_pb = instance.AppProfile(
227227
name=self.name,
228228
description=self.description,
229229
multi_cluster_routing_use_any=multi_cluster_routing_use_any,
@@ -242,7 +242,9 @@ def reload(self):
242242
:dedent: 4
243243
"""
244244

245-
app_profile_pb = self.instance_admin_client.get_app_profile(self.name)
245+
app_profile_pb = self.instance_admin_client.get_app_profile(
246+
request={"name": self.name}
247+
)
246248

247249
# NOTE: _update_from_pb does not check that the project and
248250
# app_profile ID on the response match the request.
@@ -262,7 +264,7 @@ def exists(self):
262264
:returns: True if the AppProfile exists, else False.
263265
"""
264266
try:
265-
self.instance_admin_client.get_app_profile(self.name)
267+
self.instance_admin_client.get_app_profile(request={"name": self.name})
266268
return True
267269
# NOTE: There could be other exceptions that are returned to the user.
268270
except NotFound:
@@ -291,10 +293,12 @@ def create(self, ignore_warnings=None):
291293
"""
292294
return self.from_pb(
293295
self.instance_admin_client.create_app_profile(
294-
parent=self._instance.name,
295-
app_profile_id=self.app_profile_id,
296-
app_profile=self._to_pb(),
297-
ignore_warnings=ignore_warnings,
296+
request={
297+
"parent": self._instance.name,
298+
"app_profile_id": self.app_profile_id,
299+
"app_profile": self._to_pb(),
300+
"ignore_warnings": ignore_warnings,
301+
}
298302
),
299303
self._instance,
300304
)
@@ -328,9 +332,11 @@ def update(self, ignore_warnings=None):
328332
update_mask_pb.paths.append("single_cluster_routing")
329333

330334
return self.instance_admin_client.update_app_profile(
331-
app_profile=self._to_pb(),
332-
update_mask=update_mask_pb,
333-
ignore_warnings=ignore_warnings,
335+
request={
336+
"app_profile": self._to_pb(),
337+
"update_mask": update_mask_pb,
338+
"ignore_warnings": ignore_warnings,
339+
}
334340
)
335341

336342
def delete(self, ignore_warnings=None):
@@ -352,4 +358,6 @@ def delete(self, ignore_warnings=None):
352358
If the request failed due to a retryable error and retry
353359
attempts failed. ValueError: If the parameters are invalid.
354360
"""
355-
self.instance_admin_client.delete_app_profile(self.name, ignore_warnings)
361+
self.instance_admin_client.delete_app_profile(
362+
request={"name": self.name, "ignore_warnings": ignore_warnings}
363+
)

google/cloud/bigtable/backup.py

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@
1717
import re
1818

1919
from google.cloud._helpers import _datetime_to_pb_timestamp
20-
from google.cloud.bigtable_admin_v2.gapic.bigtable_table_admin_client import (
21-
BigtableTableAdminClient,
22-
)
23-
from google.cloud.bigtable_admin_v2.types import table_pb2
20+
from google.cloud.bigtable_admin_v2 import BigtableTableAdminClient
21+
from google.cloud.bigtable_admin_v2.types import table
2422
from google.cloud.bigtable.policy import Policy
2523
from google.cloud.exceptions import NotFound
2624
from google.protobuf import field_mask_pb2
@@ -220,7 +218,7 @@ def state(self):
220218
def from_pb(cls, backup_pb, instance):
221219
"""Creates a Backup instance from a protobuf message.
222220
223-
:type backup_pb: :class:`table_pb2.Backup`
221+
:type backup_pb: :class:`table.Backup`
224222
:param backup_pb: A Backup protobuf object.
225223
226224
:type instance: :class:`Instance <google.cloud.bigtable.instance.Instance>`
@@ -256,7 +254,7 @@ def from_pb(cls, backup_pb, instance):
256254
match = _TABLE_NAME_RE.match(backup_pb.source_table)
257255
table_id = match.group("table_id") if match else None
258256

259-
expire_time = backup_pb.expire_time
257+
expire_time = backup_pb._pb.expire_time
260258

261259
backup = cls(
262260
backup_id,
@@ -265,10 +263,10 @@ def from_pb(cls, backup_pb, instance):
265263
table_id=table_id,
266264
expire_time=expire_time,
267265
)
268-
backup._start_time = backup_pb.start_time
269-
backup._end_time = backup_pb.end_time
270-
backup._size_bytes = backup_pb.size_bytes
271-
backup._state = backup_pb.state
266+
backup._start_time = backup_pb._pb.start_time
267+
backup._end_time = backup_pb._pb.end_time
268+
backup._size_bytes = backup_pb._pb.size_bytes
269+
backup._state = backup_pb._pb.state
272270

273271
return backup
274272

@@ -308,13 +306,19 @@ def create(self, cluster_id=None):
308306
if not self._cluster:
309307
raise ValueError('"cluster" parameter must be set')
310308

311-
backup = table_pb2.Backup(
309+
backup = table.Backup(
312310
source_table=self.source_table,
313311
expire_time=_datetime_to_pb_timestamp(self.expire_time),
314312
)
315313

316-
api = self._instance._client.table_admin_client
317-
return api.create_backup(self.parent, self.backup_id, backup)
314+
api = self._instance._client._table_admin_client
315+
return api.create_backup(
316+
request={
317+
"parent": self.parent,
318+
"backup_id": self.backup_id,
319+
"backup": backup,
320+
}
321+
)
318322

319323
def get(self):
320324
"""Retrieves metadata of a pending or completed Backup.
@@ -328,21 +332,21 @@ def get(self):
328332
due to a retryable error and retry attempts failed.
329333
:raises ValueError: If the parameters are invalid.
330334
"""
331-
api = self._instance._client.table_admin_client
335+
api = self._instance._client._table_admin_client
332336
try:
333-
return api.get_backup(self.name)
337+
return api.get_backup(request={"name": self.name})
334338
except NotFound:
335339
return None
336340

337341
def reload(self):
338342
"""Refreshes the stored backup properties."""
339343
backup = self.get()
340344
self._source_table = backup.source_table
341-
self._expire_time = backup.expire_time
342-
self._start_time = backup.start_time
343-
self._end_time = backup.end_time
344-
self._size_bytes = backup.size_bytes
345-
self._state = backup.state
345+
self._expire_time = backup._pb.expire_time
346+
self._start_time = backup._pb.start_time
347+
self._end_time = backup._pb.end_time
348+
self._size_bytes = backup._pb.size_bytes
349+
self._state = backup._pb.state
346350

347351
def exists(self):
348352
"""Tests whether this Backup exists.
@@ -358,18 +362,19 @@ def update_expire_time(self, new_expire_time):
358362
:type new_expire_time: :class:`datetime.datetime`
359363
:param new_expire_time: the new expiration time timestamp
360364
"""
361-
backup_update = table_pb2.Backup(
362-
name=self.name,
363-
expire_time=_datetime_to_pb_timestamp(new_expire_time),
365+
backup_update = table.Backup(
366+
name=self.name, expire_time=_datetime_to_pb_timestamp(new_expire_time),
364367
)
365368
update_mask = field_mask_pb2.FieldMask(paths=["expire_time"])
366-
api = self._instance._client.table_admin_client
367-
api.update_backup(backup_update, update_mask)
369+
api = self._instance._client._table_admin_client
370+
api.update_backup(request={"backup": backup_update, "update_mask": update_mask})
368371
self._expire_time = new_expire_time
369372

370373
def delete(self):
371374
"""Delete this Backup."""
372-
self._instance._client.table_admin_client.delete_backup(self.name)
375+
self._instance._client._table_admin_client.delete_backup(
376+
request={"name": self.name}
377+
)
373378

374379
def restore(self, table_id):
375380
"""Creates a new Table by restoring from this Backup. The new Table
@@ -391,8 +396,14 @@ def restore(self, table_id):
391396
due to a retryable error and retry attempts failed.
392397
:raises: ValueError: If the parameters are invalid.
393398
"""
394-
api = self._instance._client.table_admin_client
395-
return api.restore_table(self._instance.name, table_id, self.name)
399+
api = self._instance._client._table_admin_client
400+
return api.restore_table(
401+
request={
402+
"parent": self._instance.name,
403+
"table_id": table_id,
404+
"backup": self.name,
405+
}
406+
)
396407

397408
def get_iam_policy(self):
398409
"""Gets the IAM access control policy for this backup.
@@ -401,8 +412,7 @@ def get_iam_policy(self):
401412
:returns: The current IAM policy of this backup.
402413
"""
403414
table_api = self._instance._client.table_admin_client
404-
args = {"resource": self.name}
405-
response = table_api.get_iam_policy(**args)
415+
response = table_api.get_iam_policy(request={"resource": self.name})
406416
return Policy.from_pb(response)
407417

408418
def set_iam_policy(self, policy):
@@ -420,7 +430,9 @@ class `google.cloud.bigtable.policy.Policy`
420430
:returns: The current IAM policy of this backup.
421431
"""
422432
table_api = self._instance._client.table_admin_client
423-
response = table_api.set_iam_policy(resource=self.name, policy=policy.to_pb())
433+
response = table_api.set_iam_policy(
434+
request={"resource": self.name, "policy": policy.to_pb()}
435+
)
424436
return Policy.from_pb(response)
425437

426438
def test_iam_permissions(self, permissions):
@@ -441,6 +453,6 @@ def test_iam_permissions(self, permissions):
441453
"""
442454
table_api = self._instance._client.table_admin_client
443455
response = table_api.test_iam_permissions(
444-
resource=self.name, permissions=permissions
456+
request={"resource": self.name, "permissions": permissions}
445457
)
446458
return list(response.permissions)

0 commit comments

Comments
 (0)