Navigation Menu

Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Commit

Permalink
feat: add context manager support in client (#83)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

chore: fix docstring for first attribute of protos

committer: @busunkim96
PiperOrigin-RevId: 401271153

Source-Link: googleapis/googleapis@787f8c9

Source-Link: googleapis/googleapis-gen@81decff
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
  • Loading branch information
gcf-owl-bot[bot] committed Oct 8, 2021
1 parent 9162f27 commit d6b8569
Show file tree
Hide file tree
Showing 21 changed files with 294 additions and 15 deletions.
Expand Up @@ -1547,6 +1547,12 @@ async def delete_backup(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
18 changes: 14 additions & 4 deletions google/cloud/metastore_v1/services/dataproc_metastore/client.py
Expand Up @@ -425,10 +425,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def list_services(
Expand Down Expand Up @@ -1783,6 +1780,19 @@ def delete_backup(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -207,6 +207,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
Expand Down
Expand Up @@ -655,5 +655,8 @@ def delete_backup(
)
return self._stubs["delete_backup"]

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


__all__ = ("DataprocMetastoreGrpcTransport",)
Expand Up @@ -685,5 +685,8 @@ def delete_backup(
)
return self._stubs["delete_backup"]

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


__all__ = ("DataprocMetastoreGrpcAsyncIOTransport",)
14 changes: 13 additions & 1 deletion google/cloud/metastore_v1/types/metastore.py
Expand Up @@ -61,6 +61,7 @@

class Service(proto.Message):
r"""A managed metastore service that serves metadata queries.
Attributes:
hive_metastore_config (google.cloud.metastore_v1.types.HiveMetastoreConfig):
Configuration information specific to running
Expand Down Expand Up @@ -219,6 +220,7 @@ class HiveMetastoreConfig(proto.Message):

class KerberosConfig(proto.Message):
r"""Configuration information for a Kerberos principal.
Attributes:
keytab (google.cloud.metastore_v1.types.Secret):
A Kerberos keytab file that can be used to
Expand All @@ -242,6 +244,7 @@ class KerberosConfig(proto.Message):

class Secret(proto.Message):
r"""A securely stored value.
Attributes:
cloud_secret (str):
The relative resource name of a Secret Manager secret
Expand All @@ -255,6 +258,7 @@ class Secret(proto.Message):

class MetadataManagementActivity(proto.Message):
r"""The metadata management activities of the metastore service.
Attributes:
metadata_exports (Sequence[google.cloud.metastore_v1.types.MetadataExport]):
Output only. The latest metadata exports of
Expand All @@ -272,6 +276,7 @@ class MetadataManagementActivity(proto.Message):

class MetadataImport(proto.Message):
r"""A metastore resource that imports metadata.
Attributes:
database_dump (google.cloud.metastore_v1.types.MetadataImport.DatabaseDump):
Immutable. A database dump from a pre-
Expand Down Expand Up @@ -345,6 +350,7 @@ class DatabaseType(proto.Enum):

class MetadataExport(proto.Message):
r"""The details of a metadata export operation.
Attributes:
destination_gcs_uri (str):
Output only. A Cloud Storage URI of a folder that metadata
Expand Down Expand Up @@ -381,6 +387,7 @@ class State(proto.Enum):

class Backup(proto.Message):
r"""The details of a backup resource.
Attributes:
name (str):
Immutable. The relative resource name of the backup, in the
Expand Down Expand Up @@ -425,6 +432,7 @@ class State(proto.Enum):

class Restore(proto.Message):
r"""The details of a metadata restore operation.
Attributes:
start_time (google.protobuf.timestamp_pb2.Timestamp):
Output only. The time when the restore
Expand Down Expand Up @@ -1054,6 +1062,7 @@ class ExportMetadataRequest(proto.Message):

class RestoreServiceRequest(proto.Message):
r"""Request message for [DataprocMetastore.Restore][].
Attributes:
service (str):
Required. The relative resource name of the metastore
Expand Down Expand Up @@ -1094,6 +1103,7 @@ class RestoreServiceRequest(proto.Message):

class OperationMetadata(proto.Message):
r"""Represents the metadata of a long-running operation.
Attributes:
create_time (google.protobuf.timestamp_pb2.Timestamp):
Output only. The time the operation was
Expand Down Expand Up @@ -1132,6 +1142,7 @@ class OperationMetadata(proto.Message):

class LocationMetadata(proto.Message):
r"""Metadata about the service in a location.
Attributes:
supported_hive_metastore_versions (Sequence[google.cloud.metastore_v1.types.LocationMetadata.HiveMetastoreVersion]):
The versions of Hive Metastore that can be used when
Expand Down Expand Up @@ -1165,7 +1176,8 @@ class HiveMetastoreVersion(proto.Message):
class DatabaseDumpSpec(proto.Message):
r"""The specification of database dump to import from or export
to.
"""
"""

class Type(proto.Enum):
r"""The type of the database dump."""
Expand Down
Expand Up @@ -1548,6 +1548,12 @@ async def delete_backup(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -426,10 +426,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def list_services(
Expand Down Expand Up @@ -1784,6 +1781,19 @@ def delete_backup(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -207,6 +207,15 @@ def _prep_wrapped_messages(self, client_info):
),
}

def close(self):
"""Closes resources associated with the transport.
.. warning::
Only call this method if the transport is NOT shared
with other clients - this may cause errors in other clients!
"""
raise NotImplementedError()

@property
def operations_client(self) -> operations_v1.OperationsClient:
"""Return the client designed to process long-running operations."""
Expand Down
Expand Up @@ -656,5 +656,8 @@ def delete_backup(
)
return self._stubs["delete_backup"]

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


__all__ = ("DataprocMetastoreGrpcTransport",)
Expand Up @@ -686,5 +686,8 @@ def delete_backup(
)
return self._stubs["delete_backup"]

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


__all__ = ("DataprocMetastoreGrpcAsyncIOTransport",)
14 changes: 13 additions & 1 deletion google/cloud/metastore_v1alpha/types/metastore.py
Expand Up @@ -63,6 +63,7 @@

class Service(proto.Message):
r"""A managed metastore service that serves metadata queries.
Attributes:
hive_metastore_config (google.cloud.metastore_v1alpha.types.HiveMetastoreConfig):
Configuration information specific to running
Expand Down Expand Up @@ -258,6 +259,7 @@ class HiveMetastoreConfig(proto.Message):

class KerberosConfig(proto.Message):
r"""Configuration information for a Kerberos principal.
Attributes:
keytab (google.cloud.metastore_v1alpha.types.Secret):
A Kerberos keytab file that can be used to
Expand All @@ -281,6 +283,7 @@ class KerberosConfig(proto.Message):

class Secret(proto.Message):
r"""A securely stored value.
Attributes:
cloud_secret (str):
The relative resource name of a Secret Manager secret
Expand All @@ -294,6 +297,7 @@ class Secret(proto.Message):

class MetadataManagementActivity(proto.Message):
r"""The metadata management activities of the metastore service.
Attributes:
metadata_exports (Sequence[google.cloud.metastore_v1alpha.types.MetadataExport]):
Output only. The latest metadata exports of
Expand All @@ -311,6 +315,7 @@ class MetadataManagementActivity(proto.Message):

class MetadataImport(proto.Message):
r"""A metastore resource that imports metadata.
Attributes:
database_dump (google.cloud.metastore_v1alpha.types.MetadataImport.DatabaseDump):
Immutable. A database dump from a pre-
Expand Down Expand Up @@ -383,6 +388,7 @@ class DatabaseType(proto.Enum):

class MetadataExport(proto.Message):
r"""The details of a metadata export operation.
Attributes:
destination_gcs_uri (str):
Output only. A Cloud Storage URI of a folder that metadata
Expand Down Expand Up @@ -419,6 +425,7 @@ class State(proto.Enum):

class Backup(proto.Message):
r"""The details of a backup resource.
Attributes:
name (str):
Immutable. The relative resource name of the backup, in the
Expand Down Expand Up @@ -458,6 +465,7 @@ class State(proto.Enum):

class Restore(proto.Message):
r"""The details of a metadata restore operation.
Attributes:
start_time (google.protobuf.timestamp_pb2.Timestamp):
Output only. The time when the restore
Expand Down Expand Up @@ -1087,6 +1095,7 @@ class ExportMetadataRequest(proto.Message):

class RestoreServiceRequest(proto.Message):
r"""Request message for [DataprocMetastore.Restore][].
Attributes:
service (str):
Required. The relative resource name of the metastore
Expand Down Expand Up @@ -1127,6 +1136,7 @@ class RestoreServiceRequest(proto.Message):

class OperationMetadata(proto.Message):
r"""Represents the metadata of a long-running operation.
Attributes:
create_time (google.protobuf.timestamp_pb2.Timestamp):
Output only. The time the operation was
Expand Down Expand Up @@ -1165,6 +1175,7 @@ class OperationMetadata(proto.Message):

class LocationMetadata(proto.Message):
r"""Metadata about the service in a location.
Attributes:
supported_hive_metastore_versions (Sequence[google.cloud.metastore_v1alpha.types.LocationMetadata.HiveMetastoreVersion]):
The versions of Hive Metastore that can be used when
Expand Down Expand Up @@ -1198,7 +1209,8 @@ class HiveMetastoreVersion(proto.Message):
class DatabaseDumpSpec(proto.Message):
r"""The specification of database dump to import from or export
to.
"""
"""

class Type(proto.Enum):
r"""The type of the database dump."""
Expand Down
Expand Up @@ -1548,6 +1548,12 @@ async def delete_backup(
# Done; return the response.
return response

async def __aenter__(self):
return self

async def __aexit__(self, exc_type, exc, tb):
await self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down
Expand Up @@ -426,10 +426,7 @@ def __init__(
client_cert_source_for_mtls=client_cert_source_func,
quota_project_id=client_options.quota_project_id,
client_info=client_info,
always_use_jwt_access=(
Transport == type(self).get_transport_class("grpc")
or Transport == type(self).get_transport_class("grpc_asyncio")
),
always_use_jwt_access=True,
)

def list_services(
Expand Down Expand Up @@ -1784,6 +1781,19 @@ def delete_backup(
# Done; return the response.
return response

def __enter__(self):
return self

def __exit__(self, type, value, traceback):
"""Releases underlying transport's resources.
.. warning::
ONLY use as a context manager if the transport is NOT shared
with other clients! Exiting the with block will CLOSE the transport
and may cause errors in other clients!
"""
self.transport.close()


try:
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
Expand Down

0 comments on commit d6b8569

Please sign in to comment.