google-maps-routeoptimization 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- google/maps/routeoptimization/__init__.py +85 -0
- google/maps/routeoptimization/gapic_version.py +16 -0
- google/maps/routeoptimization/py.typed +2 -0
- google/maps/routeoptimization_v1/__init__.py +83 -0
- google/maps/routeoptimization_v1/gapic_metadata.json +58 -0
- google/maps/routeoptimization_v1/gapic_version.py +16 -0
- google/maps/routeoptimization_v1/py.typed +2 -0
- google/maps/routeoptimization_v1/services/__init__.py +15 -0
- google/maps/routeoptimization_v1/services/route_optimization/__init__.py +22 -0
- google/maps/routeoptimization_v1/services/route_optimization/async_client.py +588 -0
- google/maps/routeoptimization_v1/services/route_optimization/client.py +992 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/__init__.py +36 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/base.py +200 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/grpc.py +381 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/grpc_asyncio.py +408 -0
- google/maps/routeoptimization_v1/services/route_optimization/transports/rest.py +631 -0
- google/maps/routeoptimization_v1/types/__init__.py +72 -0
- google/maps/routeoptimization_v1/types/route_optimization_service.py +4029 -0
- google_maps_routeoptimization-0.1.0.dist-info/LICENSE +202 -0
- google_maps_routeoptimization-0.1.0.dist-info/METADATA +137 -0
- google_maps_routeoptimization-0.1.0.dist-info/RECORD +23 -0
- google_maps_routeoptimization-0.1.0.dist-info/WHEEL +5 -0
- google_maps_routeoptimization-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,992 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
# Copyright 2024 Google LLC
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
#
|
|
16
|
+
from collections import OrderedDict
|
|
17
|
+
import os
|
|
18
|
+
import re
|
|
19
|
+
from typing import (
|
|
20
|
+
Callable,
|
|
21
|
+
Dict,
|
|
22
|
+
Mapping,
|
|
23
|
+
MutableMapping,
|
|
24
|
+
MutableSequence,
|
|
25
|
+
Optional,
|
|
26
|
+
Sequence,
|
|
27
|
+
Tuple,
|
|
28
|
+
Type,
|
|
29
|
+
Union,
|
|
30
|
+
cast,
|
|
31
|
+
)
|
|
32
|
+
import warnings
|
|
33
|
+
|
|
34
|
+
from google.api_core import client_options as client_options_lib
|
|
35
|
+
from google.api_core import exceptions as core_exceptions
|
|
36
|
+
from google.api_core import gapic_v1
|
|
37
|
+
from google.api_core import retry as retries
|
|
38
|
+
from google.auth import credentials as ga_credentials # type: ignore
|
|
39
|
+
from google.auth.exceptions import MutualTLSChannelError # type: ignore
|
|
40
|
+
from google.auth.transport import mtls # type: ignore
|
|
41
|
+
from google.auth.transport.grpc import SslCredentials # type: ignore
|
|
42
|
+
from google.oauth2 import service_account # type: ignore
|
|
43
|
+
|
|
44
|
+
from google.maps.routeoptimization_v1 import gapic_version as package_version
|
|
45
|
+
|
|
46
|
+
try:
|
|
47
|
+
OptionalRetry = Union[retries.Retry, gapic_v1.method._MethodDefault, None]
|
|
48
|
+
except AttributeError: # pragma: NO COVER
|
|
49
|
+
OptionalRetry = Union[retries.Retry, object, None] # type: ignore
|
|
50
|
+
|
|
51
|
+
from google.api_core import operation # type: ignore
|
|
52
|
+
from google.api_core import operation_async # type: ignore
|
|
53
|
+
from google.longrunning import operations_pb2 # type: ignore
|
|
54
|
+
|
|
55
|
+
from google.maps.routeoptimization_v1.types import route_optimization_service
|
|
56
|
+
|
|
57
|
+
from .transports.base import DEFAULT_CLIENT_INFO, RouteOptimizationTransport
|
|
58
|
+
from .transports.grpc import RouteOptimizationGrpcTransport
|
|
59
|
+
from .transports.grpc_asyncio import RouteOptimizationGrpcAsyncIOTransport
|
|
60
|
+
from .transports.rest import RouteOptimizationRestTransport
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
class RouteOptimizationClientMeta(type):
|
|
64
|
+
"""Metaclass for the RouteOptimization client.
|
|
65
|
+
|
|
66
|
+
This provides class-level methods for building and retrieving
|
|
67
|
+
support objects (e.g. transport) without polluting the client instance
|
|
68
|
+
objects.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
_transport_registry = (
|
|
72
|
+
OrderedDict()
|
|
73
|
+
) # type: Dict[str, Type[RouteOptimizationTransport]]
|
|
74
|
+
_transport_registry["grpc"] = RouteOptimizationGrpcTransport
|
|
75
|
+
_transport_registry["grpc_asyncio"] = RouteOptimizationGrpcAsyncIOTransport
|
|
76
|
+
_transport_registry["rest"] = RouteOptimizationRestTransport
|
|
77
|
+
|
|
78
|
+
def get_transport_class(
|
|
79
|
+
cls,
|
|
80
|
+
label: Optional[str] = None,
|
|
81
|
+
) -> Type[RouteOptimizationTransport]:
|
|
82
|
+
"""Returns an appropriate transport class.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
label: The name of the desired transport. If none is
|
|
86
|
+
provided, then the first transport in the registry is used.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
The transport class to use.
|
|
90
|
+
"""
|
|
91
|
+
# If a specific transport is requested, return that one.
|
|
92
|
+
if label:
|
|
93
|
+
return cls._transport_registry[label]
|
|
94
|
+
|
|
95
|
+
# No transport is requested; return the default (that is, the first one
|
|
96
|
+
# in the dictionary).
|
|
97
|
+
return next(iter(cls._transport_registry.values()))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class RouteOptimizationClient(metaclass=RouteOptimizationClientMeta):
|
|
101
|
+
"""A service for optimizing vehicle tours.
|
|
102
|
+
|
|
103
|
+
Validity of certain types of fields:
|
|
104
|
+
|
|
105
|
+
- ``google.protobuf.Timestamp``
|
|
106
|
+
|
|
107
|
+
- Times are in Unix time: seconds since
|
|
108
|
+
1970-01-01T00:00:00+00:00.
|
|
109
|
+
- seconds must be in [0, 253402300799], i.e. in
|
|
110
|
+
[1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
|
|
111
|
+
- nanos must be unset or set to 0.
|
|
112
|
+
|
|
113
|
+
- ``google.protobuf.Duration``
|
|
114
|
+
|
|
115
|
+
- seconds must be in [0, 253402300799], i.e. in
|
|
116
|
+
[1970-01-01T00:00:00+00:00, 9999-12-31T23:59:59+00:00].
|
|
117
|
+
- nanos must be unset or set to 0.
|
|
118
|
+
|
|
119
|
+
- ``google.type.LatLng``
|
|
120
|
+
|
|
121
|
+
- latitude must be in [-90.0, 90.0].
|
|
122
|
+
- longitude must be in [-180.0, 180.0].
|
|
123
|
+
- at least one of latitude and longitude must be non-zero.
|
|
124
|
+
"""
|
|
125
|
+
|
|
126
|
+
@staticmethod
|
|
127
|
+
def _get_default_mtls_endpoint(api_endpoint):
|
|
128
|
+
"""Converts api endpoint to mTLS endpoint.
|
|
129
|
+
|
|
130
|
+
Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to
|
|
131
|
+
"*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively.
|
|
132
|
+
Args:
|
|
133
|
+
api_endpoint (Optional[str]): the api endpoint to convert.
|
|
134
|
+
Returns:
|
|
135
|
+
str: converted mTLS api endpoint.
|
|
136
|
+
"""
|
|
137
|
+
if not api_endpoint:
|
|
138
|
+
return api_endpoint
|
|
139
|
+
|
|
140
|
+
mtls_endpoint_re = re.compile(
|
|
141
|
+
r"(?P<name>[^.]+)(?P<mtls>\.mtls)?(?P<sandbox>\.sandbox)?(?P<googledomain>\.googleapis\.com)?"
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
m = mtls_endpoint_re.match(api_endpoint)
|
|
145
|
+
name, mtls, sandbox, googledomain = m.groups()
|
|
146
|
+
if mtls or not googledomain:
|
|
147
|
+
return api_endpoint
|
|
148
|
+
|
|
149
|
+
if sandbox:
|
|
150
|
+
return api_endpoint.replace(
|
|
151
|
+
"sandbox.googleapis.com", "mtls.sandbox.googleapis.com"
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com")
|
|
155
|
+
|
|
156
|
+
# Note: DEFAULT_ENDPOINT is deprecated. Use _DEFAULT_ENDPOINT_TEMPLATE instead.
|
|
157
|
+
DEFAULT_ENDPOINT = "routeoptimization.googleapis.com"
|
|
158
|
+
DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore
|
|
159
|
+
DEFAULT_ENDPOINT
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
_DEFAULT_ENDPOINT_TEMPLATE = "routeoptimization.{UNIVERSE_DOMAIN}"
|
|
163
|
+
_DEFAULT_UNIVERSE = "googleapis.com"
|
|
164
|
+
|
|
165
|
+
@classmethod
|
|
166
|
+
def from_service_account_info(cls, info: dict, *args, **kwargs):
|
|
167
|
+
"""Creates an instance of this client using the provided credentials
|
|
168
|
+
info.
|
|
169
|
+
|
|
170
|
+
Args:
|
|
171
|
+
info (dict): The service account private key info.
|
|
172
|
+
args: Additional arguments to pass to the constructor.
|
|
173
|
+
kwargs: Additional arguments to pass to the constructor.
|
|
174
|
+
|
|
175
|
+
Returns:
|
|
176
|
+
RouteOptimizationClient: The constructed client.
|
|
177
|
+
"""
|
|
178
|
+
credentials = service_account.Credentials.from_service_account_info(info)
|
|
179
|
+
kwargs["credentials"] = credentials
|
|
180
|
+
return cls(*args, **kwargs)
|
|
181
|
+
|
|
182
|
+
@classmethod
|
|
183
|
+
def from_service_account_file(cls, filename: str, *args, **kwargs):
|
|
184
|
+
"""Creates an instance of this client using the provided credentials
|
|
185
|
+
file.
|
|
186
|
+
|
|
187
|
+
Args:
|
|
188
|
+
filename (str): The path to the service account private key json
|
|
189
|
+
file.
|
|
190
|
+
args: Additional arguments to pass to the constructor.
|
|
191
|
+
kwargs: Additional arguments to pass to the constructor.
|
|
192
|
+
|
|
193
|
+
Returns:
|
|
194
|
+
RouteOptimizationClient: The constructed client.
|
|
195
|
+
"""
|
|
196
|
+
credentials = service_account.Credentials.from_service_account_file(filename)
|
|
197
|
+
kwargs["credentials"] = credentials
|
|
198
|
+
return cls(*args, **kwargs)
|
|
199
|
+
|
|
200
|
+
from_service_account_json = from_service_account_file
|
|
201
|
+
|
|
202
|
+
@property
|
|
203
|
+
def transport(self) -> RouteOptimizationTransport:
|
|
204
|
+
"""Returns the transport used by the client instance.
|
|
205
|
+
|
|
206
|
+
Returns:
|
|
207
|
+
RouteOptimizationTransport: The transport used by the client
|
|
208
|
+
instance.
|
|
209
|
+
"""
|
|
210
|
+
return self._transport
|
|
211
|
+
|
|
212
|
+
@staticmethod
|
|
213
|
+
def common_billing_account_path(
|
|
214
|
+
billing_account: str,
|
|
215
|
+
) -> str:
|
|
216
|
+
"""Returns a fully-qualified billing_account string."""
|
|
217
|
+
return "billingAccounts/{billing_account}".format(
|
|
218
|
+
billing_account=billing_account,
|
|
219
|
+
)
|
|
220
|
+
|
|
221
|
+
@staticmethod
|
|
222
|
+
def parse_common_billing_account_path(path: str) -> Dict[str, str]:
|
|
223
|
+
"""Parse a billing_account path into its component segments."""
|
|
224
|
+
m = re.match(r"^billingAccounts/(?P<billing_account>.+?)$", path)
|
|
225
|
+
return m.groupdict() if m else {}
|
|
226
|
+
|
|
227
|
+
@staticmethod
|
|
228
|
+
def common_folder_path(
|
|
229
|
+
folder: str,
|
|
230
|
+
) -> str:
|
|
231
|
+
"""Returns a fully-qualified folder string."""
|
|
232
|
+
return "folders/{folder}".format(
|
|
233
|
+
folder=folder,
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
@staticmethod
|
|
237
|
+
def parse_common_folder_path(path: str) -> Dict[str, str]:
|
|
238
|
+
"""Parse a folder path into its component segments."""
|
|
239
|
+
m = re.match(r"^folders/(?P<folder>.+?)$", path)
|
|
240
|
+
return m.groupdict() if m else {}
|
|
241
|
+
|
|
242
|
+
@staticmethod
|
|
243
|
+
def common_organization_path(
|
|
244
|
+
organization: str,
|
|
245
|
+
) -> str:
|
|
246
|
+
"""Returns a fully-qualified organization string."""
|
|
247
|
+
return "organizations/{organization}".format(
|
|
248
|
+
organization=organization,
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
@staticmethod
|
|
252
|
+
def parse_common_organization_path(path: str) -> Dict[str, str]:
|
|
253
|
+
"""Parse a organization path into its component segments."""
|
|
254
|
+
m = re.match(r"^organizations/(?P<organization>.+?)$", path)
|
|
255
|
+
return m.groupdict() if m else {}
|
|
256
|
+
|
|
257
|
+
@staticmethod
|
|
258
|
+
def common_project_path(
|
|
259
|
+
project: str,
|
|
260
|
+
) -> str:
|
|
261
|
+
"""Returns a fully-qualified project string."""
|
|
262
|
+
return "projects/{project}".format(
|
|
263
|
+
project=project,
|
|
264
|
+
)
|
|
265
|
+
|
|
266
|
+
@staticmethod
|
|
267
|
+
def parse_common_project_path(path: str) -> Dict[str, str]:
|
|
268
|
+
"""Parse a project path into its component segments."""
|
|
269
|
+
m = re.match(r"^projects/(?P<project>.+?)$", path)
|
|
270
|
+
return m.groupdict() if m else {}
|
|
271
|
+
|
|
272
|
+
@staticmethod
|
|
273
|
+
def common_location_path(
|
|
274
|
+
project: str,
|
|
275
|
+
location: str,
|
|
276
|
+
) -> str:
|
|
277
|
+
"""Returns a fully-qualified location string."""
|
|
278
|
+
return "projects/{project}/locations/{location}".format(
|
|
279
|
+
project=project,
|
|
280
|
+
location=location,
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
@staticmethod
|
|
284
|
+
def parse_common_location_path(path: str) -> Dict[str, str]:
|
|
285
|
+
"""Parse a location path into its component segments."""
|
|
286
|
+
m = re.match(r"^projects/(?P<project>.+?)/locations/(?P<location>.+?)$", path)
|
|
287
|
+
return m.groupdict() if m else {}
|
|
288
|
+
|
|
289
|
+
@classmethod
|
|
290
|
+
def get_mtls_endpoint_and_cert_source(
|
|
291
|
+
cls, client_options: Optional[client_options_lib.ClientOptions] = None
|
|
292
|
+
):
|
|
293
|
+
"""Deprecated. Return the API endpoint and client cert source for mutual TLS.
|
|
294
|
+
|
|
295
|
+
The client cert source is determined in the following order:
|
|
296
|
+
(1) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is not "true", the
|
|
297
|
+
client cert source is None.
|
|
298
|
+
(2) if `client_options.client_cert_source` is provided, use the provided one; if the
|
|
299
|
+
default client cert source exists, use the default one; otherwise the client cert
|
|
300
|
+
source is None.
|
|
301
|
+
|
|
302
|
+
The API endpoint is determined in the following order:
|
|
303
|
+
(1) if `client_options.api_endpoint` if provided, use the provided one.
|
|
304
|
+
(2) if `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is "always", use the
|
|
305
|
+
default mTLS endpoint; if the environment variable is "never", use the default API
|
|
306
|
+
endpoint; otherwise if client cert source exists, use the default mTLS endpoint, otherwise
|
|
307
|
+
use the default API endpoint.
|
|
308
|
+
|
|
309
|
+
More details can be found at https://google.aip.dev/auth/4114.
|
|
310
|
+
|
|
311
|
+
Args:
|
|
312
|
+
client_options (google.api_core.client_options.ClientOptions): Custom options for the
|
|
313
|
+
client. Only the `api_endpoint` and `client_cert_source` properties may be used
|
|
314
|
+
in this method.
|
|
315
|
+
|
|
316
|
+
Returns:
|
|
317
|
+
Tuple[str, Callable[[], Tuple[bytes, bytes]]]: returns the API endpoint and the
|
|
318
|
+
client cert source to use.
|
|
319
|
+
|
|
320
|
+
Raises:
|
|
321
|
+
google.auth.exceptions.MutualTLSChannelError: If any errors happen.
|
|
322
|
+
"""
|
|
323
|
+
|
|
324
|
+
warnings.warn(
|
|
325
|
+
"get_mtls_endpoint_and_cert_source is deprecated. Use the api_endpoint property instead.",
|
|
326
|
+
DeprecationWarning,
|
|
327
|
+
)
|
|
328
|
+
if client_options is None:
|
|
329
|
+
client_options = client_options_lib.ClientOptions()
|
|
330
|
+
use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")
|
|
331
|
+
use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto")
|
|
332
|
+
if use_client_cert not in ("true", "false"):
|
|
333
|
+
raise ValueError(
|
|
334
|
+
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
|
|
335
|
+
)
|
|
336
|
+
if use_mtls_endpoint not in ("auto", "never", "always"):
|
|
337
|
+
raise MutualTLSChannelError(
|
|
338
|
+
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
|
|
339
|
+
)
|
|
340
|
+
|
|
341
|
+
# Figure out the client cert source to use.
|
|
342
|
+
client_cert_source = None
|
|
343
|
+
if use_client_cert == "true":
|
|
344
|
+
if client_options.client_cert_source:
|
|
345
|
+
client_cert_source = client_options.client_cert_source
|
|
346
|
+
elif mtls.has_default_client_cert_source():
|
|
347
|
+
client_cert_source = mtls.default_client_cert_source()
|
|
348
|
+
|
|
349
|
+
# Figure out which api endpoint to use.
|
|
350
|
+
if client_options.api_endpoint is not None:
|
|
351
|
+
api_endpoint = client_options.api_endpoint
|
|
352
|
+
elif use_mtls_endpoint == "always" or (
|
|
353
|
+
use_mtls_endpoint == "auto" and client_cert_source
|
|
354
|
+
):
|
|
355
|
+
api_endpoint = cls.DEFAULT_MTLS_ENDPOINT
|
|
356
|
+
else:
|
|
357
|
+
api_endpoint = cls.DEFAULT_ENDPOINT
|
|
358
|
+
|
|
359
|
+
return api_endpoint, client_cert_source
|
|
360
|
+
|
|
361
|
+
@staticmethod
|
|
362
|
+
def _read_environment_variables():
|
|
363
|
+
"""Returns the environment variables used by the client.
|
|
364
|
+
|
|
365
|
+
Returns:
|
|
366
|
+
Tuple[bool, str, str]: returns the GOOGLE_API_USE_CLIENT_CERTIFICATE,
|
|
367
|
+
GOOGLE_API_USE_MTLS_ENDPOINT, and GOOGLE_CLOUD_UNIVERSE_DOMAIN environment variables.
|
|
368
|
+
|
|
369
|
+
Raises:
|
|
370
|
+
ValueError: If GOOGLE_API_USE_CLIENT_CERTIFICATE is not
|
|
371
|
+
any of ["true", "false"].
|
|
372
|
+
google.auth.exceptions.MutualTLSChannelError: If GOOGLE_API_USE_MTLS_ENDPOINT
|
|
373
|
+
is not any of ["auto", "never", "always"].
|
|
374
|
+
"""
|
|
375
|
+
use_client_cert = os.getenv(
|
|
376
|
+
"GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"
|
|
377
|
+
).lower()
|
|
378
|
+
use_mtls_endpoint = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto").lower()
|
|
379
|
+
universe_domain_env = os.getenv("GOOGLE_CLOUD_UNIVERSE_DOMAIN")
|
|
380
|
+
if use_client_cert not in ("true", "false"):
|
|
381
|
+
raise ValueError(
|
|
382
|
+
"Environment variable `GOOGLE_API_USE_CLIENT_CERTIFICATE` must be either `true` or `false`"
|
|
383
|
+
)
|
|
384
|
+
if use_mtls_endpoint not in ("auto", "never", "always"):
|
|
385
|
+
raise MutualTLSChannelError(
|
|
386
|
+
"Environment variable `GOOGLE_API_USE_MTLS_ENDPOINT` must be `never`, `auto` or `always`"
|
|
387
|
+
)
|
|
388
|
+
return use_client_cert == "true", use_mtls_endpoint, universe_domain_env
|
|
389
|
+
|
|
390
|
+
@staticmethod
|
|
391
|
+
def _get_client_cert_source(provided_cert_source, use_cert_flag):
|
|
392
|
+
"""Return the client cert source to be used by the client.
|
|
393
|
+
|
|
394
|
+
Args:
|
|
395
|
+
provided_cert_source (bytes): The client certificate source provided.
|
|
396
|
+
use_cert_flag (bool): A flag indicating whether to use the client certificate.
|
|
397
|
+
|
|
398
|
+
Returns:
|
|
399
|
+
bytes or None: The client cert source to be used by the client.
|
|
400
|
+
"""
|
|
401
|
+
client_cert_source = None
|
|
402
|
+
if use_cert_flag:
|
|
403
|
+
if provided_cert_source:
|
|
404
|
+
client_cert_source = provided_cert_source
|
|
405
|
+
elif mtls.has_default_client_cert_source():
|
|
406
|
+
client_cert_source = mtls.default_client_cert_source()
|
|
407
|
+
return client_cert_source
|
|
408
|
+
|
|
409
|
+
@staticmethod
|
|
410
|
+
def _get_api_endpoint(
|
|
411
|
+
api_override, client_cert_source, universe_domain, use_mtls_endpoint
|
|
412
|
+
):
|
|
413
|
+
"""Return the API endpoint used by the client.
|
|
414
|
+
|
|
415
|
+
Args:
|
|
416
|
+
api_override (str): The API endpoint override. If specified, this is always
|
|
417
|
+
the return value of this function and the other arguments are not used.
|
|
418
|
+
client_cert_source (bytes): The client certificate source used by the client.
|
|
419
|
+
universe_domain (str): The universe domain used by the client.
|
|
420
|
+
use_mtls_endpoint (str): How to use the mTLS endpoint, which depends also on the other parameters.
|
|
421
|
+
Possible values are "always", "auto", or "never".
|
|
422
|
+
|
|
423
|
+
Returns:
|
|
424
|
+
str: The API endpoint to be used by the client.
|
|
425
|
+
"""
|
|
426
|
+
if api_override is not None:
|
|
427
|
+
api_endpoint = api_override
|
|
428
|
+
elif use_mtls_endpoint == "always" or (
|
|
429
|
+
use_mtls_endpoint == "auto" and client_cert_source
|
|
430
|
+
):
|
|
431
|
+
_default_universe = RouteOptimizationClient._DEFAULT_UNIVERSE
|
|
432
|
+
if universe_domain != _default_universe:
|
|
433
|
+
raise MutualTLSChannelError(
|
|
434
|
+
f"mTLS is not supported in any universe other than {_default_universe}."
|
|
435
|
+
)
|
|
436
|
+
api_endpoint = RouteOptimizationClient.DEFAULT_MTLS_ENDPOINT
|
|
437
|
+
else:
|
|
438
|
+
api_endpoint = RouteOptimizationClient._DEFAULT_ENDPOINT_TEMPLATE.format(
|
|
439
|
+
UNIVERSE_DOMAIN=universe_domain
|
|
440
|
+
)
|
|
441
|
+
return api_endpoint
|
|
442
|
+
|
|
443
|
+
@staticmethod
|
|
444
|
+
def _get_universe_domain(
|
|
445
|
+
client_universe_domain: Optional[str], universe_domain_env: Optional[str]
|
|
446
|
+
) -> str:
|
|
447
|
+
"""Return the universe domain used by the client.
|
|
448
|
+
|
|
449
|
+
Args:
|
|
450
|
+
client_universe_domain (Optional[str]): The universe domain configured via the client options.
|
|
451
|
+
universe_domain_env (Optional[str]): The universe domain configured via the "GOOGLE_CLOUD_UNIVERSE_DOMAIN" environment variable.
|
|
452
|
+
|
|
453
|
+
Returns:
|
|
454
|
+
str: The universe domain to be used by the client.
|
|
455
|
+
|
|
456
|
+
Raises:
|
|
457
|
+
ValueError: If the universe domain is an empty string.
|
|
458
|
+
"""
|
|
459
|
+
universe_domain = RouteOptimizationClient._DEFAULT_UNIVERSE
|
|
460
|
+
if client_universe_domain is not None:
|
|
461
|
+
universe_domain = client_universe_domain
|
|
462
|
+
elif universe_domain_env is not None:
|
|
463
|
+
universe_domain = universe_domain_env
|
|
464
|
+
if len(universe_domain.strip()) == 0:
|
|
465
|
+
raise ValueError("Universe Domain cannot be an empty string.")
|
|
466
|
+
return universe_domain
|
|
467
|
+
|
|
468
|
+
@staticmethod
|
|
469
|
+
def _compare_universes(
|
|
470
|
+
client_universe: str, credentials: ga_credentials.Credentials
|
|
471
|
+
) -> bool:
|
|
472
|
+
"""Returns True iff the universe domains used by the client and credentials match.
|
|
473
|
+
|
|
474
|
+
Args:
|
|
475
|
+
client_universe (str): The universe domain configured via the client options.
|
|
476
|
+
credentials (ga_credentials.Credentials): The credentials being used in the client.
|
|
477
|
+
|
|
478
|
+
Returns:
|
|
479
|
+
bool: True iff client_universe matches the universe in credentials.
|
|
480
|
+
|
|
481
|
+
Raises:
|
|
482
|
+
ValueError: when client_universe does not match the universe in credentials.
|
|
483
|
+
"""
|
|
484
|
+
|
|
485
|
+
default_universe = RouteOptimizationClient._DEFAULT_UNIVERSE
|
|
486
|
+
credentials_universe = getattr(credentials, "universe_domain", default_universe)
|
|
487
|
+
|
|
488
|
+
if client_universe != credentials_universe:
|
|
489
|
+
raise ValueError(
|
|
490
|
+
"The configured universe domain "
|
|
491
|
+
f"({client_universe}) does not match the universe domain "
|
|
492
|
+
f"found in the credentials ({credentials_universe}). "
|
|
493
|
+
"If you haven't configured the universe domain explicitly, "
|
|
494
|
+
f"`{default_universe}` is the default."
|
|
495
|
+
)
|
|
496
|
+
return True
|
|
497
|
+
|
|
498
|
+
def _validate_universe_domain(self):
|
|
499
|
+
"""Validates client's and credentials' universe domains are consistent.
|
|
500
|
+
|
|
501
|
+
Returns:
|
|
502
|
+
bool: True iff the configured universe domain is valid.
|
|
503
|
+
|
|
504
|
+
Raises:
|
|
505
|
+
ValueError: If the configured universe domain is not valid.
|
|
506
|
+
"""
|
|
507
|
+
self._is_universe_domain_valid = (
|
|
508
|
+
self._is_universe_domain_valid
|
|
509
|
+
or RouteOptimizationClient._compare_universes(
|
|
510
|
+
self.universe_domain, self.transport._credentials
|
|
511
|
+
)
|
|
512
|
+
)
|
|
513
|
+
return self._is_universe_domain_valid
|
|
514
|
+
|
|
515
|
+
@property
|
|
516
|
+
def api_endpoint(self):
|
|
517
|
+
"""Return the API endpoint used by the client instance.
|
|
518
|
+
|
|
519
|
+
Returns:
|
|
520
|
+
str: The API endpoint used by the client instance.
|
|
521
|
+
"""
|
|
522
|
+
return self._api_endpoint
|
|
523
|
+
|
|
524
|
+
@property
|
|
525
|
+
def universe_domain(self) -> str:
|
|
526
|
+
"""Return the universe domain used by the client instance.
|
|
527
|
+
|
|
528
|
+
Returns:
|
|
529
|
+
str: The universe domain used by the client instance.
|
|
530
|
+
"""
|
|
531
|
+
return self._universe_domain
|
|
532
|
+
|
|
533
|
+
def __init__(
|
|
534
|
+
self,
|
|
535
|
+
*,
|
|
536
|
+
credentials: Optional[ga_credentials.Credentials] = None,
|
|
537
|
+
transport: Optional[
|
|
538
|
+
Union[
|
|
539
|
+
str,
|
|
540
|
+
RouteOptimizationTransport,
|
|
541
|
+
Callable[..., RouteOptimizationTransport],
|
|
542
|
+
]
|
|
543
|
+
] = None,
|
|
544
|
+
client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
|
|
545
|
+
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
|
|
546
|
+
) -> None:
|
|
547
|
+
"""Instantiates the route optimization client.
|
|
548
|
+
|
|
549
|
+
Args:
|
|
550
|
+
credentials (Optional[google.auth.credentials.Credentials]): The
|
|
551
|
+
authorization credentials to attach to requests. These
|
|
552
|
+
credentials identify the application to the service; if none
|
|
553
|
+
are specified, the client will attempt to ascertain the
|
|
554
|
+
credentials from the environment.
|
|
555
|
+
transport (Optional[Union[str,RouteOptimizationTransport,Callable[..., RouteOptimizationTransport]]]):
|
|
556
|
+
The transport to use, or a Callable that constructs and returns a new transport.
|
|
557
|
+
If a Callable is given, it will be called with the same set of initialization
|
|
558
|
+
arguments as used in the RouteOptimizationTransport constructor.
|
|
559
|
+
If set to None, a transport is chosen automatically.
|
|
560
|
+
client_options (Optional[Union[google.api_core.client_options.ClientOptions, dict]]):
|
|
561
|
+
Custom options for the client.
|
|
562
|
+
|
|
563
|
+
1. The ``api_endpoint`` property can be used to override the
|
|
564
|
+
default endpoint provided by the client when ``transport`` is
|
|
565
|
+
not explicitly provided. Only if this property is not set and
|
|
566
|
+
``transport`` was not explicitly provided, the endpoint is
|
|
567
|
+
determined by the GOOGLE_API_USE_MTLS_ENDPOINT environment
|
|
568
|
+
variable, which have one of the following values:
|
|
569
|
+
"always" (always use the default mTLS endpoint), "never" (always
|
|
570
|
+
use the default regular endpoint) and "auto" (auto-switch to the
|
|
571
|
+
default mTLS endpoint if client certificate is present; this is
|
|
572
|
+
the default value).
|
|
573
|
+
|
|
574
|
+
2. If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable
|
|
575
|
+
is "true", then the ``client_cert_source`` property can be used
|
|
576
|
+
to provide a client certificate for mTLS transport. If
|
|
577
|
+
not provided, the default SSL client certificate will be used if
|
|
578
|
+
present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not
|
|
579
|
+
set, no client certificate will be used.
|
|
580
|
+
|
|
581
|
+
3. The ``universe_domain`` property can be used to override the
|
|
582
|
+
default "googleapis.com" universe. Note that the ``api_endpoint``
|
|
583
|
+
property still takes precedence; and ``universe_domain`` is
|
|
584
|
+
currently not supported for mTLS.
|
|
585
|
+
|
|
586
|
+
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
|
|
587
|
+
The client info used to send a user-agent string along with
|
|
588
|
+
API requests. If ``None``, then default info will be used.
|
|
589
|
+
Generally, you only need to set this if you're developing
|
|
590
|
+
your own client library.
|
|
591
|
+
|
|
592
|
+
Raises:
|
|
593
|
+
google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport
|
|
594
|
+
creation failed for any reason.
|
|
595
|
+
"""
|
|
596
|
+
self._client_options = client_options
|
|
597
|
+
if isinstance(self._client_options, dict):
|
|
598
|
+
self._client_options = client_options_lib.from_dict(self._client_options)
|
|
599
|
+
if self._client_options is None:
|
|
600
|
+
self._client_options = client_options_lib.ClientOptions()
|
|
601
|
+
self._client_options = cast(
|
|
602
|
+
client_options_lib.ClientOptions, self._client_options
|
|
603
|
+
)
|
|
604
|
+
|
|
605
|
+
universe_domain_opt = getattr(self._client_options, "universe_domain", None)
|
|
606
|
+
|
|
607
|
+
(
|
|
608
|
+
self._use_client_cert,
|
|
609
|
+
self._use_mtls_endpoint,
|
|
610
|
+
self._universe_domain_env,
|
|
611
|
+
) = RouteOptimizationClient._read_environment_variables()
|
|
612
|
+
self._client_cert_source = RouteOptimizationClient._get_client_cert_source(
|
|
613
|
+
self._client_options.client_cert_source, self._use_client_cert
|
|
614
|
+
)
|
|
615
|
+
self._universe_domain = RouteOptimizationClient._get_universe_domain(
|
|
616
|
+
universe_domain_opt, self._universe_domain_env
|
|
617
|
+
)
|
|
618
|
+
self._api_endpoint = None # updated below, depending on `transport`
|
|
619
|
+
|
|
620
|
+
# Initialize the universe domain validation.
|
|
621
|
+
self._is_universe_domain_valid = False
|
|
622
|
+
|
|
623
|
+
api_key_value = getattr(self._client_options, "api_key", None)
|
|
624
|
+
if api_key_value and credentials:
|
|
625
|
+
raise ValueError(
|
|
626
|
+
"client_options.api_key and credentials are mutually exclusive"
|
|
627
|
+
)
|
|
628
|
+
|
|
629
|
+
# Save or instantiate the transport.
|
|
630
|
+
# Ordinarily, we provide the transport, but allowing a custom transport
|
|
631
|
+
# instance provides an extensibility point for unusual situations.
|
|
632
|
+
transport_provided = isinstance(transport, RouteOptimizationTransport)
|
|
633
|
+
if transport_provided:
|
|
634
|
+
# transport is a RouteOptimizationTransport instance.
|
|
635
|
+
if credentials or self._client_options.credentials_file or api_key_value:
|
|
636
|
+
raise ValueError(
|
|
637
|
+
"When providing a transport instance, "
|
|
638
|
+
"provide its credentials directly."
|
|
639
|
+
)
|
|
640
|
+
if self._client_options.scopes:
|
|
641
|
+
raise ValueError(
|
|
642
|
+
"When providing a transport instance, provide its scopes "
|
|
643
|
+
"directly."
|
|
644
|
+
)
|
|
645
|
+
self._transport = cast(RouteOptimizationTransport, transport)
|
|
646
|
+
self._api_endpoint = self._transport.host
|
|
647
|
+
|
|
648
|
+
self._api_endpoint = (
|
|
649
|
+
self._api_endpoint
|
|
650
|
+
or RouteOptimizationClient._get_api_endpoint(
|
|
651
|
+
self._client_options.api_endpoint,
|
|
652
|
+
self._client_cert_source,
|
|
653
|
+
self._universe_domain,
|
|
654
|
+
self._use_mtls_endpoint,
|
|
655
|
+
)
|
|
656
|
+
)
|
|
657
|
+
|
|
658
|
+
if not transport_provided:
|
|
659
|
+
import google.auth._default # type: ignore
|
|
660
|
+
|
|
661
|
+
if api_key_value and hasattr(
|
|
662
|
+
google.auth._default, "get_api_key_credentials"
|
|
663
|
+
):
|
|
664
|
+
credentials = google.auth._default.get_api_key_credentials(
|
|
665
|
+
api_key_value
|
|
666
|
+
)
|
|
667
|
+
|
|
668
|
+
transport_init: Union[
|
|
669
|
+
Type[RouteOptimizationTransport],
|
|
670
|
+
Callable[..., RouteOptimizationTransport],
|
|
671
|
+
] = (
|
|
672
|
+
type(self).get_transport_class(transport)
|
|
673
|
+
if isinstance(transport, str) or transport is None
|
|
674
|
+
else cast(Callable[..., RouteOptimizationTransport], transport)
|
|
675
|
+
)
|
|
676
|
+
# initialize with the provided callable or the passed in class
|
|
677
|
+
self._transport = transport_init(
|
|
678
|
+
credentials=credentials,
|
|
679
|
+
credentials_file=self._client_options.credentials_file,
|
|
680
|
+
host=self._api_endpoint,
|
|
681
|
+
scopes=self._client_options.scopes,
|
|
682
|
+
client_cert_source_for_mtls=self._client_cert_source,
|
|
683
|
+
quota_project_id=self._client_options.quota_project_id,
|
|
684
|
+
client_info=client_info,
|
|
685
|
+
always_use_jwt_access=True,
|
|
686
|
+
api_audience=self._client_options.api_audience,
|
|
687
|
+
)
|
|
688
|
+
|
|
689
|
+
def optimize_tours(
|
|
690
|
+
self,
|
|
691
|
+
request: Optional[
|
|
692
|
+
Union[route_optimization_service.OptimizeToursRequest, dict]
|
|
693
|
+
] = None,
|
|
694
|
+
*,
|
|
695
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
696
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
697
|
+
metadata: Sequence[Tuple[str, str]] = (),
|
|
698
|
+
) -> route_optimization_service.OptimizeToursResponse:
|
|
699
|
+
r"""Sends an ``OptimizeToursRequest`` containing a ``ShipmentModel``
|
|
700
|
+
and returns an ``OptimizeToursResponse`` containing
|
|
701
|
+
``ShipmentRoute``\ s, which are a set of routes to be performed
|
|
702
|
+
by vehicles minimizing the overall cost.
|
|
703
|
+
|
|
704
|
+
A ``ShipmentModel`` model consists mainly of ``Shipment``\ s
|
|
705
|
+
that need to be carried out and ``Vehicle``\ s that can be used
|
|
706
|
+
to transport the ``Shipment``\ s. The ``ShipmentRoute``\ s
|
|
707
|
+
assign ``Shipment``\ s to ``Vehicle``\ s. More specifically,
|
|
708
|
+
they assign a series of ``Visit``\ s to each vehicle, where a
|
|
709
|
+
``Visit`` corresponds to a ``VisitRequest``, which is a pickup
|
|
710
|
+
or delivery for a ``Shipment``.
|
|
711
|
+
|
|
712
|
+
The goal is to provide an assignment of ``ShipmentRoute``\ s to
|
|
713
|
+
``Vehicle``\ s that minimizes the total cost where cost has many
|
|
714
|
+
components defined in the ``ShipmentModel``.
|
|
715
|
+
|
|
716
|
+
.. code-block:: python
|
|
717
|
+
|
|
718
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
719
|
+
# code template only.
|
|
720
|
+
# It will require modifications to work:
|
|
721
|
+
# - It may require correct/in-range values for request initialization.
|
|
722
|
+
# - It may require specifying regional endpoints when creating the service
|
|
723
|
+
# client as shown in:
|
|
724
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
725
|
+
from google.maps import routeoptimization_v1
|
|
726
|
+
|
|
727
|
+
def sample_optimize_tours():
|
|
728
|
+
# Create a client
|
|
729
|
+
client = routeoptimization_v1.RouteOptimizationClient()
|
|
730
|
+
|
|
731
|
+
# Initialize request argument(s)
|
|
732
|
+
request = routeoptimization_v1.OptimizeToursRequest(
|
|
733
|
+
parent="parent_value",
|
|
734
|
+
)
|
|
735
|
+
|
|
736
|
+
# Make the request
|
|
737
|
+
response = client.optimize_tours(request=request)
|
|
738
|
+
|
|
739
|
+
# Handle the response
|
|
740
|
+
print(response)
|
|
741
|
+
|
|
742
|
+
Args:
|
|
743
|
+
request (Union[google.maps.routeoptimization_v1.types.OptimizeToursRequest, dict]):
|
|
744
|
+
The request object. Request to be given to a tour
|
|
745
|
+
optimization solver which defines the
|
|
746
|
+
shipment model to solve as well as
|
|
747
|
+
optimization parameters.
|
|
748
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
749
|
+
should be retried.
|
|
750
|
+
timeout (float): The timeout for this request.
|
|
751
|
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
|
752
|
+
sent along with the request as metadata.
|
|
753
|
+
|
|
754
|
+
Returns:
|
|
755
|
+
google.maps.routeoptimization_v1.types.OptimizeToursResponse:
|
|
756
|
+
Response after solving a tour
|
|
757
|
+
optimization problem containing the
|
|
758
|
+
routes followed by each vehicle, the
|
|
759
|
+
shipments which have been skipped and
|
|
760
|
+
the overall cost of the solution.
|
|
761
|
+
|
|
762
|
+
"""
|
|
763
|
+
# Create or coerce a protobuf request object.
|
|
764
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
765
|
+
# there are no flattened fields), or create one.
|
|
766
|
+
if not isinstance(request, route_optimization_service.OptimizeToursRequest):
|
|
767
|
+
request = route_optimization_service.OptimizeToursRequest(request)
|
|
768
|
+
|
|
769
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
770
|
+
# and friendly error handling.
|
|
771
|
+
rpc = self._transport._wrapped_methods[self._transport.optimize_tours]
|
|
772
|
+
|
|
773
|
+
# Certain fields should be provided within the metadata header;
|
|
774
|
+
# add these here.
|
|
775
|
+
metadata = tuple(metadata) + (
|
|
776
|
+
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
|
|
777
|
+
)
|
|
778
|
+
|
|
779
|
+
# Validate the universe domain.
|
|
780
|
+
self._validate_universe_domain()
|
|
781
|
+
|
|
782
|
+
# Send the request.
|
|
783
|
+
response = rpc(
|
|
784
|
+
request,
|
|
785
|
+
retry=retry,
|
|
786
|
+
timeout=timeout,
|
|
787
|
+
metadata=metadata,
|
|
788
|
+
)
|
|
789
|
+
|
|
790
|
+
# Done; return the response.
|
|
791
|
+
return response
|
|
792
|
+
|
|
793
|
+
def batch_optimize_tours(
|
|
794
|
+
self,
|
|
795
|
+
request: Optional[
|
|
796
|
+
Union[route_optimization_service.BatchOptimizeToursRequest, dict]
|
|
797
|
+
] = None,
|
|
798
|
+
*,
|
|
799
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
800
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
801
|
+
metadata: Sequence[Tuple[str, str]] = (),
|
|
802
|
+
) -> operation.Operation:
|
|
803
|
+
r"""Optimizes vehicle tours for one or more ``OptimizeToursRequest``
|
|
804
|
+
messages as a batch.
|
|
805
|
+
|
|
806
|
+
This method is a Long Running Operation (LRO). The inputs for
|
|
807
|
+
optimization (``OptimizeToursRequest`` messages) and outputs
|
|
808
|
+
(``OptimizeToursResponse`` messages) are read/written from/to
|
|
809
|
+
Cloud Storage in user-specified format. Like the
|
|
810
|
+
``OptimizeTours`` method, each ``OptimizeToursRequest`` contains
|
|
811
|
+
a ``ShipmentModel`` and returns an ``OptimizeToursResponse``
|
|
812
|
+
containing ``ShipmentRoute``\ s, which are a set of routes to be
|
|
813
|
+
performed by vehicles minimizing the overall cost.
|
|
814
|
+
|
|
815
|
+
.. code-block:: python
|
|
816
|
+
|
|
817
|
+
# This snippet has been automatically generated and should be regarded as a
|
|
818
|
+
# code template only.
|
|
819
|
+
# It will require modifications to work:
|
|
820
|
+
# - It may require correct/in-range values for request initialization.
|
|
821
|
+
# - It may require specifying regional endpoints when creating the service
|
|
822
|
+
# client as shown in:
|
|
823
|
+
# https://googleapis.dev/python/google-api-core/latest/client_options.html
|
|
824
|
+
from google.maps import routeoptimization_v1
|
|
825
|
+
|
|
826
|
+
def sample_batch_optimize_tours():
|
|
827
|
+
# Create a client
|
|
828
|
+
client = routeoptimization_v1.RouteOptimizationClient()
|
|
829
|
+
|
|
830
|
+
# Initialize request argument(s)
|
|
831
|
+
model_configs = routeoptimization_v1.AsyncModelConfig()
|
|
832
|
+
model_configs.input_config.gcs_source.uri = "uri_value"
|
|
833
|
+
model_configs.input_config.data_format = "PROTO_TEXT"
|
|
834
|
+
model_configs.output_config.gcs_destination.uri = "uri_value"
|
|
835
|
+
model_configs.output_config.data_format = "PROTO_TEXT"
|
|
836
|
+
|
|
837
|
+
request = routeoptimization_v1.BatchOptimizeToursRequest(
|
|
838
|
+
parent="parent_value",
|
|
839
|
+
model_configs=model_configs,
|
|
840
|
+
)
|
|
841
|
+
|
|
842
|
+
# Make the request
|
|
843
|
+
operation = client.batch_optimize_tours(request=request)
|
|
844
|
+
|
|
845
|
+
print("Waiting for operation to complete...")
|
|
846
|
+
|
|
847
|
+
response = operation.result()
|
|
848
|
+
|
|
849
|
+
# Handle the response
|
|
850
|
+
print(response)
|
|
851
|
+
|
|
852
|
+
Args:
|
|
853
|
+
request (Union[google.maps.routeoptimization_v1.types.BatchOptimizeToursRequest, dict]):
|
|
854
|
+
The request object. Request to batch optimize tours as an asynchronous
|
|
855
|
+
operation. Each input file should contain one
|
|
856
|
+
``OptimizeToursRequest``, and each output file will
|
|
857
|
+
contain one ``OptimizeToursResponse``. The request
|
|
858
|
+
contains information to read/write and parse the files.
|
|
859
|
+
All the input and output files should be under the same
|
|
860
|
+
project.
|
|
861
|
+
retry (google.api_core.retry.Retry): Designation of what errors, if any,
|
|
862
|
+
should be retried.
|
|
863
|
+
timeout (float): The timeout for this request.
|
|
864
|
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
|
865
|
+
sent along with the request as metadata.
|
|
866
|
+
|
|
867
|
+
Returns:
|
|
868
|
+
google.api_core.operation.Operation:
|
|
869
|
+
An object representing a long-running operation.
|
|
870
|
+
|
|
871
|
+
The result type for the operation will be :class:`google.maps.routeoptimization_v1.types.BatchOptimizeToursResponse` Response to a BatchOptimizeToursRequest. This is returned in
|
|
872
|
+
the Long Running Operation after the operation is
|
|
873
|
+
complete.
|
|
874
|
+
|
|
875
|
+
"""
|
|
876
|
+
# Create or coerce a protobuf request object.
|
|
877
|
+
# - Use the request object if provided (there's no risk of modifying the input as
|
|
878
|
+
# there are no flattened fields), or create one.
|
|
879
|
+
if not isinstance(
|
|
880
|
+
request, route_optimization_service.BatchOptimizeToursRequest
|
|
881
|
+
):
|
|
882
|
+
request = route_optimization_service.BatchOptimizeToursRequest(request)
|
|
883
|
+
|
|
884
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
885
|
+
# and friendly error handling.
|
|
886
|
+
rpc = self._transport._wrapped_methods[self._transport.batch_optimize_tours]
|
|
887
|
+
|
|
888
|
+
# Certain fields should be provided within the metadata header;
|
|
889
|
+
# add these here.
|
|
890
|
+
metadata = tuple(metadata) + (
|
|
891
|
+
gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)),
|
|
892
|
+
)
|
|
893
|
+
|
|
894
|
+
# Validate the universe domain.
|
|
895
|
+
self._validate_universe_domain()
|
|
896
|
+
|
|
897
|
+
# Send the request.
|
|
898
|
+
response = rpc(
|
|
899
|
+
request,
|
|
900
|
+
retry=retry,
|
|
901
|
+
timeout=timeout,
|
|
902
|
+
metadata=metadata,
|
|
903
|
+
)
|
|
904
|
+
|
|
905
|
+
# Wrap the response in an operation future.
|
|
906
|
+
response = operation.from_gapic(
|
|
907
|
+
response,
|
|
908
|
+
self._transport.operations_client,
|
|
909
|
+
route_optimization_service.BatchOptimizeToursResponse,
|
|
910
|
+
metadata_type=route_optimization_service.BatchOptimizeToursMetadata,
|
|
911
|
+
)
|
|
912
|
+
|
|
913
|
+
# Done; return the response.
|
|
914
|
+
return response
|
|
915
|
+
|
|
916
|
+
def __enter__(self) -> "RouteOptimizationClient":
|
|
917
|
+
return self
|
|
918
|
+
|
|
919
|
+
def __exit__(self, type, value, traceback):
|
|
920
|
+
"""Releases underlying transport's resources.
|
|
921
|
+
|
|
922
|
+
.. warning::
|
|
923
|
+
ONLY use as a context manager if the transport is NOT shared
|
|
924
|
+
with other clients! Exiting the with block will CLOSE the transport
|
|
925
|
+
and may cause errors in other clients!
|
|
926
|
+
"""
|
|
927
|
+
self.transport.close()
|
|
928
|
+
|
|
929
|
+
def get_operation(
|
|
930
|
+
self,
|
|
931
|
+
request: Optional[operations_pb2.GetOperationRequest] = None,
|
|
932
|
+
*,
|
|
933
|
+
retry: OptionalRetry = gapic_v1.method.DEFAULT,
|
|
934
|
+
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
|
|
935
|
+
metadata: Sequence[Tuple[str, str]] = (),
|
|
936
|
+
) -> operations_pb2.Operation:
|
|
937
|
+
r"""Gets the latest state of a long-running operation.
|
|
938
|
+
|
|
939
|
+
Args:
|
|
940
|
+
request (:class:`~.operations_pb2.GetOperationRequest`):
|
|
941
|
+
The request object. Request message for
|
|
942
|
+
`GetOperation` method.
|
|
943
|
+
retry (google.api_core.retry.Retry): Designation of what errors,
|
|
944
|
+
if any, should be retried.
|
|
945
|
+
timeout (float): The timeout for this request.
|
|
946
|
+
metadata (Sequence[Tuple[str, str]]): Strings which should be
|
|
947
|
+
sent along with the request as metadata.
|
|
948
|
+
Returns:
|
|
949
|
+
~.operations_pb2.Operation:
|
|
950
|
+
An ``Operation`` object.
|
|
951
|
+
"""
|
|
952
|
+
# Create or coerce a protobuf request object.
|
|
953
|
+
# The request isn't a proto-plus wrapped type,
|
|
954
|
+
# so it must be constructed via keyword expansion.
|
|
955
|
+
if isinstance(request, dict):
|
|
956
|
+
request = operations_pb2.GetOperationRequest(**request)
|
|
957
|
+
|
|
958
|
+
# Wrap the RPC method; this adds retry and timeout information,
|
|
959
|
+
# and friendly error handling.
|
|
960
|
+
rpc = gapic_v1.method.wrap_method(
|
|
961
|
+
self._transport.get_operation,
|
|
962
|
+
default_timeout=None,
|
|
963
|
+
client_info=DEFAULT_CLIENT_INFO,
|
|
964
|
+
)
|
|
965
|
+
|
|
966
|
+
# Certain fields should be provided within the metadata header;
|
|
967
|
+
# add these here.
|
|
968
|
+
metadata = tuple(metadata) + (
|
|
969
|
+
gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)),
|
|
970
|
+
)
|
|
971
|
+
|
|
972
|
+
# Validate the universe domain.
|
|
973
|
+
self._validate_universe_domain()
|
|
974
|
+
|
|
975
|
+
# Send the request.
|
|
976
|
+
response = rpc(
|
|
977
|
+
request,
|
|
978
|
+
retry=retry,
|
|
979
|
+
timeout=timeout,
|
|
980
|
+
metadata=metadata,
|
|
981
|
+
)
|
|
982
|
+
|
|
983
|
+
# Done; return the response.
|
|
984
|
+
return response
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
|
|
988
|
+
gapic_version=package_version.__version__
|
|
989
|
+
)
|
|
990
|
+
|
|
991
|
+
|
|
992
|
+
__all__ = ("RouteOptimizationClient",)
|