From dc2172fa8c540efca01c81fdd7f40880e087f66d Mon Sep 17 00:00:00 2001 From: Yoshi Automation Bot Date: Thu, 29 Oct 2020 08:18:02 -0700 Subject: [PATCH] fix!: update package names to avoid conflict with google-cloud-bigquery (#47) BREAKING CHANGE: update package names to avoid conflict with google-cloud-bigquery The google-cloud-bigquery package uses the `google.cloud.bigquery` path as a plain Python module, not a namespace package. When this package and google-cloud-bigquery are installed in the same environment, conflicts can result. This PR was generated using Autosynth. :rainbow: Synth log will be available here: https://source.cloud.google.com/results/invocations/efdacdcf-4630-4d74-9bea-5ef6df381d38/targets - [ ] To automatically regenerate this PR, check this box. PiperOrigin-RevId: 339531446 Source-Link: https://github.com/googleapis/googleapis/commit/ab0498dc4bd2bcfcb70ab257e8edfa00f86083a6 PiperOrigin-RevId: 339048690 Source-Link: https://github.com/googleapis/googleapis/commit/3c8c2d81369c4665824b20706426b018507415f7 PiperOrigin-RevId: 338646463 Source-Link: https://github.com/googleapis/googleapis/commit/20b11dfe4538cd5da7b4c3dd7d2bf5b9922ff3ed PiperOrigin-RevId: 327026955 Source-Link: https://github.com/googleapis/googleapis/commit/0dc0a6c0f1a9f979bc0690f0caa5fbafa3000c2c --- .../services.rst | 2 +- .../types.rst | 2 +- docs/index.rst | 4 +- .../reservation_service/async_client.py | 1 + .../services/reservation_service/client.py | 1 + .../__init__.py | 60 +- .../py.typed | 0 .../__init__.py | 0 .../py.typed | 0 .../services/__init__.py | 0 .../services/reservation_service/__init__.py | 0 .../reservation_service/async_client.py | 1971 +++++++++++++++ .../services/reservation_service/client.py | 2155 +++++++++++++++++ .../services/reservation_service/pagers.py | 2 +- .../transports/__init__.py | 0 .../reservation_service/transports/base.py | 136 +- .../reservation_service/transports/grpc.py | 4 +- .../transports/grpc_asyncio.py | 4 +- .../types/__init__.py | 0 .../types/reservation.py | 0 ...fixup_bigquery_reservation_v1_keywords.py} | 6 +- synth.metadata | 47 +- .../__init__.py | 0 .../test_reservation_service.py | 20 +- 24 files changed, 4319 insertions(+), 96 deletions(-) rename docs/{reservation_v1 => bigquery_reservation_v1}/services.rst (72%) rename docs/{reservation_v1 => bigquery_reservation_v1}/types.rst (70%) rename google/cloud/{bigquery/reservation => bigquery_reservation}/__init__.py (58%) rename google/cloud/{bigquery/reservation => bigquery_reservation}/py.typed (100%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/__init__.py (100%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/py.typed (100%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/services/__init__.py (100%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/services/reservation_service/__init__.py (100%) create mode 100644 google/cloud/bigquery_reservation_v1/services/reservation_service/async_client.py create mode 100644 google/cloud/bigquery_reservation_v1/services/reservation_service/client.py rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/services/reservation_service/pagers.py (99%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/services/reservation_service/transports/__init__.py (100%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/services/reservation_service/transports/base.py (72%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/services/reservation_service/transports/grpc.py (99%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/services/reservation_service/transports/grpc_asyncio.py (99%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/types/__init__.py (100%) rename google/cloud/{bigquery/reservation_v1 => bigquery_reservation_v1}/types/reservation.py (100%) rename scripts/{fixup_reservation_v1_keywords.py => fixup_bigquery_reservation_v1_keywords.py} (97%) rename tests/unit/gapic/{reservation_v1 => bigquery_reservation_v1}/__init__.py (100%) rename tests/unit/gapic/{reservation_v1 => bigquery_reservation_v1}/test_reservation_service.py (99%) diff --git a/docs/reservation_v1/services.rst b/docs/bigquery_reservation_v1/services.rst similarity index 72% rename from docs/reservation_v1/services.rst rename to docs/bigquery_reservation_v1/services.rst index d573d08d..b2601c3b 100644 --- a/docs/reservation_v1/services.rst +++ b/docs/bigquery_reservation_v1/services.rst @@ -1,6 +1,6 @@ Services for Google Cloud Bigquery Reservation v1 API ===================================================== -.. automodule:: google.cloud.bigquery.reservation_v1.services.reservation_service +.. automodule:: google.cloud.bigquery_reservation_v1.services.reservation_service :members: :inherited-members: diff --git a/docs/reservation_v1/types.rst b/docs/bigquery_reservation_v1/types.rst similarity index 70% rename from docs/reservation_v1/types.rst rename to docs/bigquery_reservation_v1/types.rst index 71b6c38f..96a1583d 100644 --- a/docs/reservation_v1/types.rst +++ b/docs/bigquery_reservation_v1/types.rst @@ -1,6 +1,6 @@ Types for Google Cloud Bigquery Reservation v1 API ================================================== -.. automodule:: google.cloud.bigquery.reservation_v1.types +.. automodule:: google.cloud.bigquery_reservation_v1.types :members: :show-inheritance: diff --git a/docs/index.rst b/docs/index.rst index b5fc8623..41171732 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,8 +6,8 @@ API Reference .. toctree:: :maxdepth: 2 - reservation_v1/services - reservation_v1/types + bigquery_reservation_v1/services + bigquery_reservation_v1/types Changelog --------- diff --git a/google/cloud/bigquery/reservation_v1/services/reservation_service/async_client.py b/google/cloud/bigquery/reservation_v1/services/reservation_service/async_client.py index 60a800b6..2b24488c 100644 --- a/google/cloud/bigquery/reservation_v1/services/reservation_service/async_client.py +++ b/google/cloud/bigquery/reservation_v1/services/reservation_service/async_client.py @@ -1562,6 +1562,7 @@ async def search_assignments( - ``assignee=folders/123`` - ``assignee=organizations/456`` + This corresponds to the ``query`` field on the ``request`` instance; if ``request`` is provided, this should not be set. diff --git a/google/cloud/bigquery/reservation_v1/services/reservation_service/client.py b/google/cloud/bigquery/reservation_v1/services/reservation_service/client.py index c2b0f9bc..9b381a58 100644 --- a/google/cloud/bigquery/reservation_v1/services/reservation_service/client.py +++ b/google/cloud/bigquery/reservation_v1/services/reservation_service/client.py @@ -1822,6 +1822,7 @@ def search_assignments( - ``assignee=folders/123`` - ``assignee=organizations/456`` + This corresponds to the ``query`` field on the ``request`` instance; if ``request`` is provided, this should not be set. diff --git a/google/cloud/bigquery/reservation/__init__.py b/google/cloud/bigquery_reservation/__init__.py similarity index 58% rename from google/cloud/bigquery/reservation/__init__.py rename to google/cloud/bigquery_reservation/__init__.py index 74fa58e2..8ef414c5 100644 --- a/google/cloud/bigquery/reservation/__init__.py +++ b/google/cloud/bigquery_reservation/__init__.py @@ -15,82 +15,82 @@ # limitations under the License. # -from google.cloud.bigquery.reservation_v1.services.reservation_service.async_client import ( +from google.cloud.bigquery_reservation_v1.services.reservation_service.async_client import ( ReservationServiceAsyncClient, ) -from google.cloud.bigquery.reservation_v1.services.reservation_service.client import ( +from google.cloud.bigquery_reservation_v1.services.reservation_service.client import ( ReservationServiceClient, ) -from google.cloud.bigquery.reservation_v1.types.reservation import Assignment -from google.cloud.bigquery.reservation_v1.types.reservation import BiReservation -from google.cloud.bigquery.reservation_v1.types.reservation import CapacityCommitment -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import Assignment +from google.cloud.bigquery_reservation_v1.types.reservation import BiReservation +from google.cloud.bigquery_reservation_v1.types.reservation import CapacityCommitment +from google.cloud.bigquery_reservation_v1.types.reservation import ( CreateAssignmentRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( CreateCapacityCommitmentRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( CreateReservationRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( DeleteAssignmentRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( DeleteCapacityCommitmentRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( DeleteReservationRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( GetBiReservationRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( GetCapacityCommitmentRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import GetReservationRequest -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import GetReservationRequest +from google.cloud.bigquery_reservation_v1.types.reservation import ( ListAssignmentsRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( ListAssignmentsResponse, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( ListCapacityCommitmentsRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( ListCapacityCommitmentsResponse, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( ListReservationsRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( ListReservationsResponse, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( MergeCapacityCommitmentsRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import MoveAssignmentRequest -from google.cloud.bigquery.reservation_v1.types.reservation import Reservation -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import MoveAssignmentRequest +from google.cloud.bigquery_reservation_v1.types.reservation import Reservation +from google.cloud.bigquery_reservation_v1.types.reservation import ( SearchAssignmentsRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( SearchAssignmentsResponse, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( SplitCapacityCommitmentRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( SplitCapacityCommitmentResponse, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( UpdateBiReservationRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( UpdateCapacityCommitmentRequest, ) -from google.cloud.bigquery.reservation_v1.types.reservation import ( +from google.cloud.bigquery_reservation_v1.types.reservation import ( UpdateReservationRequest, ) diff --git a/google/cloud/bigquery/reservation/py.typed b/google/cloud/bigquery_reservation/py.typed similarity index 100% rename from google/cloud/bigquery/reservation/py.typed rename to google/cloud/bigquery_reservation/py.typed diff --git a/google/cloud/bigquery/reservation_v1/__init__.py b/google/cloud/bigquery_reservation_v1/__init__.py similarity index 100% rename from google/cloud/bigquery/reservation_v1/__init__.py rename to google/cloud/bigquery_reservation_v1/__init__.py diff --git a/google/cloud/bigquery/reservation_v1/py.typed b/google/cloud/bigquery_reservation_v1/py.typed similarity index 100% rename from google/cloud/bigquery/reservation_v1/py.typed rename to google/cloud/bigquery_reservation_v1/py.typed diff --git a/google/cloud/bigquery/reservation_v1/services/__init__.py b/google/cloud/bigquery_reservation_v1/services/__init__.py similarity index 100% rename from google/cloud/bigquery/reservation_v1/services/__init__.py rename to google/cloud/bigquery_reservation_v1/services/__init__.py diff --git a/google/cloud/bigquery/reservation_v1/services/reservation_service/__init__.py b/google/cloud/bigquery_reservation_v1/services/reservation_service/__init__.py similarity index 100% rename from google/cloud/bigquery/reservation_v1/services/reservation_service/__init__.py rename to google/cloud/bigquery_reservation_v1/services/reservation_service/__init__.py diff --git a/google/cloud/bigquery_reservation_v1/services/reservation_service/async_client.py b/google/cloud/bigquery_reservation_v1/services/reservation_service/async_client.py new file mode 100644 index 00000000..4dbd0608 --- /dev/null +++ b/google/cloud/bigquery_reservation_v1/services/reservation_service/async_client.py @@ -0,0 +1,1971 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from collections import OrderedDict +import functools +import re +from typing import Dict, Sequence, Tuple, Type, Union +import pkg_resources + +import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core import exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.bigquery_reservation_v1.services.reservation_service import pagers +from google.cloud.bigquery_reservation_v1.types import reservation +from google.cloud.bigquery_reservation_v1.types import reservation as gcbr_reservation +from google.protobuf import field_mask_pb2 as field_mask # type: ignore +from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.rpc import status_pb2 as status # type: ignore + +from .transports.base import ReservationServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc_asyncio import ReservationServiceGrpcAsyncIOTransport +from .client import ReservationServiceClient + + +class ReservationServiceAsyncClient: + """This API allows users to manage their flat-rate BigQuery + reservations. + + A reservation provides computational resource guarantees, in the + form of `slots `__, to + users. A slot is a unit of computational power in BigQuery, and + serves as the basic unit of parallelism. In a scan of a + multi-partitioned table, a single slot operates on a single + partition of the table. A reservation resource exists as a child + resource of the admin project and location, e.g.: + ``projects/myproject/locations/US/reservations/reservationName``. + + A capacity commitment is a way to purchase compute capacity for + BigQuery jobs (in the form of slots) with some committed period of + usage. A capacity commitment resource exists as a child resource of + the admin project and location, e.g.: + ``projects/myproject/locations/US/capacityCommitments/id``. + """ + + _client: ReservationServiceClient + + DEFAULT_ENDPOINT = ReservationServiceClient.DEFAULT_ENDPOINT + DEFAULT_MTLS_ENDPOINT = ReservationServiceClient.DEFAULT_MTLS_ENDPOINT + + assignment_path = staticmethod(ReservationServiceClient.assignment_path) + parse_assignment_path = staticmethod(ReservationServiceClient.parse_assignment_path) + bi_reservation_path = staticmethod(ReservationServiceClient.bi_reservation_path) + parse_bi_reservation_path = staticmethod( + ReservationServiceClient.parse_bi_reservation_path + ) + capacity_commitment_path = staticmethod( + ReservationServiceClient.capacity_commitment_path + ) + parse_capacity_commitment_path = staticmethod( + ReservationServiceClient.parse_capacity_commitment_path + ) + reservation_path = staticmethod(ReservationServiceClient.reservation_path) + parse_reservation_path = staticmethod( + ReservationServiceClient.parse_reservation_path + ) + + common_billing_account_path = staticmethod( + ReservationServiceClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + ReservationServiceClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(ReservationServiceClient.common_folder_path) + parse_common_folder_path = staticmethod( + ReservationServiceClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + ReservationServiceClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + ReservationServiceClient.parse_common_organization_path + ) + + common_project_path = staticmethod(ReservationServiceClient.common_project_path) + parse_common_project_path = staticmethod( + ReservationServiceClient.parse_common_project_path + ) + + common_location_path = staticmethod(ReservationServiceClient.common_location_path) + parse_common_location_path = staticmethod( + ReservationServiceClient.parse_common_location_path + ) + + from_service_account_file = ReservationServiceClient.from_service_account_file + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ReservationServiceTransport: + """Return the transport used by the client instance. + + Returns: + ReservationServiceTransport: The transport used by the client instance. + """ + return self._client.transport + + get_transport_class = functools.partial( + type(ReservationServiceClient).get_transport_class, + type(ReservationServiceClient), + ) + + def __init__( + self, + *, + credentials: credentials.Credentials = None, + transport: Union[str, ReservationServiceTransport] = "grpc_asyncio", + client_options: ClientOptions = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiate the reservation service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.ReservationServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (ClientOptions): Custom options for the client. It + won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + + Raises: + google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport + creation failed for any reason. + """ + + self._client = ReservationServiceClient( + credentials=credentials, + transport=transport, + client_options=client_options, + client_info=client_info, + ) + + async def create_reservation( + self, + request: gcbr_reservation.CreateReservationRequest = None, + *, + parent: str = None, + reservation: gcbr_reservation.Reservation = None, + reservation_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcbr_reservation.Reservation: + r"""Creates a new reservation resource. + + Args: + request (:class:`~.gcbr_reservation.CreateReservationRequest`): + The request object. The request for + [ReservationService.CreateReservation][google.cloud.bigquery.reservation.v1.ReservationService.CreateReservation]. + parent (:class:`str`): + Required. Project, location. E.g., + ``projects/myproject/locations/US`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reservation (:class:`~.gcbr_reservation.Reservation`): + Definition of the new reservation to + create. + This corresponds to the ``reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reservation_id (:class:`str`): + The reservation ID. This field must + only contain lower case alphanumeric + characters or dash. Max length is 64 + characters. + This corresponds to the ``reservation_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.gcbr_reservation.Reservation: + A reservation is a mechanism used to + guarantee slots to users. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, reservation, reservation_id]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = gcbr_reservation.CreateReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if reservation is not None: + request.reservation = reservation + if reservation_id is not None: + request.reservation_id = reservation_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_reservation, + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def list_reservations( + self, + request: reservation.ListReservationsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReservationsAsyncPager: + r"""Lists all the reservations for the project in the + specified location. + + Args: + request (:class:`~.reservation.ListReservationsRequest`): + The request object. The request for + [ReservationService.ListReservations][google.cloud.bigquery.reservation.v1.ReservationService.ListReservations]. + parent (:class:`str`): + Required. The parent resource name containing project + and location, e.g.: ``projects/myproject/locations/US`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.ListReservationsAsyncPager: + The response for + [ReservationService.ListReservations][google.cloud.bigquery.reservation.v1.ReservationService.ListReservations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.ListReservationsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_reservations, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListReservationsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_reservation( + self, + request: reservation.GetReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.Reservation: + r"""Returns information about the reservation. + + Args: + request (:class:`~.reservation.GetReservationRequest`): + The request object. The request for + [ReservationService.GetReservation][google.cloud.bigquery.reservation.v1.ReservationService.GetReservation]. + name (:class:`str`): + Required. Resource name of the reservation to retrieve. + E.g., + ``projects/myproject/locations/US/reservations/team1-prod`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.Reservation: + A reservation is a mechanism used to + guarantee slots to users. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.GetReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_reservation, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def delete_reservation( + self, + request: reservation.DeleteReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a reservation. Returns + ``google.rpc.Code.FAILED_PRECONDITION`` when reservation has + assignments. + + Args: + request (:class:`~.reservation.DeleteReservationRequest`): + The request object. The request for + [ReservationService.DeleteReservation][google.cloud.bigquery.reservation.v1.ReservationService.DeleteReservation]. + name (:class:`str`): + Required. Resource name of the reservation to retrieve. + E.g., + ``projects/myproject/locations/US/reservations/team1-prod`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.DeleteReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_reservation, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + + async def update_reservation( + self, + request: gcbr_reservation.UpdateReservationRequest = None, + *, + reservation: gcbr_reservation.Reservation = None, + update_mask: field_mask.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcbr_reservation.Reservation: + r"""Updates an existing reservation resource. + + Args: + request (:class:`~.gcbr_reservation.UpdateReservationRequest`): + The request object. The request for + [ReservationService.UpdateReservation][google.cloud.bigquery.reservation.v1.ReservationService.UpdateReservation]. + reservation (:class:`~.gcbr_reservation.Reservation`): + Content of the reservation to update. + This corresponds to the ``reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`~.field_mask.FieldMask`): + Standard field mask for the set of + fields to be updated. + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.gcbr_reservation.Reservation: + A reservation is a mechanism used to + guarantee slots to users. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([reservation, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = gcbr_reservation.UpdateReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if reservation is not None: + request.reservation = reservation + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_reservation, + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("reservation.name", request.reservation.name),) + ), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def create_capacity_commitment( + self, + request: reservation.CreateCapacityCommitmentRequest = None, + *, + parent: str = None, + capacity_commitment: reservation.CapacityCommitment = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.CapacityCommitment: + r"""Creates a new capacity commitment resource. + + Args: + request (:class:`~.reservation.CreateCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.CreateCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.CreateCapacityCommitment]. + parent (:class:`str`): + Required. Resource name of the parent reservation. E.g., + ``projects/myproject/locations/US`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + capacity_commitment (:class:`~.reservation.CapacityCommitment`): + Content of the capacity commitment to + create. + This corresponds to the ``capacity_commitment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.CapacityCommitment: + Capacity commitment is a way to + purchase compute capacity for BigQuery + jobs (in the form of slots) with some + committed period of usage. Annual + commitments renew by default. + Commitments can be removed after their + commitment end time passes. + + In order to remove annual commitment, + its plan needs to be changed to monthly + or flex first. + + A capacity commitment resource exists as + a child resource of the admin project. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, capacity_commitment]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.CreateCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if capacity_commitment is not None: + request.capacity_commitment = capacity_commitment + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_capacity_commitment, + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def list_capacity_commitments( + self, + request: reservation.ListCapacityCommitmentsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListCapacityCommitmentsAsyncPager: + r"""Lists all the capacity commitments for the admin + project. + + Args: + request (:class:`~.reservation.ListCapacityCommitmentsRequest`): + The request object. The request for + [ReservationService.ListCapacityCommitments][google.cloud.bigquery.reservation.v1.ReservationService.ListCapacityCommitments]. + parent (:class:`str`): + Required. Resource name of the parent reservation. E.g., + ``projects/myproject/locations/US`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.ListCapacityCommitmentsAsyncPager: + The response for + [ReservationService.ListCapacityCommitments][google.cloud.bigquery.reservation.v1.ReservationService.ListCapacityCommitments]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.ListCapacityCommitmentsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_capacity_commitments, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListCapacityCommitmentsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def get_capacity_commitment( + self, + request: reservation.GetCapacityCommitmentRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.CapacityCommitment: + r"""Returns information about the capacity commitment. + + Args: + request (:class:`~.reservation.GetCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.GetCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.GetCapacityCommitment]. + name (:class:`str`): + Required. Resource name of the capacity commitment to + retrieve. E.g., + ``projects/myproject/locations/US/capacityCommitments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.CapacityCommitment: + Capacity commitment is a way to + purchase compute capacity for BigQuery + jobs (in the form of slots) with some + committed period of usage. Annual + commitments renew by default. + Commitments can be removed after their + commitment end time passes. + + In order to remove annual commitment, + its plan needs to be changed to monthly + or flex first. + + A capacity commitment resource exists as + a child resource of the admin project. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.GetCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_capacity_commitment, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def delete_capacity_commitment( + self, + request: reservation.DeleteCapacityCommitmentRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a capacity commitment. Attempting to delete capacity + commitment before its commitment_end_time will fail with the + error code ``google.rpc.Code.FAILED_PRECONDITION``. + + Args: + request (:class:`~.reservation.DeleteCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.DeleteCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.DeleteCapacityCommitment]. + name (:class:`str`): + Required. Resource name of the capacity commitment to + delete. E.g., + ``projects/myproject/locations/US/capacityCommitments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.DeleteCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_capacity_commitment, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + + async def update_capacity_commitment( + self, + request: reservation.UpdateCapacityCommitmentRequest = None, + *, + capacity_commitment: reservation.CapacityCommitment = None, + update_mask: field_mask.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.CapacityCommitment: + r"""Updates an existing capacity commitment. + + Only ``plan`` and ``renewal_plan`` fields can be updated. + + Plan can only be changed to a plan of a longer commitment + period. Attempting to change to a plan with shorter commitment + period will fail with the error code + ``google.rpc.Code.FAILED_PRECONDITION``. + + Args: + request (:class:`~.reservation.UpdateCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.UpdateCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.UpdateCapacityCommitment]. + capacity_commitment (:class:`~.reservation.CapacityCommitment`): + Content of the capacity commitment to + update. + This corresponds to the ``capacity_commitment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`~.field_mask.FieldMask`): + Standard field mask for the set of + fields to be updated. + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.CapacityCommitment: + Capacity commitment is a way to + purchase compute capacity for BigQuery + jobs (in the form of slots) with some + committed period of usage. Annual + commitments renew by default. + Commitments can be removed after their + commitment end time passes. + + In order to remove annual commitment, + its plan needs to be changed to monthly + or flex first. + + A capacity commitment resource exists as + a child resource of the admin project. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([capacity_commitment, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.UpdateCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if capacity_commitment is not None: + request.capacity_commitment = capacity_commitment + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_capacity_commitment, + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("capacity_commitment.name", request.capacity_commitment.name),) + ), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def split_capacity_commitment( + self, + request: reservation.SplitCapacityCommitmentRequest = None, + *, + name: str = None, + slot_count: int = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.SplitCapacityCommitmentResponse: + r"""Splits capacity commitment to two commitments of the same plan + and ``commitment_end_time``. + + A common use case is to enable downgrading commitments. + + For example, in order to downgrade from 10000 slots to 8000, you + might split a 10000 capacity commitment into commitments of 2000 + and 8000. Then, you would change the plan of the first one to + ``FLEX`` and then delete it. + + Args: + request (:class:`~.reservation.SplitCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.SplitCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.SplitCapacityCommitment]. + name (:class:`str`): + Required. The resource name e.g.,: + ``projects/myproject/locations/US/capacityCommitments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + slot_count (:class:`int`): + Number of slots in the capacity + commitment after the split. + This corresponds to the ``slot_count`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.SplitCapacityCommitmentResponse: + The response for + [ReservationService.SplitCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.SplitCapacityCommitment]. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, slot_count]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.SplitCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + if slot_count is not None: + request.slot_count = slot_count + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.split_capacity_commitment, + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def merge_capacity_commitments( + self, + request: reservation.MergeCapacityCommitmentsRequest = None, + *, + parent: str = None, + capacity_commitment_ids: Sequence[str] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.CapacityCommitment: + r"""Merges capacity commitments of the same plan into a single + commitment. + + The resulting capacity commitment has the greater + commitment_end_time out of the to-be-merged capacity + commitments. + + Attempting to merge capacity commitments of different plan will + fail with the error code + ``google.rpc.Code.FAILED_PRECONDITION``. + + Args: + request (:class:`~.reservation.MergeCapacityCommitmentsRequest`): + The request object. The request for + [ReservationService.MergeCapacityCommitments][google.cloud.bigquery.reservation.v1.ReservationService.MergeCapacityCommitments]. + parent (:class:`str`): + Parent resource that identifies admin project and + location e.g., ``projects/myproject/locations/us`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + capacity_commitment_ids (:class:`Sequence[str]`): + Ids of capacity commitments to merge. + These capacity commitments must exist + under admin project and location + specified in the parent. + ID is the last portion of capacity + commitment name e.g., 'abc' for + projects/myproject/locations/US/capacityCommitments/abc + This corresponds to the ``capacity_commitment_ids`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.CapacityCommitment: + Capacity commitment is a way to + purchase compute capacity for BigQuery + jobs (in the form of slots) with some + committed period of usage. Annual + commitments renew by default. + Commitments can be removed after their + commitment end time passes. + + In order to remove annual commitment, + its plan needs to be changed to monthly + or flex first. + + A capacity commitment resource exists as + a child resource of the admin project. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, capacity_commitment_ids]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.MergeCapacityCommitmentsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + + if capacity_commitment_ids: + request.capacity_commitment_ids.extend(capacity_commitment_ids) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.merge_capacity_commitments, + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def create_assignment( + self, + request: reservation.CreateAssignmentRequest = None, + *, + parent: str = None, + assignment: reservation.Assignment = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.Assignment: + r"""Creates an assignment object which allows the given project to + submit jobs of a certain type using slots from the specified + reservation. + + Currently a resource (project, folder, organization) can only + have one assignment per each (job_type, location) combination, + and that reservation will be used for all jobs of the matching + type. + + Different assignments can be created on different levels of the + projects, folders or organization hierarchy. During query + execution, the assignment is looked up at the project, folder + and organization levels in that order. The first assignment + found is applied to the query. + + When creating assignments, it does not matter if other + assignments exist at higher levels. + + Example: + + - The organization ``organizationA`` contains two projects, + ``project1`` and ``project2``. + - Assignments for all three entities (``organizationA``, + ``project1``, and ``project2``) could all be created and + mapped to the same or different reservations. + + Returns ``google.rpc.Code.PERMISSION_DENIED`` if user does not + have 'bigquery.admin' permissions on the project using the + reservation and the project that owns this reservation. + + Returns ``google.rpc.Code.INVALID_ARGUMENT`` when location of + the assignment does not match location of the reservation. + + Args: + request (:class:`~.reservation.CreateAssignmentRequest`): + The request object. The request for + [ReservationService.CreateAssignment][google.cloud.bigquery.reservation.v1.ReservationService.CreateAssignment]. + Note: "bigquery.reservationAssignments.create" + permission is required on the related assignee. + parent (:class:`str`): + Required. The parent resource name of the assignment + E.g. + ``projects/myproject/locations/US/reservations/team1-prod`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + assignment (:class:`~.reservation.Assignment`): + Assignment resource to create. + This corresponds to the ``assignment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.Assignment: + A Assignment allows a project to + submit jobs of a certain type using + slots from the specified reservation. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, assignment]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.CreateAssignmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if assignment is not None: + request.assignment = assignment + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.create_assignment, + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def list_assignments( + self, + request: reservation.ListAssignmentsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListAssignmentsAsyncPager: + r"""Lists assignments. + + Only explicitly created assignments will be returned. + + Example: + + - Organization ``organizationA`` contains two projects, + ``project1`` and ``project2``. + - Reservation ``res1`` exists and was created previously. + - CreateAssignment was used previously to define the following + associations between entities and reservations: + ```` and ```` + + In this example, ListAssignments will just return the above two + assignments for reservation ``res1``, and no expansion/merge + will happen. + + The wildcard "-" can be used for reservations in the request. In + that case all assignments belongs to the specified project and + location will be listed. + + **Note** "-" cannot be used for projects nor locations. + + Args: + request (:class:`~.reservation.ListAssignmentsRequest`): + The request object. The request for + [ReservationService.ListAssignments][google.cloud.bigquery.reservation.v1.ReservationService.ListAssignments]. + parent (:class:`str`): + Required. The parent resource name e.g.: + + ``projects/myproject/locations/US/reservations/team1-prod`` + + Or: + + ``projects/myproject/locations/US/reservations/-`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.ListAssignmentsAsyncPager: + The response for + [ReservationService.ListAssignments][google.cloud.bigquery.reservation.v1.ReservationService.ListAssignments]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.ListAssignmentsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.list_assignments, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.ListAssignmentsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def delete_assignment( + self, + request: reservation.DeleteAssignmentRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a assignment. No expansion will happen. + + Example: + + - Organization ``organizationA`` contains two projects, + ``project1`` and ``project2``. + - Reservation ``res1`` exists and was created previously. + - CreateAssignment was used previously to define the following + associations between entities and reservations: + ```` and ```` + + In this example, deletion of the ```` + assignment won't affect the other assignment + ````. After said deletion, queries from + ``project1`` will still use ``res1`` while queries from + ``project2`` will switch to use on-demand mode. + + Args: + request (:class:`~.reservation.DeleteAssignmentRequest`): + The request object. The request for + [ReservationService.DeleteAssignment][google.cloud.bigquery.reservation.v1.ReservationService.DeleteAssignment]. + Note: "bigquery.reservationAssignments.delete" + permission is required on the related assignee. + name (:class:`str`): + Required. Name of the resource, e.g. + ``projects/myproject/locations/US/reservations/team1-prod/assignments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.DeleteAssignmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.delete_assignment, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + await rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + + async def search_assignments( + self, + request: reservation.SearchAssignmentsRequest = None, + *, + parent: str = None, + query: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.SearchAssignmentsAsyncPager: + r"""Looks up assignments for a specified resource for a particular + region. If the request is about a project: + + 1. Assignments created on the project will be returned if they + exist. + 2. Otherwise assignments created on the closest ancestor will be + returned. + 3. Assignments for different JobTypes will all be returned. + + The same logic applies if the request is about a folder. + + If the request is about an organization, then assignments + created on the organization will be returned (organization + doesn't have ancestors). + + Comparing to ListAssignments, there are some behavior + differences: + + 1. permission on the assignee will be verified in this API. + 2. Hierarchy lookup (project->folder->organization) happens in + this API. + 3. Parent here is ``projects/*/locations/*``, instead of + ``projects/*/locations/*reservations/*``. + + **Note** "-" cannot be used for projects nor locations. + + Args: + request (:class:`~.reservation.SearchAssignmentsRequest`): + The request object. The request for + [ReservationService.SearchAssignments][google.cloud.bigquery.reservation.v1.ReservationService.SearchAssignments]. + Note: "bigquery.reservationAssignments.search" + permission is required on the related assignee. + parent (:class:`str`): + Required. The resource name of the admin + project(containing project and location), e.g.: + ``projects/myproject/locations/US``. + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + query (:class:`str`): + Please specify resource name as assignee in the query. + + Examples: + + - ``assignee=projects/myproject`` + - ``assignee=folders/123`` + - ``assignee=organizations/456`` + + This corresponds to the ``query`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.SearchAssignmentsAsyncPager: + The response for + [ReservationService.SearchAssignments][google.cloud.bigquery.reservation.v1.ReservationService.SearchAssignments]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, query]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.SearchAssignmentsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if query is not None: + request.query = query + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.search_assignments, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__aiter__` convenience method. + response = pagers.SearchAssignmentsAsyncPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + async def move_assignment( + self, + request: reservation.MoveAssignmentRequest = None, + *, + name: str = None, + destination_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.Assignment: + r"""Moves an assignment under a new reservation. + This differs from removing an existing assignment and + recreating a new one by providing a transactional change + that ensures an assignee always has an associated + reservation. + + Args: + request (:class:`~.reservation.MoveAssignmentRequest`): + The request object. The request for + [ReservationService.MoveAssignment][google.cloud.bigquery.reservation.v1.ReservationService.MoveAssignment]. + **Note**: "bigquery.reservationAssignments.create" + permission is required on the destination_id. + + **Note**: "bigquery.reservationAssignments.create" and + "bigquery.reservationAssignments.delete" permission are + required on the related assignee. + name (:class:`str`): + Required. The resource name of the assignment, e.g. + ``projects/myproject/locations/US/reservations/team1-prod/assignments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + destination_id (:class:`str`): + The new reservation ID, e.g.: + ``projects/myotherproject/locations/US/reservations/team2-prod`` + This corresponds to the ``destination_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.Assignment: + A Assignment allows a project to + submit jobs of a certain type using + slots from the specified reservation. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, destination_id]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.MoveAssignmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + if destination_id is not None: + request.destination_id = destination_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.move_assignment, + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def get_bi_reservation( + self, + request: reservation.GetBiReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.BiReservation: + r"""Retrieves a BI reservation. + + Args: + request (:class:`~.reservation.GetBiReservationRequest`): + The request object. A request to get a singleton BI + reservation. + name (:class:`str`): + Required. Name of the requested reservation, for + example: + ``projects/{project_id}/locations/{location_id}/bireservation`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.BiReservation: + Represents a BI Reservation. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.GetBiReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.get_bi_reservation, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + async def update_bi_reservation( + self, + request: reservation.UpdateBiReservationRequest = None, + *, + bi_reservation: reservation.BiReservation = None, + update_mask: field_mask.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.BiReservation: + r"""Updates a BI reservation. + + Only fields specified in the ``field_mask`` are updated. + + A singleton BI reservation always exists with default size 0. In + order to reserve BI capacity it needs to be updated to an amount + greater than 0. In order to release BI capacity reservation size + must be set to 0. + + Args: + request (:class:`~.reservation.UpdateBiReservationRequest`): + The request object. A request to update a BI + reservation. + bi_reservation (:class:`~.reservation.BiReservation`): + A reservation to update. + This corresponds to the ``bi_reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`~.field_mask.FieldMask`): + A list of fields to be updated in + this request. + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.BiReservation: + Represents a BI Reservation. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([bi_reservation, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + request = reservation.UpdateBiReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if bi_reservation is not None: + request.bi_reservation = bi_reservation + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = gapic_v1.method_async.wrap_method( + self._client._transport.update_bi_reservation, + default_timeout=60.0, + client_info=DEFAULT_CLIENT_INFO, + ) + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("bi_reservation.name", request.bi_reservation.name),) + ), + ) + + # Send the request. + response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-bigquery-reservation", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("ReservationServiceAsyncClient",) diff --git a/google/cloud/bigquery_reservation_v1/services/reservation_service/client.py b/google/cloud/bigquery_reservation_v1/services/reservation_service/client.py new file mode 100644 index 00000000..882b1b5a --- /dev/null +++ b/google/cloud/bigquery_reservation_v1/services/reservation_service/client.py @@ -0,0 +1,2155 @@ +# -*- coding: utf-8 -*- + +# Copyright 2020 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +from collections import OrderedDict +from distutils import util +import os +import re +from typing import Callable, Dict, Optional, Sequence, Tuple, Type, Union +import pkg_resources + +from google.api_core import client_options as client_options_lib # type: ignore +from google.api_core import exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore + +from google.cloud.bigquery_reservation_v1.services.reservation_service import pagers +from google.cloud.bigquery_reservation_v1.types import reservation +from google.cloud.bigquery_reservation_v1.types import reservation as gcbr_reservation +from google.protobuf import field_mask_pb2 as field_mask # type: ignore +from google.protobuf import timestamp_pb2 as timestamp # type: ignore +from google.rpc import status_pb2 as status # type: ignore + +from .transports.base import ReservationServiceTransport, DEFAULT_CLIENT_INFO +from .transports.grpc import ReservationServiceGrpcTransport +from .transports.grpc_asyncio import ReservationServiceGrpcAsyncIOTransport + + +class ReservationServiceClientMeta(type): + """Metaclass for the ReservationService client. + + This provides class-level methods for building and retrieving + support objects (e.g. transport) without polluting the client instance + objects. + """ + + _transport_registry = ( + OrderedDict() + ) # type: Dict[str, Type[ReservationServiceTransport]] + _transport_registry["grpc"] = ReservationServiceGrpcTransport + _transport_registry["grpc_asyncio"] = ReservationServiceGrpcAsyncIOTransport + + def get_transport_class( + cls, label: str = None, + ) -> Type[ReservationServiceTransport]: + """Return an appropriate transport class. + + Args: + label: The name of the desired transport. If none is + provided, then the first transport in the registry is used. + + Returns: + The transport class to use. + """ + # If a specific transport is requested, return that one. + if label: + return cls._transport_registry[label] + + # No transport is requested; return the default (that is, the first one + # in the dictionary). + return next(iter(cls._transport_registry.values())) + + +class ReservationServiceClient(metaclass=ReservationServiceClientMeta): + """This API allows users to manage their flat-rate BigQuery + reservations. + + A reservation provides computational resource guarantees, in the + form of `slots `__, to + users. A slot is a unit of computational power in BigQuery, and + serves as the basic unit of parallelism. In a scan of a + multi-partitioned table, a single slot operates on a single + partition of the table. A reservation resource exists as a child + resource of the admin project and location, e.g.: + ``projects/myproject/locations/US/reservations/reservationName``. + + A capacity commitment is a way to purchase compute capacity for + BigQuery jobs (in the form of slots) with some committed period of + usage. A capacity commitment resource exists as a child resource of + the admin project and location, e.g.: + ``projects/myproject/locations/US/capacityCommitments/id``. + """ + + @staticmethod + def _get_default_mtls_endpoint(api_endpoint): + """Convert api endpoint to mTLS endpoint. + Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to + "*.mtls.sandbox.googleapis.com" and "*.mtls.googleapis.com" respectively. + Args: + api_endpoint (Optional[str]): the api endpoint to convert. + Returns: + str: converted mTLS api endpoint. + """ + if not api_endpoint: + return api_endpoint + + mtls_endpoint_re = re.compile( + r"(?P[^.]+)(?P\.mtls)?(?P\.sandbox)?(?P\.googleapis\.com)?" + ) + + m = mtls_endpoint_re.match(api_endpoint) + name, mtls, sandbox, googledomain = m.groups() + if mtls or not googledomain: + return api_endpoint + + if sandbox: + return api_endpoint.replace( + "sandbox.googleapis.com", "mtls.sandbox.googleapis.com" + ) + + return api_endpoint.replace(".googleapis.com", ".mtls.googleapis.com") + + DEFAULT_ENDPOINT = "bigqueryreservation.googleapis.com" + DEFAULT_MTLS_ENDPOINT = _get_default_mtls_endpoint.__func__( # type: ignore + DEFAULT_ENDPOINT + ) + + @classmethod + def from_service_account_file(cls, filename: str, *args, **kwargs): + """Creates an instance of this client using the provided credentials + file. + + Args: + filename (str): The path to the service account private key json + file. + args: Additional arguments to pass to the constructor. + kwargs: Additional arguments to pass to the constructor. + + Returns: + {@api.name}: The constructed client. + """ + credentials = service_account.Credentials.from_service_account_file(filename) + kwargs["credentials"] = credentials + return cls(*args, **kwargs) + + from_service_account_json = from_service_account_file + + @property + def transport(self) -> ReservationServiceTransport: + """Return the transport used by the client instance. + + Returns: + ReservationServiceTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def assignment_path( + project: str, location: str, reservation: str, assignment: str, + ) -> str: + """Return a fully-qualified assignment string.""" + return "projects/{project}/locations/{location}/reservations/{reservation}/assignments/{assignment}".format( + project=project, + location=location, + reservation=reservation, + assignment=assignment, + ) + + @staticmethod + def parse_assignment_path(path: str) -> Dict[str, str]: + """Parse a assignment path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/reservations/(?P.+?)/assignments/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def bi_reservation_path(project: str, location: str,) -> str: + """Return a fully-qualified bi_reservation string.""" + return "projects/{project}/locations/{location}/bireservation".format( + project=project, location=location, + ) + + @staticmethod + def parse_bi_reservation_path(path: str) -> Dict[str, str]: + """Parse a bi_reservation path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/bireservation$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def capacity_commitment_path( + project: str, location: str, capacity_commitment: str, + ) -> str: + """Return a fully-qualified capacity_commitment string.""" + return "projects/{project}/locations/{location}/capacityCommitments/{capacity_commitment}".format( + project=project, location=location, capacity_commitment=capacity_commitment, + ) + + @staticmethod + def parse_capacity_commitment_path(path: str) -> Dict[str, str]: + """Parse a capacity_commitment path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/capacityCommitments/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def reservation_path(project: str, location: str, reservation: str,) -> str: + """Return a fully-qualified reservation string.""" + return "projects/{project}/locations/{location}/reservations/{reservation}".format( + project=project, location=location, reservation=reservation, + ) + + @staticmethod + def parse_reservation_path(path: str) -> Dict[str, str]: + """Parse a reservation path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/locations/(?P.+?)/reservations/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + + def __init__( + self, + *, + credentials: Optional[credentials.Credentials] = None, + transport: Union[str, ReservationServiceTransport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, + client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, + ) -> None: + """Instantiate the reservation service client. + + Args: + credentials (Optional[google.auth.credentials.Credentials]): The + authorization credentials to attach to requests. These + credentials identify the application to the service; if none + are specified, the client will attempt to ascertain the + credentials from the environment. + transport (Union[str, ~.ReservationServiceTransport]): The + transport to use. If set to None, a transport is chosen + automatically. + client_options (client_options_lib.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. + (1) The ``api_endpoint`` property can be used to override the + default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT + environment variable can also be used to override the endpoint: + "always" (always use the default mTLS endpoint), "never" (always + use the default regular endpoint) and "auto" (auto switch to the + default mTLS endpoint if client certificate is present, this is + the default value). However, the ``api_endpoint`` property takes + precedence if provided. + (2) If GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable + is "true", then the ``client_cert_source`` property can be used + to provide client certificate for mutual TLS transport. If + not provided, the default SSL client certificate will be used if + present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not + set, no client certificate will be used. + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + 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. + + Raises: + google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport + creation failed for any reason. + """ + if isinstance(client_options, dict): + client_options = client_options_lib.from_dict(client_options) + if client_options is None: + client_options = client_options_lib.ClientOptions() + + # Create SSL credentials for mutual TLS if needed. + use_client_cert = bool( + util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false")) + ) + + ssl_credentials = None + is_mtls = False + if use_client_cert: + if client_options.client_cert_source: + import grpc # type: ignore + + cert, key = client_options.client_cert_source() + ssl_credentials = grpc.ssl_channel_credentials( + certificate_chain=cert, private_key=key + ) + is_mtls = True + else: + creds = SslCredentials() + is_mtls = creds.is_mtls + ssl_credentials = creds.ssl_credentials if is_mtls else None + + # Figure out which api endpoint to use. + if client_options.api_endpoint is not None: + api_endpoint = client_options.api_endpoint + else: + use_mtls_env = os.getenv("GOOGLE_API_USE_MTLS_ENDPOINT", "auto") + if use_mtls_env == "never": + api_endpoint = self.DEFAULT_ENDPOINT + elif use_mtls_env == "always": + api_endpoint = self.DEFAULT_MTLS_ENDPOINT + elif use_mtls_env == "auto": + api_endpoint = ( + self.DEFAULT_MTLS_ENDPOINT if is_mtls else self.DEFAULT_ENDPOINT + ) + else: + raise MutualTLSChannelError( + "Unsupported GOOGLE_API_USE_MTLS_ENDPOINT value. Accepted values: never, auto, always" + ) + + # Save or instantiate the transport. + # Ordinarily, we provide the transport, but allowing a custom transport + # instance provides an extensibility point for unusual situations. + if isinstance(transport, ReservationServiceTransport): + # transport is a ReservationServiceTransport instance. + if credentials or client_options.credentials_file: + raise ValueError( + "When providing a transport instance, " + "provide its credentials directly." + ) + if client_options.scopes: + raise ValueError( + "When providing a transport instance, " + "provide its scopes directly." + ) + self._transport = transport + else: + Transport = type(self).get_transport_class(transport) + self._transport = Transport( + credentials=credentials, + credentials_file=client_options.credentials_file, + host=api_endpoint, + scopes=client_options.scopes, + ssl_channel_credentials=ssl_credentials, + quota_project_id=client_options.quota_project_id, + client_info=client_info, + ) + + def create_reservation( + self, + request: gcbr_reservation.CreateReservationRequest = None, + *, + parent: str = None, + reservation: gcbr_reservation.Reservation = None, + reservation_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcbr_reservation.Reservation: + r"""Creates a new reservation resource. + + Args: + request (:class:`~.gcbr_reservation.CreateReservationRequest`): + The request object. The request for + [ReservationService.CreateReservation][google.cloud.bigquery.reservation.v1.ReservationService.CreateReservation]. + parent (:class:`str`): + Required. Project, location. E.g., + ``projects/myproject/locations/US`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reservation (:class:`~.gcbr_reservation.Reservation`): + Definition of the new reservation to + create. + This corresponds to the ``reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + reservation_id (:class:`str`): + The reservation ID. This field must + only contain lower case alphanumeric + characters or dash. Max length is 64 + characters. + This corresponds to the ``reservation_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.gcbr_reservation.Reservation: + A reservation is a mechanism used to + guarantee slots to users. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, reservation, reservation_id]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a gcbr_reservation.CreateReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, gcbr_reservation.CreateReservationRequest): + request = gcbr_reservation.CreateReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if reservation is not None: + request.reservation = reservation + if reservation_id is not None: + request.reservation_id = reservation_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def list_reservations( + self, + request: reservation.ListReservationsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListReservationsPager: + r"""Lists all the reservations for the project in the + specified location. + + Args: + request (:class:`~.reservation.ListReservationsRequest`): + The request object. The request for + [ReservationService.ListReservations][google.cloud.bigquery.reservation.v1.ReservationService.ListReservations]. + parent (:class:`str`): + Required. The parent resource name containing project + and location, e.g.: ``projects/myproject/locations/US`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.ListReservationsPager: + The response for + [ReservationService.ListReservations][google.cloud.bigquery.reservation.v1.ReservationService.ListReservations]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.ListReservationsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.ListReservationsRequest): + request = reservation.ListReservationsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_reservations] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListReservationsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def get_reservation( + self, + request: reservation.GetReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.Reservation: + r"""Returns information about the reservation. + + Args: + request (:class:`~.reservation.GetReservationRequest`): + The request object. The request for + [ReservationService.GetReservation][google.cloud.bigquery.reservation.v1.ReservationService.GetReservation]. + name (:class:`str`): + Required. Resource name of the reservation to retrieve. + E.g., + ``projects/myproject/locations/US/reservations/team1-prod`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.Reservation: + A reservation is a mechanism used to + guarantee slots to users. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.GetReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.GetReservationRequest): + request = reservation.GetReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def delete_reservation( + self, + request: reservation.DeleteReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a reservation. Returns + ``google.rpc.Code.FAILED_PRECONDITION`` when reservation has + assignments. + + Args: + request (:class:`~.reservation.DeleteReservationRequest`): + The request object. The request for + [ReservationService.DeleteReservation][google.cloud.bigquery.reservation.v1.ReservationService.DeleteReservation]. + name (:class:`str`): + Required. Resource name of the reservation to retrieve. + E.g., + ``projects/myproject/locations/US/reservations/team1-prod`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.DeleteReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.DeleteReservationRequest): + request = reservation.DeleteReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + + def update_reservation( + self, + request: gcbr_reservation.UpdateReservationRequest = None, + *, + reservation: gcbr_reservation.Reservation = None, + update_mask: field_mask.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> gcbr_reservation.Reservation: + r"""Updates an existing reservation resource. + + Args: + request (:class:`~.gcbr_reservation.UpdateReservationRequest`): + The request object. The request for + [ReservationService.UpdateReservation][google.cloud.bigquery.reservation.v1.ReservationService.UpdateReservation]. + reservation (:class:`~.gcbr_reservation.Reservation`): + Content of the reservation to update. + This corresponds to the ``reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`~.field_mask.FieldMask`): + Standard field mask for the set of + fields to be updated. + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.gcbr_reservation.Reservation: + A reservation is a mechanism used to + guarantee slots to users. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([reservation, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a gcbr_reservation.UpdateReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, gcbr_reservation.UpdateReservationRequest): + request = gcbr_reservation.UpdateReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if reservation is not None: + request.reservation = reservation + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("reservation.name", request.reservation.name),) + ), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def create_capacity_commitment( + self, + request: reservation.CreateCapacityCommitmentRequest = None, + *, + parent: str = None, + capacity_commitment: reservation.CapacityCommitment = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.CapacityCommitment: + r"""Creates a new capacity commitment resource. + + Args: + request (:class:`~.reservation.CreateCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.CreateCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.CreateCapacityCommitment]. + parent (:class:`str`): + Required. Resource name of the parent reservation. E.g., + ``projects/myproject/locations/US`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + capacity_commitment (:class:`~.reservation.CapacityCommitment`): + Content of the capacity commitment to + create. + This corresponds to the ``capacity_commitment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.CapacityCommitment: + Capacity commitment is a way to + purchase compute capacity for BigQuery + jobs (in the form of slots) with some + committed period of usage. Annual + commitments renew by default. + Commitments can be removed after their + commitment end time passes. + + In order to remove annual commitment, + its plan needs to be changed to monthly + or flex first. + + A capacity commitment resource exists as + a child resource of the admin project. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, capacity_commitment]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.CreateCapacityCommitmentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.CreateCapacityCommitmentRequest): + request = reservation.CreateCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if capacity_commitment is not None: + request.capacity_commitment = capacity_commitment + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.create_capacity_commitment + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def list_capacity_commitments( + self, + request: reservation.ListCapacityCommitmentsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListCapacityCommitmentsPager: + r"""Lists all the capacity commitments for the admin + project. + + Args: + request (:class:`~.reservation.ListCapacityCommitmentsRequest`): + The request object. The request for + [ReservationService.ListCapacityCommitments][google.cloud.bigquery.reservation.v1.ReservationService.ListCapacityCommitments]. + parent (:class:`str`): + Required. Resource name of the parent reservation. E.g., + ``projects/myproject/locations/US`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.ListCapacityCommitmentsPager: + The response for + [ReservationService.ListCapacityCommitments][google.cloud.bigquery.reservation.v1.ReservationService.ListCapacityCommitments]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.ListCapacityCommitmentsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.ListCapacityCommitmentsRequest): + request = reservation.ListCapacityCommitmentsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.list_capacity_commitments + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListCapacityCommitmentsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def get_capacity_commitment( + self, + request: reservation.GetCapacityCommitmentRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.CapacityCommitment: + r"""Returns information about the capacity commitment. + + Args: + request (:class:`~.reservation.GetCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.GetCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.GetCapacityCommitment]. + name (:class:`str`): + Required. Resource name of the capacity commitment to + retrieve. E.g., + ``projects/myproject/locations/US/capacityCommitments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.CapacityCommitment: + Capacity commitment is a way to + purchase compute capacity for BigQuery + jobs (in the form of slots) with some + committed period of usage. Annual + commitments renew by default. + Commitments can be removed after their + commitment end time passes. + + In order to remove annual commitment, + its plan needs to be changed to monthly + or flex first. + + A capacity commitment resource exists as + a child resource of the admin project. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.GetCapacityCommitmentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.GetCapacityCommitmentRequest): + request = reservation.GetCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_capacity_commitment] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def delete_capacity_commitment( + self, + request: reservation.DeleteCapacityCommitmentRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a capacity commitment. Attempting to delete capacity + commitment before its commitment_end_time will fail with the + error code ``google.rpc.Code.FAILED_PRECONDITION``. + + Args: + request (:class:`~.reservation.DeleteCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.DeleteCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.DeleteCapacityCommitment]. + name (:class:`str`): + Required. Resource name of the capacity commitment to + delete. E.g., + ``projects/myproject/locations/US/capacityCommitments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.DeleteCapacityCommitmentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.DeleteCapacityCommitmentRequest): + request = reservation.DeleteCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.delete_capacity_commitment + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + + def update_capacity_commitment( + self, + request: reservation.UpdateCapacityCommitmentRequest = None, + *, + capacity_commitment: reservation.CapacityCommitment = None, + update_mask: field_mask.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.CapacityCommitment: + r"""Updates an existing capacity commitment. + + Only ``plan`` and ``renewal_plan`` fields can be updated. + + Plan can only be changed to a plan of a longer commitment + period. Attempting to change to a plan with shorter commitment + period will fail with the error code + ``google.rpc.Code.FAILED_PRECONDITION``. + + Args: + request (:class:`~.reservation.UpdateCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.UpdateCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.UpdateCapacityCommitment]. + capacity_commitment (:class:`~.reservation.CapacityCommitment`): + Content of the capacity commitment to + update. + This corresponds to the ``capacity_commitment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`~.field_mask.FieldMask`): + Standard field mask for the set of + fields to be updated. + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.CapacityCommitment: + Capacity commitment is a way to + purchase compute capacity for BigQuery + jobs (in the form of slots) with some + committed period of usage. Annual + commitments renew by default. + Commitments can be removed after their + commitment end time passes. + + In order to remove annual commitment, + its plan needs to be changed to monthly + or flex first. + + A capacity commitment resource exists as + a child resource of the admin project. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([capacity_commitment, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.UpdateCapacityCommitmentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.UpdateCapacityCommitmentRequest): + request = reservation.UpdateCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if capacity_commitment is not None: + request.capacity_commitment = capacity_commitment + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.update_capacity_commitment + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("capacity_commitment.name", request.capacity_commitment.name),) + ), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def split_capacity_commitment( + self, + request: reservation.SplitCapacityCommitmentRequest = None, + *, + name: str = None, + slot_count: int = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.SplitCapacityCommitmentResponse: + r"""Splits capacity commitment to two commitments of the same plan + and ``commitment_end_time``. + + A common use case is to enable downgrading commitments. + + For example, in order to downgrade from 10000 slots to 8000, you + might split a 10000 capacity commitment into commitments of 2000 + and 8000. Then, you would change the plan of the first one to + ``FLEX`` and then delete it. + + Args: + request (:class:`~.reservation.SplitCapacityCommitmentRequest`): + The request object. The request for + [ReservationService.SplitCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.SplitCapacityCommitment]. + name (:class:`str`): + Required. The resource name e.g.,: + ``projects/myproject/locations/US/capacityCommitments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + slot_count (:class:`int`): + Number of slots in the capacity + commitment after the split. + This corresponds to the ``slot_count`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.SplitCapacityCommitmentResponse: + The response for + [ReservationService.SplitCapacityCommitment][google.cloud.bigquery.reservation.v1.ReservationService.SplitCapacityCommitment]. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, slot_count]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.SplitCapacityCommitmentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.SplitCapacityCommitmentRequest): + request = reservation.SplitCapacityCommitmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + if slot_count is not None: + request.slot_count = slot_count + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.split_capacity_commitment + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def merge_capacity_commitments( + self, + request: reservation.MergeCapacityCommitmentsRequest = None, + *, + parent: str = None, + capacity_commitment_ids: Sequence[str] = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.CapacityCommitment: + r"""Merges capacity commitments of the same plan into a single + commitment. + + The resulting capacity commitment has the greater + commitment_end_time out of the to-be-merged capacity + commitments. + + Attempting to merge capacity commitments of different plan will + fail with the error code + ``google.rpc.Code.FAILED_PRECONDITION``. + + Args: + request (:class:`~.reservation.MergeCapacityCommitmentsRequest`): + The request object. The request for + [ReservationService.MergeCapacityCommitments][google.cloud.bigquery.reservation.v1.ReservationService.MergeCapacityCommitments]. + parent (:class:`str`): + Parent resource that identifies admin project and + location e.g., ``projects/myproject/locations/us`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + capacity_commitment_ids (:class:`Sequence[str]`): + Ids of capacity commitments to merge. + These capacity commitments must exist + under admin project and location + specified in the parent. + ID is the last portion of capacity + commitment name e.g., 'abc' for + projects/myproject/locations/US/capacityCommitments/abc + This corresponds to the ``capacity_commitment_ids`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.CapacityCommitment: + Capacity commitment is a way to + purchase compute capacity for BigQuery + jobs (in the form of slots) with some + committed period of usage. Annual + commitments renew by default. + Commitments can be removed after their + commitment end time passes. + + In order to remove annual commitment, + its plan needs to be changed to monthly + or flex first. + + A capacity commitment resource exists as + a child resource of the admin project. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, capacity_commitment_ids]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.MergeCapacityCommitmentsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.MergeCapacityCommitmentsRequest): + request = reservation.MergeCapacityCommitmentsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + + if capacity_commitment_ids: + request.capacity_commitment_ids.extend(capacity_commitment_ids) + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[ + self._transport.merge_capacity_commitments + ] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def create_assignment( + self, + request: reservation.CreateAssignmentRequest = None, + *, + parent: str = None, + assignment: reservation.Assignment = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.Assignment: + r"""Creates an assignment object which allows the given project to + submit jobs of a certain type using slots from the specified + reservation. + + Currently a resource (project, folder, organization) can only + have one assignment per each (job_type, location) combination, + and that reservation will be used for all jobs of the matching + type. + + Different assignments can be created on different levels of the + projects, folders or organization hierarchy. During query + execution, the assignment is looked up at the project, folder + and organization levels in that order. The first assignment + found is applied to the query. + + When creating assignments, it does not matter if other + assignments exist at higher levels. + + Example: + + - The organization ``organizationA`` contains two projects, + ``project1`` and ``project2``. + - Assignments for all three entities (``organizationA``, + ``project1``, and ``project2``) could all be created and + mapped to the same or different reservations. + + Returns ``google.rpc.Code.PERMISSION_DENIED`` if user does not + have 'bigquery.admin' permissions on the project using the + reservation and the project that owns this reservation. + + Returns ``google.rpc.Code.INVALID_ARGUMENT`` when location of + the assignment does not match location of the reservation. + + Args: + request (:class:`~.reservation.CreateAssignmentRequest`): + The request object. The request for + [ReservationService.CreateAssignment][google.cloud.bigquery.reservation.v1.ReservationService.CreateAssignment]. + Note: "bigquery.reservationAssignments.create" + permission is required on the related assignee. + parent (:class:`str`): + Required. The parent resource name of the assignment + E.g. + ``projects/myproject/locations/US/reservations/team1-prod`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + assignment (:class:`~.reservation.Assignment`): + Assignment resource to create. + This corresponds to the ``assignment`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.Assignment: + A Assignment allows a project to + submit jobs of a certain type using + slots from the specified reservation. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, assignment]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.CreateAssignmentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.CreateAssignmentRequest): + request = reservation.CreateAssignmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if assignment is not None: + request.assignment = assignment + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.create_assignment] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def list_assignments( + self, + request: reservation.ListAssignmentsRequest = None, + *, + parent: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.ListAssignmentsPager: + r"""Lists assignments. + + Only explicitly created assignments will be returned. + + Example: + + - Organization ``organizationA`` contains two projects, + ``project1`` and ``project2``. + - Reservation ``res1`` exists and was created previously. + - CreateAssignment was used previously to define the following + associations between entities and reservations: + ```` and ```` + + In this example, ListAssignments will just return the above two + assignments for reservation ``res1``, and no expansion/merge + will happen. + + The wildcard "-" can be used for reservations in the request. In + that case all assignments belongs to the specified project and + location will be listed. + + **Note** "-" cannot be used for projects nor locations. + + Args: + request (:class:`~.reservation.ListAssignmentsRequest`): + The request object. The request for + [ReservationService.ListAssignments][google.cloud.bigquery.reservation.v1.ReservationService.ListAssignments]. + parent (:class:`str`): + Required. The parent resource name e.g.: + + ``projects/myproject/locations/US/reservations/team1-prod`` + + Or: + + ``projects/myproject/locations/US/reservations/-`` + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.ListAssignmentsPager: + The response for + [ReservationService.ListAssignments][google.cloud.bigquery.reservation.v1.ReservationService.ListAssignments]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.ListAssignmentsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.ListAssignmentsRequest): + request = reservation.ListAssignmentsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.list_assignments] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.ListAssignmentsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def delete_assignment( + self, + request: reservation.DeleteAssignmentRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> None: + r"""Deletes a assignment. No expansion will happen. + + Example: + + - Organization ``organizationA`` contains two projects, + ``project1`` and ``project2``. + - Reservation ``res1`` exists and was created previously. + - CreateAssignment was used previously to define the following + associations between entities and reservations: + ```` and ```` + + In this example, deletion of the ```` + assignment won't affect the other assignment + ````. After said deletion, queries from + ``project1`` will still use ``res1`` while queries from + ``project2`` will switch to use on-demand mode. + + Args: + request (:class:`~.reservation.DeleteAssignmentRequest`): + The request object. The request for + [ReservationService.DeleteAssignment][google.cloud.bigquery.reservation.v1.ReservationService.DeleteAssignment]. + Note: "bigquery.reservationAssignments.delete" + permission is required on the related assignee. + name (:class:`str`): + Required. Name of the resource, e.g. + ``projects/myproject/locations/US/reservations/team1-prod/assignments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.DeleteAssignmentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.DeleteAssignmentRequest): + request = reservation.DeleteAssignmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.delete_assignment] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + rpc( + request, retry=retry, timeout=timeout, metadata=metadata, + ) + + def search_assignments( + self, + request: reservation.SearchAssignmentsRequest = None, + *, + parent: str = None, + query: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> pagers.SearchAssignmentsPager: + r"""Looks up assignments for a specified resource for a particular + region. If the request is about a project: + + 1. Assignments created on the project will be returned if they + exist. + 2. Otherwise assignments created on the closest ancestor will be + returned. + 3. Assignments for different JobTypes will all be returned. + + The same logic applies if the request is about a folder. + + If the request is about an organization, then assignments + created on the organization will be returned (organization + doesn't have ancestors). + + Comparing to ListAssignments, there are some behavior + differences: + + 1. permission on the assignee will be verified in this API. + 2. Hierarchy lookup (project->folder->organization) happens in + this API. + 3. Parent here is ``projects/*/locations/*``, instead of + ``projects/*/locations/*reservations/*``. + + **Note** "-" cannot be used for projects nor locations. + + Args: + request (:class:`~.reservation.SearchAssignmentsRequest`): + The request object. The request for + [ReservationService.SearchAssignments][google.cloud.bigquery.reservation.v1.ReservationService.SearchAssignments]. + Note: "bigquery.reservationAssignments.search" + permission is required on the related assignee. + parent (:class:`str`): + Required. The resource name of the admin + project(containing project and location), e.g.: + ``projects/myproject/locations/US``. + This corresponds to the ``parent`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + query (:class:`str`): + Please specify resource name as assignee in the query. + + Examples: + + - ``assignee=projects/myproject`` + - ``assignee=folders/123`` + - ``assignee=organizations/456`` + + This corresponds to the ``query`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.pagers.SearchAssignmentsPager: + The response for + [ReservationService.SearchAssignments][google.cloud.bigquery.reservation.v1.ReservationService.SearchAssignments]. + + Iterating over this object will yield results and + resolve additional pages automatically. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([parent, query]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.SearchAssignmentsRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.SearchAssignmentsRequest): + request = reservation.SearchAssignmentsRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if parent is not None: + request.parent = parent + if query is not None: + request.query = query + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.search_assignments] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("parent", request.parent),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # This method is paged; wrap the response in a pager, which provides + # an `__iter__` convenience method. + response = pagers.SearchAssignmentsPager( + method=rpc, request=request, response=response, metadata=metadata, + ) + + # Done; return the response. + return response + + def move_assignment( + self, + request: reservation.MoveAssignmentRequest = None, + *, + name: str = None, + destination_id: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.Assignment: + r"""Moves an assignment under a new reservation. + This differs from removing an existing assignment and + recreating a new one by providing a transactional change + that ensures an assignee always has an associated + reservation. + + Args: + request (:class:`~.reservation.MoveAssignmentRequest`): + The request object. The request for + [ReservationService.MoveAssignment][google.cloud.bigquery.reservation.v1.ReservationService.MoveAssignment]. + **Note**: "bigquery.reservationAssignments.create" + permission is required on the destination_id. + + **Note**: "bigquery.reservationAssignments.create" and + "bigquery.reservationAssignments.delete" permission are + required on the related assignee. + name (:class:`str`): + Required. The resource name of the assignment, e.g. + ``projects/myproject/locations/US/reservations/team1-prod/assignments/123`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + destination_id (:class:`str`): + The new reservation ID, e.g.: + ``projects/myotherproject/locations/US/reservations/team2-prod`` + This corresponds to the ``destination_id`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.Assignment: + A Assignment allows a project to + submit jobs of a certain type using + slots from the specified reservation. + + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name, destination_id]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.MoveAssignmentRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.MoveAssignmentRequest): + request = reservation.MoveAssignmentRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + if destination_id is not None: + request.destination_id = destination_id + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.move_assignment] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def get_bi_reservation( + self, + request: reservation.GetBiReservationRequest = None, + *, + name: str = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.BiReservation: + r"""Retrieves a BI reservation. + + Args: + request (:class:`~.reservation.GetBiReservationRequest`): + The request object. A request to get a singleton BI + reservation. + name (:class:`str`): + Required. Name of the requested reservation, for + example: + ``projects/{project_id}/locations/{location_id}/bireservation`` + This corresponds to the ``name`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.BiReservation: + Represents a BI Reservation. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([name]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.GetBiReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.GetBiReservationRequest): + request = reservation.GetBiReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if name is not None: + request.name = name + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.get_bi_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata((("name", request.name),)), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + def update_bi_reservation( + self, + request: reservation.UpdateBiReservationRequest = None, + *, + bi_reservation: reservation.BiReservation = None, + update_mask: field_mask.FieldMask = None, + retry: retries.Retry = gapic_v1.method.DEFAULT, + timeout: float = None, + metadata: Sequence[Tuple[str, str]] = (), + ) -> reservation.BiReservation: + r"""Updates a BI reservation. + + Only fields specified in the ``field_mask`` are updated. + + A singleton BI reservation always exists with default size 0. In + order to reserve BI capacity it needs to be updated to an amount + greater than 0. In order to release BI capacity reservation size + must be set to 0. + + Args: + request (:class:`~.reservation.UpdateBiReservationRequest`): + The request object. A request to update a BI + reservation. + bi_reservation (:class:`~.reservation.BiReservation`): + A reservation to update. + This corresponds to the ``bi_reservation`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + update_mask (:class:`~.field_mask.FieldMask`): + A list of fields to be updated in + this request. + This corresponds to the ``update_mask`` field + on the ``request`` instance; if ``request`` is provided, this + should not be set. + + retry (google.api_core.retry.Retry): Designation of what errors, if any, + should be retried. + timeout (float): The timeout for this request. + metadata (Sequence[Tuple[str, str]]): Strings which should be + sent along with the request as metadata. + + Returns: + ~.reservation.BiReservation: + Represents a BI Reservation. + """ + # Create or coerce a protobuf request object. + # Sanity check: If we got a request object, we should *not* have + # gotten any keyword arguments that map to the request. + has_flattened_params = any([bi_reservation, update_mask]) + if request is not None and has_flattened_params: + raise ValueError( + "If the `request` argument is set, then none of " + "the individual field arguments should be set." + ) + + # Minor optimization to avoid making a copy if the user passes + # in a reservation.UpdateBiReservationRequest. + # There's no risk of modifying the input as we've already verified + # there are no flattened fields. + if not isinstance(request, reservation.UpdateBiReservationRequest): + request = reservation.UpdateBiReservationRequest(request) + + # If we have keyword arguments corresponding to fields on the + # request, apply these. + + if bi_reservation is not None: + request.bi_reservation = bi_reservation + if update_mask is not None: + request.update_mask = update_mask + + # Wrap the RPC method; this adds retry and timeout information, + # and friendly error handling. + rpc = self._transport._wrapped_methods[self._transport.update_bi_reservation] + + # Certain fields should be provided within the metadata header; + # add these here. + metadata = tuple(metadata) + ( + gapic_v1.routing_header.to_grpc_metadata( + (("bi_reservation.name", request.bi_reservation.name),) + ), + ) + + # Send the request. + response = rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + + # Done; return the response. + return response + + +try: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo( + gapic_version=pkg_resources.get_distribution( + "google-cloud-bigquery-reservation", + ).version, + ) +except pkg_resources.DistributionNotFound: + DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() + + +__all__ = ("ReservationServiceClient",) diff --git a/google/cloud/bigquery/reservation_v1/services/reservation_service/pagers.py b/google/cloud/bigquery_reservation_v1/services/reservation_service/pagers.py similarity index 99% rename from google/cloud/bigquery/reservation_v1/services/reservation_service/pagers.py rename to google/cloud/bigquery_reservation_v1/services/reservation_service/pagers.py index a20d3438..a1c94827 100644 --- a/google/cloud/bigquery/reservation_v1/services/reservation_service/pagers.py +++ b/google/cloud/bigquery_reservation_v1/services/reservation_service/pagers.py @@ -17,7 +17,7 @@ from typing import Any, AsyncIterable, Awaitable, Callable, Iterable, Sequence, Tuple -from google.cloud.bigquery.reservation_v1.types import reservation +from google.cloud.bigquery_reservation_v1.types import reservation class ListReservationsPager: diff --git a/google/cloud/bigquery/reservation_v1/services/reservation_service/transports/__init__.py b/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/__init__.py similarity index 100% rename from google/cloud/bigquery/reservation_v1/services/reservation_service/transports/__init__.py rename to google/cloud/bigquery_reservation_v1/services/reservation_service/transports/__init__.py diff --git a/google/cloud/bigquery/reservation_v1/services/reservation_service/transports/base.py b/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/base.py similarity index 72% rename from google/cloud/bigquery/reservation_v1/services/reservation_service/transports/base.py rename to google/cloud/bigquery_reservation_v1/services/reservation_service/transports/base.py index f0140e1d..3f9b2546 100644 --- a/google/cloud/bigquery/reservation_v1/services/reservation_service/transports/base.py +++ b/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/base.py @@ -25,8 +25,8 @@ from google.api_core import retry as retries # type: ignore from google.auth import credentials # type: ignore -from google.cloud.bigquery.reservation_v1.types import reservation -from google.cloud.bigquery.reservation_v1.types import reservation as gcbr_reservation +from google.cloud.bigquery_reservation_v1.types import reservation +from google.cloud.bigquery_reservation_v1.types import reservation as gcbr_reservation from google.protobuf import empty_pb2 as empty # type: ignore @@ -112,76 +112,170 @@ def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { self.create_reservation: gapic_v1.method.wrap_method( - self.create_reservation, default_timeout=None, client_info=client_info, + self.create_reservation, default_timeout=60.0, client_info=client_info, ), self.list_reservations: gapic_v1.method.wrap_method( - self.list_reservations, default_timeout=None, client_info=client_info, + self.list_reservations, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=client_info, ), self.get_reservation: gapic_v1.method.wrap_method( - self.get_reservation, default_timeout=None, client_info=client_info, + self.get_reservation, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=client_info, ), self.delete_reservation: gapic_v1.method.wrap_method( - self.delete_reservation, default_timeout=None, client_info=client_info, + self.delete_reservation, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=client_info, ), self.update_reservation: gapic_v1.method.wrap_method( - self.update_reservation, default_timeout=None, client_info=client_info, + self.update_reservation, default_timeout=60.0, client_info=client_info, ), self.create_capacity_commitment: gapic_v1.method.wrap_method( self.create_capacity_commitment, - default_timeout=None, + default_timeout=60.0, client_info=client_info, ), self.list_capacity_commitments: gapic_v1.method.wrap_method( self.list_capacity_commitments, - default_timeout=None, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, client_info=client_info, ), self.get_capacity_commitment: gapic_v1.method.wrap_method( self.get_capacity_commitment, - default_timeout=None, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, client_info=client_info, ), self.delete_capacity_commitment: gapic_v1.method.wrap_method( self.delete_capacity_commitment, - default_timeout=None, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, client_info=client_info, ), self.update_capacity_commitment: gapic_v1.method.wrap_method( self.update_capacity_commitment, - default_timeout=None, + default_timeout=60.0, client_info=client_info, ), self.split_capacity_commitment: gapic_v1.method.wrap_method( self.split_capacity_commitment, - default_timeout=None, + default_timeout=60.0, client_info=client_info, ), self.merge_capacity_commitments: gapic_v1.method.wrap_method( self.merge_capacity_commitments, - default_timeout=None, + default_timeout=60.0, client_info=client_info, ), self.create_assignment: gapic_v1.method.wrap_method( - self.create_assignment, default_timeout=None, client_info=client_info, + self.create_assignment, default_timeout=60.0, client_info=client_info, ), self.list_assignments: gapic_v1.method.wrap_method( - self.list_assignments, default_timeout=None, client_info=client_info, + self.list_assignments, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=client_info, ), self.delete_assignment: gapic_v1.method.wrap_method( - self.delete_assignment, default_timeout=None, client_info=client_info, + self.delete_assignment, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=client_info, ), self.search_assignments: gapic_v1.method.wrap_method( - self.search_assignments, default_timeout=None, client_info=client_info, + self.search_assignments, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=client_info, ), self.move_assignment: gapic_v1.method.wrap_method( - self.move_assignment, default_timeout=None, client_info=client_info, + self.move_assignment, default_timeout=60.0, client_info=client_info, ), self.get_bi_reservation: gapic_v1.method.wrap_method( - self.get_bi_reservation, default_timeout=None, client_info=client_info, + self.get_bi_reservation, + default_retry=retries.Retry( + initial=0.1, + maximum=60.0, + multiplier=1.3, + predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.ServiceUnavailable, + ), + ), + default_timeout=60.0, + client_info=client_info, ), self.update_bi_reservation: gapic_v1.method.wrap_method( self.update_bi_reservation, - default_timeout=None, + default_timeout=60.0, client_info=client_info, ), } diff --git a/google/cloud/bigquery/reservation_v1/services/reservation_service/transports/grpc.py b/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc.py similarity index 99% rename from google/cloud/bigquery/reservation_v1/services/reservation_service/transports/grpc.py rename to google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc.py index 266aab8c..90ec2952 100644 --- a/google/cloud/bigquery/reservation_v1/services/reservation_service/transports/grpc.py +++ b/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc.py @@ -26,8 +26,8 @@ import grpc # type: ignore -from google.cloud.bigquery.reservation_v1.types import reservation -from google.cloud.bigquery.reservation_v1.types import reservation as gcbr_reservation +from google.cloud.bigquery_reservation_v1.types import reservation +from google.cloud.bigquery_reservation_v1.types import reservation as gcbr_reservation from google.protobuf import empty_pb2 as empty # type: ignore from .base import ReservationServiceTransport, DEFAULT_CLIENT_INFO diff --git a/google/cloud/bigquery/reservation_v1/services/reservation_service/transports/grpc_asyncio.py b/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc_asyncio.py similarity index 99% rename from google/cloud/bigquery/reservation_v1/services/reservation_service/transports/grpc_asyncio.py rename to google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc_asyncio.py index 9ea590aa..4f80cac0 100644 --- a/google/cloud/bigquery/reservation_v1/services/reservation_service/transports/grpc_asyncio.py +++ b/google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc_asyncio.py @@ -27,8 +27,8 @@ import grpc # type: ignore from grpc.experimental import aio # type: ignore -from google.cloud.bigquery.reservation_v1.types import reservation -from google.cloud.bigquery.reservation_v1.types import reservation as gcbr_reservation +from google.cloud.bigquery_reservation_v1.types import reservation +from google.cloud.bigquery_reservation_v1.types import reservation as gcbr_reservation from google.protobuf import empty_pb2 as empty # type: ignore from .base import ReservationServiceTransport, DEFAULT_CLIENT_INFO diff --git a/google/cloud/bigquery/reservation_v1/types/__init__.py b/google/cloud/bigquery_reservation_v1/types/__init__.py similarity index 100% rename from google/cloud/bigquery/reservation_v1/types/__init__.py rename to google/cloud/bigquery_reservation_v1/types/__init__.py diff --git a/google/cloud/bigquery/reservation_v1/types/reservation.py b/google/cloud/bigquery_reservation_v1/types/reservation.py similarity index 100% rename from google/cloud/bigquery/reservation_v1/types/reservation.py rename to google/cloud/bigquery_reservation_v1/types/reservation.py diff --git a/scripts/fixup_reservation_v1_keywords.py b/scripts/fixup_bigquery_reservation_v1_keywords.py similarity index 97% rename from scripts/fixup_reservation_v1_keywords.py rename to scripts/fixup_bigquery_reservation_v1_keywords.py index bc9c8f00..7056b9ed 100644 --- a/scripts/fixup_reservation_v1_keywords.py +++ b/scripts/fixup_bigquery_reservation_v1_keywords.py @@ -38,7 +38,7 @@ def partition( return results[1], results[0] -class reservationCallTransformer(cst.CSTTransformer): +class bigquery_reservationCallTransformer(cst.CSTTransformer): CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata') METHOD_TO_PARAMS: Dict[str, Tuple[str]] = { 'create_assignment': ('parent', 'assignment', ), @@ -109,7 +109,7 @@ def fix_files( in_dir: pathlib.Path, out_dir: pathlib.Path, *, - transformer=reservationCallTransformer(), + transformer=bigquery_reservationCallTransformer(), ): """Duplicate the input dir to the output dir, fixing file method calls. @@ -142,7 +142,7 @@ def fix_files( if __name__ == '__main__': parser = argparse.ArgumentParser( - description="""Fix up source that uses the reservation client library. + description="""Fix up source that uses the bigquery_reservation client library. The existing sources are NOT overwritten but are copied to output_dir with changes made. diff --git a/synth.metadata b/synth.metadata index ebfa71db..23649272 100644 --- a/synth.metadata +++ b/synth.metadata @@ -4,15 +4,15 @@ "git": { "name": ".", "remote": "https://github.com/googleapis/python-bigquery-reservation.git", - "sha": "21bff87047519754a01983c9a4551cb534bcb88c" + "sha": "dcea1f2c3bed3a79be0a55218df6698cc29d3bf5" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "5ad09e867a8f1faa19fbd674e51fa9c3f5fe2770", - "internalRef": "326514554" + "sha": "ab0498dc4bd2bcfcb70ab257e8edfa00f86083a6", + "internalRef": "339531446" } }, { @@ -37,12 +37,11 @@ "apiName": "bigquery/reservation", "apiVersion": "v1", "language": "python", - "generator": "gapic-generator-python" + "generator": "bazel" } } ], "generatedFiles": [ - ".coveragerc", ".flake8", ".github/CONTRIBUTING.md", ".github/ISSUE_TEMPLATE/bug_report.md", @@ -92,30 +91,32 @@ "MANIFEST.in", "docs/_static/custom.css", "docs/_templates/layout.html", + "docs/bigquery_reservation_v1/services.rst", + "docs/bigquery_reservation_v1/types.rst", "docs/conf.py", "docs/multiprocessing.rst", - "docs/reservation_v1/services.rst", - "docs/reservation_v1/types.rst", - "google/cloud/bigquery/reservation/__init__.py", - "google/cloud/bigquery/reservation/py.typed", - "google/cloud/bigquery/reservation_v1/__init__.py", - "google/cloud/bigquery/reservation_v1/py.typed", - "google/cloud/bigquery/reservation_v1/services/__init__.py", - "google/cloud/bigquery/reservation_v1/services/reservation_service/__init__.py", "google/cloud/bigquery/reservation_v1/services/reservation_service/async_client.py", "google/cloud/bigquery/reservation_v1/services/reservation_service/client.py", - "google/cloud/bigquery/reservation_v1/services/reservation_service/pagers.py", - "google/cloud/bigquery/reservation_v1/services/reservation_service/transports/__init__.py", - "google/cloud/bigquery/reservation_v1/services/reservation_service/transports/base.py", - "google/cloud/bigquery/reservation_v1/services/reservation_service/transports/grpc.py", - "google/cloud/bigquery/reservation_v1/services/reservation_service/transports/grpc_asyncio.py", - "google/cloud/bigquery/reservation_v1/types/__init__.py", - "google/cloud/bigquery/reservation_v1/types/reservation.py", + "google/cloud/bigquery_reservation/__init__.py", + "google/cloud/bigquery_reservation/py.typed", + "google/cloud/bigquery_reservation_v1/__init__.py", + "google/cloud/bigquery_reservation_v1/py.typed", + "google/cloud/bigquery_reservation_v1/services/__init__.py", + "google/cloud/bigquery_reservation_v1/services/reservation_service/__init__.py", + "google/cloud/bigquery_reservation_v1/services/reservation_service/async_client.py", + "google/cloud/bigquery_reservation_v1/services/reservation_service/client.py", + "google/cloud/bigquery_reservation_v1/services/reservation_service/pagers.py", + "google/cloud/bigquery_reservation_v1/services/reservation_service/transports/__init__.py", + "google/cloud/bigquery_reservation_v1/services/reservation_service/transports/base.py", + "google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc.py", + "google/cloud/bigquery_reservation_v1/services/reservation_service/transports/grpc_asyncio.py", + "google/cloud/bigquery_reservation_v1/types/__init__.py", + "google/cloud/bigquery_reservation_v1/types/reservation.py", "mypy.ini", "noxfile.py", "renovate.json", "scripts/decrypt-secrets.sh", - "scripts/fixup_reservation_v1_keywords.py", + "scripts/fixup_bigquery_reservation_v1_keywords.py", "scripts/readme-gen/readme_gen.py", "scripts/readme-gen/templates/README.tmpl.rst", "scripts/readme-gen/templates/auth.tmpl.rst", @@ -124,7 +125,7 @@ "scripts/readme-gen/templates/install_portaudio.tmpl.rst", "setup.cfg", "testing/.gitignore", - "tests/unit/gapic/reservation_v1/__init__.py", - "tests/unit/gapic/reservation_v1/test_reservation_service.py" + "tests/unit/gapic/bigquery_reservation_v1/__init__.py", + "tests/unit/gapic/bigquery_reservation_v1/test_reservation_service.py" ] } \ No newline at end of file diff --git a/tests/unit/gapic/reservation_v1/__init__.py b/tests/unit/gapic/bigquery_reservation_v1/__init__.py similarity index 100% rename from tests/unit/gapic/reservation_v1/__init__.py rename to tests/unit/gapic/bigquery_reservation_v1/__init__.py diff --git a/tests/unit/gapic/reservation_v1/test_reservation_service.py b/tests/unit/gapic/bigquery_reservation_v1/test_reservation_service.py similarity index 99% rename from tests/unit/gapic/reservation_v1/test_reservation_service.py rename to tests/unit/gapic/bigquery_reservation_v1/test_reservation_service.py index 466b0281..773baa97 100644 --- a/tests/unit/gapic/reservation_v1/test_reservation_service.py +++ b/tests/unit/gapic/bigquery_reservation_v1/test_reservation_service.py @@ -32,16 +32,16 @@ from google.api_core import grpc_helpers_async from google.auth import credentials from google.auth.exceptions import MutualTLSChannelError -from google.cloud.bigquery.reservation_v1.services.reservation_service import ( +from google.cloud.bigquery_reservation_v1.services.reservation_service import ( ReservationServiceAsyncClient, ) -from google.cloud.bigquery.reservation_v1.services.reservation_service import ( +from google.cloud.bigquery_reservation_v1.services.reservation_service import ( ReservationServiceClient, ) -from google.cloud.bigquery.reservation_v1.services.reservation_service import pagers -from google.cloud.bigquery.reservation_v1.services.reservation_service import transports -from google.cloud.bigquery.reservation_v1.types import reservation -from google.cloud.bigquery.reservation_v1.types import reservation as gcbr_reservation +from google.cloud.bigquery_reservation_v1.services.reservation_service import pagers +from google.cloud.bigquery_reservation_v1.services.reservation_service import transports +from google.cloud.bigquery_reservation_v1.types import reservation +from google.cloud.bigquery_reservation_v1.types import reservation as gcbr_reservation from google.oauth2 import service_account from google.protobuf import any_pb2 as gp_any # type: ignore from google.protobuf import field_mask_pb2 as field_mask # type: ignore @@ -440,7 +440,7 @@ def test_reservation_service_client_client_options_credentials_file( def test_reservation_service_client_client_options_from_dict(): with mock.patch( - "google.cloud.bigquery.reservation_v1.services.reservation_service.transports.ReservationServiceGrpcTransport.__init__" + "google.cloud.bigquery_reservation_v1.services.reservation_service.transports.ReservationServiceGrpcTransport.__init__" ) as grpc_transport: grpc_transport.return_value = None client = ReservationServiceClient( @@ -5463,7 +5463,7 @@ def test_reservation_service_base_transport_error(): def test_reservation_service_base_transport(): # Instantiate the base transport. with mock.patch( - "google.cloud.bigquery.reservation_v1.services.reservation_service.transports.ReservationServiceTransport.__init__" + "google.cloud.bigquery_reservation_v1.services.reservation_service.transports.ReservationServiceTransport.__init__" ) as Transport: Transport.return_value = None transport = transports.ReservationServiceTransport( @@ -5503,7 +5503,7 @@ def test_reservation_service_base_transport_with_credentials_file(): with mock.patch.object( auth, "load_credentials_from_file" ) as load_creds, mock.patch( - "google.cloud.bigquery.reservation_v1.services.reservation_service.transports.ReservationServiceTransport._prep_wrapped_messages" + "google.cloud.bigquery_reservation_v1.services.reservation_service.transports.ReservationServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None load_creds.return_value = (credentials.AnonymousCredentials(), None) @@ -5523,7 +5523,7 @@ def test_reservation_service_base_transport_with_credentials_file(): def test_reservation_service_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(auth, "default") as adc, mock.patch( - "google.cloud.bigquery.reservation_v1.services.reservation_service.transports.ReservationServiceTransport._prep_wrapped_messages" + "google.cloud.bigquery_reservation_v1.services.reservation_service.transports.ReservationServiceTransport._prep_wrapped_messages" ) as Transport: Transport.return_value = None adc.return_value = (credentials.AnonymousCredentials(), None)