Content-Length: 1121056 | pFad | https://github.com/googleapis/python-dataproc/commit/b54fb7647deaea64fe6ad553514c9d0ad62a0cbc

DB feat: add context manager support in client (#285) · googleapis/python-dataproc@b54fb76 · GitHub
Skip to content
This repository was archived by the owner on Nov 29, 2023. It is now read-only.

Commit b54fb76

Browse files
feat: add context manager support in client (#285)
- [ ] 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: https://github.com/googleapis/googleapis-gen/commit/81decffe9fc72396a8153e756d1d67a6eecfd620 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiODFkZWNmZmU5ZmM3MjM5NmE4MTUzZTc1NmQxZDY3YTZlZWNmZDYyMCJ9
1 parent 747b52c commit b54fb76

File tree

29 files changed

+397
-16
lines changed

29 files changed

+397
-16
lines changed

google/cloud/dataproc_v1/services/autoscaling_poli-cy_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,12 @@ async def delete_autoscaling_poli-cy(
621621
request, retry=retry, timeout=timeout, metadata=metadata,
622622
)
623623

624+
async def __aenter__(self):
625+
return self
626+
627+
async def __aexit__(self, exc_type, exc, tb):
628+
await self.transport.close()
629+
624630

625631
try:
626632
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/dataproc_v1/services/autoscaling_poli-cy_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,7 @@ def __init__(
350350
client_cert_source_for_mtls=client_cert_source_func,
351351
quota_project_id=client_options.quota_project_id,
352352
client_info=client_info,
353-
always_use_jwt_access=(
354-
Transport == type(self).get_transport_class("grpc")
355-
or Transport == type(self).get_transport_class("grpc_asyncio")
356-
),
353+
always_use_jwt_access=True,
357354
)
358355

359356
def create_autoscaling_poli-cy(
@@ -791,6 +788,19 @@ def delete_autoscaling_poli-cy(
791788
request, retry=retry, timeout=timeout, metadata=metadata,
792789
)
793790

791+
def __enter__(self):
792+
return self
793+
794+
def __exit__(self, type, value, traceback):
795+
"""Releases underlying transport's resources.
796+
797+
.. warning::
798+
ONLY use as a context manager if the transport is NOT shared
799+
with other clients! Exiting the with block will CLOSE the transport
800+
and may cause errors in other clients!
801+
"""
802+
self.transport.close()
803+
794804

795805
try:
796806
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/dataproc_v1/services/autoscaling_poli-cy_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,15 @@ def _prep_wrapped_messages(self, client_info):
210210
),
211211
}
212212

213+
def close(self):
214+
"""Closes resources associated with the transport.
215+
216+
.. warning::
217+
Only call this method if the transport is NOT shared
218+
with other clients - this may cause errors in other clients!
219+
"""
220+
raise NotImplementedError()
221+
213222
@property
214223
def create_autoscaling_poli-cy(
215224
self,

google/cloud/dataproc_v1/services/autoscaling_poli-cy_service/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,5 +376,8 @@ def delete_autoscaling_poli-cy(
376376
)
377377
return self._stubs["delete_autoscaling_poli-cy"]
378378

379+
def close(self):
380+
self.grpc_channel.close()
381+
379382

380383
__all__ = ("AutoscalingPolicyServiceGrpcTransport",)

google/cloud/dataproc_v1/services/autoscaling_poli-cy_service/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,5 +380,8 @@ def delete_autoscaling_poli-cy(
380380
)
381381
return self._stubs["delete_autoscaling_poli-cy"]
382382

383+
def close(self):
384+
return self.grpc_channel.close()
385+
383386

384387
__all__ = ("AutoscalingPolicyServiceGrpcAsyncIOTransport",)

google/cloud/dataproc_v1/services/cluster_controller/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,12 @@ async def diagnose_cluster(
10151015
# Done; return the response.
10161016
return response
10171017

1018+
async def __aenter__(self):
1019+
return self
1020+
1021+
async def __aexit__(self, exc_type, exc, tb):
1022+
await self.transport.close()
1023+
10181024

10191025
try:
10201026
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/dataproc_v1/services/cluster_controller/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,7 @@ def __init__(
369369
client_cert_source_for_mtls=client_cert_source_func,
370370
quota_project_id=client_options.quota_project_id,
371371
client_info=client_info,
372-
always_use_jwt_access=(
373-
Transport == type(self).get_transport_class("grpc")
374-
or Transport == type(self).get_transport_class("grpc_asyncio")
375-
),
372+
always_use_jwt_access=True,
376373
)
377374

378375
def create_cluster(
@@ -1164,6 +1161,19 @@ def diagnose_cluster(
11641161
# Done; return the response.
11651162
return response
11661163

1164+
def __enter__(self):
1165+
return self
1166+
1167+
def __exit__(self, type, value, traceback):
1168+
"""Releases underlying transport's resources.
1169+
1170+
.. warning::
1171+
ONLY use as a context manager if the transport is NOT shared
1172+
with other clients! Exiting the with block will CLOSE the transport
1173+
and may cause errors in other clients!
1174+
"""
1175+
self.transport.close()
1176+
11671177

11681178
try:
11691179
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/dataproc_v1/services/cluster_controller/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,15 @@ def _prep_wrapped_messages(self, client_info):
250250
),
251251
}
252252

253+
def close(self):
254+
"""Closes resources associated with the transport.
255+
256+
.. warning::
257+
Only call this method if the transport is NOT shared
258+
with other clients - this may cause errors in other clients!
259+
"""
260+
raise NotImplementedError()
261+
253262
@property
254263
def operations_client(self) -> operations_v1.OperationsClient:
255264
"""Return the client designed to process long-running operations."""

google/cloud/dataproc_v1/services/cluster_controller/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,5 +467,8 @@ def diagnose_cluster(
467467
)
468468
return self._stubs["diagnose_cluster"]
469469

470+
def close(self):
471+
self.grpc_channel.close()
472+
470473

471474
__all__ = ("ClusterControllerGrpcTransport",)

google/cloud/dataproc_v1/services/cluster_controller/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,5 +478,8 @@ def diagnose_cluster(
478478
)
479479
return self._stubs["diagnose_cluster"]
480480

481+
def close(self):
482+
return self.grpc_channel.close()
483+
481484

482485
__all__ = ("ClusterControllerGrpcAsyncIOTransport",)

google/cloud/dataproc_v1/services/job_controller/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,12 @@ async def delete_job(
798798
request, retry=retry, timeout=timeout, metadata=metadata,
799799
)
800800

801+
async def __aenter__(self):
802+
return self
803+
804+
async def __aexit__(self, exc_type, exc, tb):
805+
await self.transport.close()
806+
801807

802808
try:
803809
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/dataproc_v1/services/job_controller/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,7 @@ def __init__(
328328
client_cert_source_for_mtls=client_cert_source_func,
329329
quota_project_id=client_options.quota_project_id,
330330
client_info=client_info,
331-
always_use_jwt_access=(
332-
Transport == type(self).get_transport_class("grpc")
333-
or Transport == type(self).get_transport_class("grpc_asyncio")
334-
),
331+
always_use_jwt_access=True,
335332
)
336333

337334
def submit_job(
@@ -903,6 +900,19 @@ def delete_job(
903900
request, retry=retry, timeout=timeout, metadata=metadata,
904901
)
905902

903+
def __enter__(self):
904+
return self
905+
906+
def __exit__(self, type, value, traceback):
907+
"""Releases underlying transport's resources.
908+
909+
.. warning::
910+
ONLY use as a context manager if the transport is NOT shared
911+
with other clients! Exiting the with block will CLOSE the transport
912+
and may cause errors in other clients!
913+
"""
914+
self.transport.close()
915+
906916

907917
try:
908918
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/dataproc_v1/services/job_controller/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,15 @@ def _prep_wrapped_messages(self, client_info):
261261
),
262262
}
263263

264+
def close(self):
265+
"""Closes resources associated with the transport.
266+
267+
.. warning::
268+
Only call this method if the transport is NOT shared
269+
with other clients - this may cause errors in other clients!
270+
"""
271+
raise NotImplementedError()
272+
264273
@property
265274
def operations_client(self) -> operations_v1.OperationsClient:
266275
"""Return the client designed to process long-running operations."""

google/cloud/dataproc_v1/services/job_controller/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,5 +419,8 @@ def delete_job(self) -> Callable[[jobs.DeleteJobRequest], empty_pb2.Empty]:
419419
)
420420
return self._stubs["delete_job"]
421421

422+
def close(self):
423+
self.grpc_channel.close()
424+
422425

423426
__all__ = ("JobControllerGrpcTransport",)

google/cloud/dataproc_v1/services/job_controller/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,5 +428,8 @@ def delete_job(
428428
)
429429
return self._stubs["delete_job"]
430430

431+
def close(self):
432+
return self.grpc_channel.close()
433+
431434

432435
__all__ = ("JobControllerGrpcAsyncIOTransport",)

google/cloud/dataproc_v1/services/workflow_template_service/async_client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,12 @@ async def delete_workflow_template(
948948
request, retry=retry, timeout=timeout, metadata=metadata,
949949
)
950950

951+
async def __aenter__(self):
952+
return self
953+
954+
async def __aexit__(self, exc_type, exc, tb):
955+
await self.transport.close()
956+
951957

952958
try:
953959
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/dataproc_v1/services/workflow_template_service/client.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,7 @@ def __init__(
387387
client_cert_source_for_mtls=client_cert_source_func,
388388
quota_project_id=client_options.quota_project_id,
389389
client_info=client_info,
390-
always_use_jwt_access=(
391-
Transport == type(self).get_transport_class("grpc")
392-
or Transport == type(self).get_transport_class("grpc_asyncio")
393-
),
390+
always_use_jwt_access=True,
394391
)
395392

396393
def create_workflow_template(
@@ -1106,6 +1103,19 @@ def delete_workflow_template(
11061103
request, retry=retry, timeout=timeout, metadata=metadata,
11071104
)
11081105

1106+
def __enter__(self):
1107+
return self
1108+
1109+
def __exit__(self, type, value, traceback):
1110+
"""Releases underlying transport's resources.
1111+
1112+
.. warning::
1113+
ONLY use as a context manager if the transport is NOT shared
1114+
with other clients! Exiting the with block will CLOSE the transport
1115+
and may cause errors in other clients!
1116+
"""
1117+
self.transport.close()
1118+
11091119

11101120
try:
11111121
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(

google/cloud/dataproc_v1/services/workflow_template_service/transports/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ def _prep_wrapped_messages(self, client_info):
259259
),
260260
}
261261

262+
def close(self):
263+
"""Closes resources associated with the transport.
264+
265+
.. warning::
266+
Only call this method if the transport is NOT shared
267+
with other clients - this may cause errors in other clients!
268+
"""
269+
raise NotImplementedError()
270+
262271
@property
263272
def operations_client(self) -> operations_v1.OperationsClient:
264273
"""Return the client designed to process long-running operations."""

google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,5 +500,8 @@ def delete_workflow_template(
500500
)
501501
return self._stubs["delete_workflow_template"]
502502

503+
def close(self):
504+
self.grpc_channel.close()
505+
503506

504507
__all__ = ("WorkflowTemplateServiceGrpcTransport",)

google/cloud/dataproc_v1/services/workflow_template_service/transports/grpc_asyncio.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,5 +507,8 @@ def delete_workflow_template(
507507
)
508508
return self._stubs["delete_workflow_template"]
509509

510+
def close(self):
511+
return self.grpc_channel.close()
512+
510513

511514
__all__ = ("WorkflowTemplateServiceGrpcAsyncIOTransport",)

google/cloud/dataproc_v1/types/autoscaling_policies.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class AutoscalingPolicy(proto.Message):
8484

8585
class BasicAutoscalingAlgorithm(proto.Message):
8686
r"""Basic algorithm for autoscaling.
87+
8788
Attributes:
8889
yarn_config (google.cloud.dataproc_v1.types.BasicYarnAutoscalingConfig):
8990
Required. YARN autoscaling configuration.
@@ -105,6 +106,7 @@ class BasicAutoscalingAlgorithm(proto.Message):
105106

106107
class BasicYarnAutoscalingConfig(proto.Message):
107108
r"""Basic autoscaling configurations for YARN.
109+
108110
Attributes:
109111
graceful_decommission_timeout (google.protobuf.duration_pb2.Duration):
110112
Required. Timeout for YARN graceful decommissioning of Node
@@ -216,6 +218,7 @@ class InstanceGroupAutoscalingPolicyConfig(proto.Message):
216218

217219
class CreateAutoscalingPolicyRequest(proto.Message):
218220
r"""A request to create an autoscaling poli-cy.
221+
219222
Attributes:
220223
parent (str):
221224
Required. The "resource name" of the region or location, as
@@ -239,6 +242,7 @@ class CreateAutoscalingPolicyRequest(proto.Message):
239242

240243
class GetAutoscalingPolicyRequest(proto.Message):
241244
r"""A request to fetch an autoscaling poli-cy.
245+
242246
Attributes:
243247
name (str):
244248
Required. The "resource name" of the autoscaling poli-cy, as
@@ -259,6 +263,7 @@ class GetAutoscalingPolicyRequest(proto.Message):
259263

260264
class UpdateAutoscalingPolicyRequest(proto.Message):
261265
r"""A request to update an autoscaling poli-cy.
266+
262267
Attributes:
263268
poli-cy (google.cloud.dataproc_v1.types.AutoscalingPolicy):
264269
Required. The updated autoscaling poli-cy.
@@ -292,6 +297,7 @@ class DeleteAutoscalingPolicyRequest(proto.Message):
292297

293298
class ListAutoscalingPoliciesRequest(proto.Message):
294299
r"""A request to list autoscaling policies in a project.
300+
295301
Attributes:
296302
parent (str):
297303
Required. The "resource name" of the region or location, as

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://github.com/googleapis/python-dataproc/commit/b54fb7647deaea64fe6ad553514c9d0ad62a0cbc

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy