Skip to content

Commit

Permalink
Add 'client_options' support, update list method docstrings (via synt…
Browse files Browse the repository at this point in the history
…h). (#8505)
  • Loading branch information
yoshi-automation authored and busunkim96 committed Jun 28, 2019
1 parent 0d14378 commit 5ff4e34
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import warnings

from google.oauth2 import service_account
import google.api_core.client_options
import google.api_core.gapic_v1.client_info
import google.api_core.gapic_v1.config
import google.api_core.gapic_v1.method
Expand Down Expand Up @@ -85,6 +86,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -115,6 +117,9 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
Expand All @@ -133,6 +138,15 @@ def __init__(
stacklevel=2,
)

api_endpoint = self.SERVICE_ADDRESS
if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(
client_options
)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint

# Instantiate the transport.
# The transport is responsible for handling serialization and
# deserialization and actually sending data to the service.
Expand All @@ -141,6 +155,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=cluster_controller_grpc_transport.ClusterControllerGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -151,7 +166,7 @@ def __init__(
self.transport = transport
else:
self.transport = cluster_controller_grpc_transport.ClusterControllerGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -713,10 +728,10 @@ def list_clusters(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.dataproc_v1.types.Cluster` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.dataproc_v1.types.Cluster` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down
25 changes: 20 additions & 5 deletions dataproc/google/cloud/dataproc_v1/gapic/job_controller_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import warnings

from google.oauth2 import service_account
import google.api_core.client_options
import google.api_core.gapic_v1.client_info
import google.api_core.gapic_v1.config
import google.api_core.gapic_v1.method
Expand Down Expand Up @@ -82,6 +83,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -112,6 +114,9 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
Expand All @@ -130,6 +135,15 @@ def __init__(
stacklevel=2,
)

api_endpoint = self.SERVICE_ADDRESS
if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(
client_options
)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint

# Instantiate the transport.
# The transport is responsible for handling serialization and
# deserialization and actually sending data to the service.
Expand All @@ -138,6 +152,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=job_controller_grpc_transport.JobControllerGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -148,7 +163,7 @@ def __init__(
self.transport = transport
else:
self.transport = job_controller_grpc_transport.JobControllerGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -407,10 +422,10 @@ def list_jobs(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.dataproc_v1.types.Job` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.dataproc_v1.types.Job` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import warnings

from google.oauth2 import service_account
import google.api_core.client_options
import google.api_core.gapic_v1.client_info
import google.api_core.gapic_v1.config
import google.api_core.gapic_v1.method
Expand Down Expand Up @@ -110,6 +111,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -140,6 +142,9 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
Expand All @@ -158,6 +163,15 @@ def __init__(
stacklevel=2,
)

api_endpoint = self.SERVICE_ADDRESS
if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(
client_options
)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint

# Instantiate the transport.
# The transport is responsible for handling serialization and
# deserialization and actually sending data to the service.
Expand All @@ -166,6 +180,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=workflow_template_service_grpc_transport.WorkflowTemplateServiceGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -176,7 +191,7 @@ def __init__(
self.transport = transport
else:
self.transport = workflow_template_service_grpc_transport.WorkflowTemplateServiceGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -741,10 +756,10 @@ def list_workflow_templates(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.dataproc_v1.types.WorkflowTemplate` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.dataproc_v1.types.WorkflowTemplate` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import warnings

from google.oauth2 import service_account
import google.api_core.client_options
import google.api_core.gapic_v1.client_info
import google.api_core.gapic_v1.config
import google.api_core.gapic_v1.method
Expand Down Expand Up @@ -100,6 +101,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -130,6 +132,9 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
Expand All @@ -148,6 +153,15 @@ def __init__(
stacklevel=2,
)

api_endpoint = self.SERVICE_ADDRESS
if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(
client_options
)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint

# Instantiate the transport.
# The transport is responsible for handling serialization and
# deserialization and actually sending data to the service.
Expand All @@ -156,6 +170,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=autoscaling_policy_service_grpc_transport.AutoscalingPolicyServiceGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -166,7 +181,7 @@ def __init__(
self.transport = transport
else:
self.transport = autoscaling_policy_service_grpc_transport.AutoscalingPolicyServiceGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -471,10 +486,10 @@ def list_autoscaling_policies(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.dataproc_v1beta2.types.AutoscalingPolicy` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.dataproc_v1beta2.types.AutoscalingPolicy` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import warnings

from google.oauth2 import service_account
import google.api_core.client_options
import google.api_core.gapic_v1.client_info
import google.api_core.gapic_v1.config
import google.api_core.gapic_v1.method
Expand Down Expand Up @@ -89,6 +90,7 @@ def __init__(
credentials=None,
client_config=None,
client_info=None,
client_options=None,
):
"""Constructor.
Expand Down Expand Up @@ -119,6 +121,9 @@ def __init__(
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
client_options (Union[dict, google.api_core.client_options.ClientOptions]):
Client options used to set user options on the client. API Endpoint
should be set through client_options.
"""
# Raise deprecation warnings for things we want to go away.
if client_config is not None:
Expand All @@ -137,6 +142,15 @@ def __init__(
stacklevel=2,
)

api_endpoint = self.SERVICE_ADDRESS
if client_options:
if type(client_options) == dict:
client_options = google.api_core.client_options.from_dict(
client_options
)
if client_options.api_endpoint:
api_endpoint = client_options.api_endpoint

# Instantiate the transport.
# The transport is responsible for handling serialization and
# deserialization and actually sending data to the service.
Expand All @@ -145,6 +159,7 @@ def __init__(
self.transport = transport(
credentials=credentials,
default_class=cluster_controller_grpc_transport.ClusterControllerGrpcTransport,
address=api_endpoint,
)
else:
if credentials:
Expand All @@ -155,7 +170,7 @@ def __init__(
self.transport = transport
else:
self.transport = cluster_controller_grpc_transport.ClusterControllerGrpcTransport(
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
address=api_endpoint, channel=channel, credentials=credentials
)

if client_info is None:
Expand Down Expand Up @@ -729,10 +744,10 @@ def list_clusters(
that is provided to the method.
Returns:
A :class:`~google.gax.PageIterator` instance. By default, this
is an iterable of :class:`~google.cloud.dataproc_v1beta2.types.Cluster` instances.
This object can also be configured to iterate over the pages
of the response through the `options` parameter.
A :class:`~google.api_core.page_iterator.PageIterator` instance.
An iterable of :class:`~google.cloud.dataproc_v1beta2.types.Cluster` instances.
You can also iterate over the pages of the response
using its `pages` property.
Raises:
google.api_core.exceptions.GoogleAPICallError: If the request
Expand Down
Loading

0 comments on commit 5ff4e34

Please sign in to comment.