15
15
16
16
import functools
17
17
import pkg_resources
18
+ import warnings
18
19
19
20
import google .api_core .gapic_v1 .client_info
20
21
import google .api_core .gapic_v1 .config
26
27
27
28
from google .cloud .monitoring_v3 .gapic import alert_policy_service_client_config
28
29
from google .cloud .monitoring_v3 .gapic import enums
30
+ from google .cloud .monitoring_v3 .gapic .transports import alert_policy_service_grpc_transport
29
31
from google .cloud .monitoring_v3 .proto import alert_pb2
30
32
from google .cloud .monitoring_v3 .proto import alert_service_pb2
31
33
from google .cloud .monitoring_v3 .proto import alert_service_pb2_grpc
@@ -52,17 +54,8 @@ class AlertPolicyServiceClient(object):
52
54
SERVICE_ADDRESS = 'monitoring.googleapis.com:443'
53
55
"""The default address of the service."""
54
56
55
- # The scopes needed to make gRPC calls to all of the methods defined in
56
- # this service
57
- _DEFAULT_SCOPES = (
58
- 'https://www.googleapis.com/auth/cloud-platform' ,
59
- 'https://www.googleapis.com/auth/monitoring' ,
60
- 'https://www.googleapis.com/auth/monitoring.read' ,
61
- 'https://www.googleapis.com/auth/monitoring.write' ,
62
- )
63
-
64
- # The name of the interface for this client. This is the key used to find
65
- # method configuration in the client_config dictionary.
57
+ # The name of the interface for this client. This is the key used to
58
+ # find the method configuration in the client_config dictionary.
66
59
_INTERFACE_NAME = 'google.monitoring.v3.AlertPolicyService'
67
60
68
61
@classmethod
@@ -93,48 +86,71 @@ def alert_policy_condition_path(cls, project, alert_policy, condition):
93
86
)
94
87
95
88
def __init__ (self ,
89
+ transport = None ,
96
90
channel = None ,
97
91
credentials = None ,
98
92
client_config = alert_policy_service_client_config .config ,
99
93
client_info = None ):
100
94
"""Constructor.
101
95
102
96
Args:
103
- channel (grpc.Channel): A ``Channel`` instance through
104
- which to make calls. This argument is mutually exclusive
97
+ transport (Union[~.AlertPolicyServiceGrpcTransport,
98
+ Callable[[~.Credentials, type], ~.AlertPolicyServiceGrpcTransport]): A transport
99
+ instance, responsible for actually making the API calls.
100
+ The default transport uses the gRPC protocol.
101
+ This argument may also be a callable which returns a
102
+ transport instance. Callables will be sent the credentials
103
+ as the first argument and the default transport class as
104
+ the second argument.
105
+ channel (grpc.Channel): DEPRECATED. A ``Channel`` instance
106
+ through which to make calls. This argument is mutually exclusive
105
107
with ``credentials``; providing both will raise an exception.
106
108
credentials (google.auth.credentials.Credentials): The
107
109
authorization credentials to attach to requests. These
108
110
credentials identify this application to the service. If none
109
111
are specified, the client will attempt to ascertain the
110
112
credentials from the environment.
111
- client_config (dict): A dictionary of call options for each
112
- method. If not specified, the default configuration is used.
113
+ This argument is mutually exclusive with providing a
114
+ transport instance to ``transport``; doing so will raise
115
+ an exception.
116
+ client_config (dict): DEPRECATED. A dictionary of call options for
117
+ each method. If not specified, the default configuration is used.
113
118
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
114
119
The client info used to send a user-agent string along with
115
120
API requests. If ``None``, then default info will be used.
116
121
Generally, you only need to set this if you're developing
117
122
your own client library.
118
123
"""
119
- # If both `channel` and `credentials` are specified, raise an
120
- # exception (channels come with credentials baked in already).
121
- if channel is not None and credentials is not None :
122
- raise ValueError (
123
- 'The `channel` and `credentials` arguments to {} are mutually '
124
- 'exclusive.' .format (self .__class__ .__name__ ), )
125
-
126
- # Create the channel.
127
- self .channel = channel
128
- if self .channel is None :
129
- self .channel = google .api_core .grpc_helpers .create_channel (
130
- self .SERVICE_ADDRESS ,
131
- credentials = credentials ,
132
- scopes = self ._DEFAULT_SCOPES ,
133
- )
134
-
135
- # Create the gRPC stubs.
136
- self ._alert_policy_service_stub = (
137
- alert_service_pb2_grpc .AlertPolicyServiceStub (self .channel ))
124
+ # Raise deprecation warnings for things we want to go away.
125
+ if client_config :
126
+ warnings .warn ('The `client_config` argument is deprecated.' ,
127
+ PendingDeprecationWarning )
128
+ if channel :
129
+ warnings .warn (
130
+ 'The `channel` argument is deprecated; use '
131
+ '`transport` instead.' , PendingDeprecationWarning )
132
+
133
+ # Instantiate the transport.
134
+ # The transport is responsible for handling serialization and
135
+ # deserialization and actually sending data to the service.
136
+ if transport :
137
+ if callable (transport ):
138
+ self .transport = transport (
139
+ credentials = credentials ,
140
+ default_class = alert_policy_service_grpc_transport .
141
+ AlertPolicyServiceGrpcTransport ,
142
+ )
143
+ else :
144
+ if credentials :
145
+ raise ValueError (
146
+ 'Received both a transport instance and '
147
+ 'credentials; these are mutually exclusive.' )
148
+ self .transport = transport
149
+ self .transport = alert_policy_service_grpc_transport .AlertPolicyServiceGrpcTransport (
150
+ address = self .SERVICE_ADDRESS ,
151
+ channel = channel ,
152
+ credentials = credentials ,
153
+ )
138
154
139
155
if client_info is None :
140
156
client_info = (
@@ -149,27 +165,12 @@ def __init__(self,
149
165
self ._method_configs = google .api_core .gapic_v1 .config .parse_method_configs (
150
166
client_config ['interfaces' ][self ._INTERFACE_NAME ], )
151
167
168
+ # Save a dictionary of cached API call functions.
169
+ # These are the actual callables which invoke the proper
170
+ # transport methods, wrapped with `wrap_method` to add retry,
171
+ # timeout, and the like.
152
172
self ._inner_api_calls = {}
153
173
154
- def _intercept_channel (self , * interceptors ):
155
- """ Experimental. Bind gRPC interceptors to the gRPC channel.
156
-
157
- Args:
158
- interceptors (*Union[grpc.UnaryUnaryClientInterceptor, grpc.UnaryStreamingClientInterceptor, grpc.StreamingUnaryClientInterceptor, grpc.StreamingStreamingClientInterceptor]):
159
- Zero or more gRPC interceptors. Interceptors are given control in the order
160
- they are listed.
161
- Raises:
162
- TypeError: If interceptor does not derive from any of
163
- UnaryUnaryClientInterceptor,
164
- UnaryStreamClientInterceptor,
165
- StreamUnaryClientInterceptor, or
166
- StreamStreamClientInterceptor.
167
- """
168
- self .channel = grpc .intercept_channel (self .channel , * interceptors )
169
- self ._alert_policy_service_stub = (
170
- alert_service_pb2_grpc .AlertPolicyServiceStub (self .channel ))
171
- self ._inner_api_calls .clear ()
172
-
173
174
# Service calls
174
175
def list_alert_policies (self ,
175
176
name ,
@@ -254,10 +255,11 @@ def list_alert_policies(self,
254
255
if metadata is None :
255
256
metadata = []
256
257
metadata = list (metadata )
258
+ # Wrap the transport method to add retry and timeout logic.
257
259
if 'list_alert_policies' not in self ._inner_api_calls :
258
260
self ._inner_api_calls [
259
261
'list_alert_policies' ] = google .api_core .gapic_v1 .method .wrap_method (
260
- self ._alert_policy_service_stub . ListAlertPolicies ,
262
+ self .transport . list_alert_policies ,
261
263
default_retry = self ._method_configs [
262
264
'ListAlertPolicies' ].retry ,
263
265
default_timeout = self ._method_configs ['ListAlertPolicies' ]
@@ -328,10 +330,11 @@ def get_alert_policy(self,
328
330
if metadata is None :
329
331
metadata = []
330
332
metadata = list (metadata )
333
+ # Wrap the transport method to add retry and timeout logic.
331
334
if 'get_alert_policy' not in self ._inner_api_calls :
332
335
self ._inner_api_calls [
333
336
'get_alert_policy' ] = google .api_core .gapic_v1 .method .wrap_method (
334
- self ._alert_policy_service_stub . GetAlertPolicy ,
337
+ self .transport . get_alert_policy ,
335
338
default_retry = self ._method_configs ['GetAlertPolicy' ].retry ,
336
339
default_timeout = self ._method_configs ['GetAlertPolicy' ]
337
340
.timeout ,
@@ -399,10 +402,11 @@ def create_alert_policy(self,
399
402
if metadata is None :
400
403
metadata = []
401
404
metadata = list (metadata )
405
+ # Wrap the transport method to add retry and timeout logic.
402
406
if 'create_alert_policy' not in self ._inner_api_calls :
403
407
self ._inner_api_calls [
404
408
'create_alert_policy' ] = google .api_core .gapic_v1 .method .wrap_method (
405
- self ._alert_policy_service_stub . CreateAlertPolicy ,
409
+ self .transport . create_alert_policy ,
406
410
default_retry = self ._method_configs [
407
411
'CreateAlertPolicy' ].retry ,
408
412
default_timeout = self ._method_configs ['CreateAlertPolicy' ]
@@ -459,10 +463,11 @@ def delete_alert_policy(self,
459
463
if metadata is None :
460
464
metadata = []
461
465
metadata = list (metadata )
466
+ # Wrap the transport method to add retry and timeout logic.
462
467
if 'delete_alert_policy' not in self ._inner_api_calls :
463
468
self ._inner_api_calls [
464
469
'delete_alert_policy' ] = google .api_core .gapic_v1 .method .wrap_method (
465
- self ._alert_policy_service_stub . DeleteAlertPolicy ,
470
+ self .transport . delete_alert_policy ,
466
471
default_retry = self ._method_configs [
467
472
'DeleteAlertPolicy' ].retry ,
468
473
default_timeout = self ._method_configs ['DeleteAlertPolicy' ]
@@ -549,10 +554,11 @@ def update_alert_policy(self,
549
554
if metadata is None :
550
555
metadata = []
551
556
metadata = list (metadata )
557
+ # Wrap the transport method to add retry and timeout logic.
552
558
if 'update_alert_policy' not in self ._inner_api_calls :
553
559
self ._inner_api_calls [
554
560
'update_alert_policy' ] = google .api_core .gapic_v1 .method .wrap_method (
555
- self ._alert_policy_service_stub . UpdateAlertPolicy ,
561
+ self .transport . update_alert_policy ,
556
562
default_retry = self ._method_configs [
557
563
'UpdateAlertPolicy' ].retry ,
558
564
default_timeout = self ._method_configs ['UpdateAlertPolicy' ]
0 commit comments