Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate code from googleapis/python-bigquery-reservation #10261

Merged
merged 54 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
df69248
chore: add reservation quickstart and test (#25)
shollyman Jan 7, 2021
e8a29d6
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Feb 16, 2021
a3a5913
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Mar 10, 2021
a101a20
chore(deps): update dependency pytest to v6.2.3 (#96)
renovate-bot Apr 28, 2021
132d579
chore(deps): update dependency pytest to v6.2.4 (#104)
renovate-bot May 4, 2021
8521bfd
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Jul 1, 2021
a75eca4
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Jul 28, 2021
0482206
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Jul 28, 2021
10221ef
docs: samples for managing reservations (#144)
tswast Aug 13, 2021
84b5217
chore: migrate default branch from master to main (#153)
plamut Aug 26, 2021
993c7c1
chore(deps): update dependency google-cloud-testutils to v1.1.0 (#156)
renovate-bot Aug 30, 2021
aa15a8a
chore(deps): update dependency pytest to v6.2.5 (#155)
renovate-bot Aug 31, 2021
89766f2
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Sep 9, 2021
36c969a
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Sep 27, 2021
1641bc0
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Oct 13, 2021
cd638d7
chore(deps): update dependency google-cloud-testutils to v1.2.0 (#179)
renovate-bot Oct 21, 2021
7a86ef4
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Nov 2, 2021
8333f86
chore(deps): update dependency google-cloud-testutils to v1.3.0 (#194)
renovate-bot Dec 3, 2021
d66e9a0
chore(deps): update dependency google-cloud-testutils to v1.3.1 (#195)
renovate-bot Dec 7, 2021
7a0b79c
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Jan 5, 2022
a6e54c0
chore(deps): update all dependencies (#220)
renovate-bot Feb 8, 2022
41c20a9
chore(deps): update dependency pytest to v7.0.1 (#223)
renovate-bot Feb 14, 2022
2c1fd8c
test: cleanup capacity commitments leftover from failed samples tests…
tswast Feb 28, 2022
767bfad
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Mar 8, 2022
171f354
chore(deps): update dependency pytest to v7.1.0 (#238)
renovate-bot Mar 13, 2022
3620b84
chore(deps): update dependency pytest to v7.1.1 (#239)
renovate-bot Mar 19, 2022
8c60da5
chore(python): use black==22.3.0 (#243)
gcf-owl-bot[bot] Mar 28, 2022
7f55093
chore(python): add nox session to sort python imports (#257)
gcf-owl-bot[bot] Apr 21, 2022
5f8fadf
chore(deps): update dependency pytest to v7.1.2 (#260)
renovate-bot Apr 25, 2022
3aa0324
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot May 19, 2022
3bdef5e
chore(deps): update all dependencies (#276)
renovate-bot Jul 16, 2022
d1d1255
chore(deps): update all dependencies (#289)
renovate-bot Aug 2, 2022
32a5fd1
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Aug 16, 2022
e0a96f6
chore(deps): update dependency pytest to v7.1.3 (#304)
renovate-bot Sep 6, 2022
aefb07b
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Oct 4, 2022
23e3da0
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Oct 18, 2022
2385a0f
chore(deps): update dependency pytest to v7.2.0 (#316)
renovate-bot Oct 26, 2022
d0180e0
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Dec 16, 2022
80ae473
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Jan 11, 2023
e1a9a6b
chore(deps): update dependency pytest to v7.2.1 (#330)
renovate-bot Jan 14, 2023
5935dc0
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Jan 23, 2023
7110a38
feat: enable "rest" transport in Python for services supporting numer…
gcf-owl-bot[bot] Feb 16, 2023
65de231
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Mar 1, 2023
479ac49
chore(deps): update dependency pytest to v7.2.2 (#345)
renovate-bot Mar 4, 2023
75a2dcd
chore(deps): update dependency google-cloud-bigquery-reservation to v…
renovate-bot Mar 30, 2023
b8131db
chore(deps): update dependency pytest to v7.3.1 (#354)
renovate-bot Jun 1, 2023
ebaabcf
skip python-3.6 in sample test
dizcology Jun 16, 2023
cb61b03
update .githug/CODEOWNERS
dizcology Jun 20, 2023
88c746d
remove capacity commitment from tests and conftest.py
dizcology Jul 20, 2023
8d2cf7d
remove unused imports
dizcology Jul 20, 2023
658f48c
remove unused imports
dizcology Jul 20, 2023
035a688
set edition to ENTERPRISE in reservation_create
dizcology Jul 20, 2023
270ad34
skip reservation_update test
dizcology Jul 20, 2023
677a4a1
remove unused import, add comments about skipped test
dizcology Jul 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
/bigquery-connection/**/* @GoogleCloudPlatform/api-bigquery @GoogleCloudPlatform/python-samples-reviewers
/bigquery-datatransfer/**/* @GoogleCloudPlatform/api-bigquery @GoogleCloudPlatform/python-samples-reviewers
/bigquery-migration/**/* @GoogleCloudPlatform/api-bigquery @GoogleCloudPlatform/python-samples-reviewers
/bigquery-reservation/**/* @GoogleCloudPlatform/api-bigquery @GoogleCloudPlatform/python-samples-reviewers
/dlp/**/* @GoogleCloudPlatform/googleapis-dlp @GoogleCloudPlatform/python-samples-reviewers
/functions/spanner/* @GoogleCloudPlatform/api-spanner-python @GoogleCloudPlatform/functions-framework-google @GoogleCloudPlatform/python-samples-reviewers
/healthcare/**/* @GoogleCloudPlatform/healthcare-life-sciences @GoogleCloudPlatform/python-samples-reviewers
Expand Down
Empty file.
42 changes: 42 additions & 0 deletions bigquery-reservation/snippets/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2021 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
#
# https://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.

import os

from google.cloud.bigquery_reservation_v1.services import reservation_service
import pytest


@pytest.fixture(scope="session")
def project_id() -> str:
return os.environ["GOOGLE_CLOUD_PROJECT"]


@pytest.fixture(scope="session")
def reservation_client(
transport: str = "grpc",
) -> reservation_service.ReservationServiceClient:
return reservation_service.ReservationServiceClient(transport=transport)


@pytest.fixture(scope="session")
def location() -> str:
return "US"


@pytest.fixture(scope="session")
def location_path(project_id: str, location: str) -> str:
return reservation_service.ReservationServiceClient.common_location_path(
project_id, location
)
38 changes: 38 additions & 0 deletions bigquery-reservation/snippets/noxfile_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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.

# Default TEST_CONFIG_OVERRIDE for python repos.

# You can copy this file into your directory, then it will be inported from
# the noxfile.py.

# The source of truth:
# https://github.com/GoogleCloudPlatform/python-docs-samples/blob/master/noxfile_config.py

TEST_CONFIG_OVERRIDE = {
# You can opt out from the test for specific Python versions.
"ignored_versions": ["2.7", "3.6"],
# Old samples are opted out of enforcing Python type hints
# All new samples should feature them
"enforce_type_hints": True,
# An envvar key for determining the project id to use. Change it
# to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a
# build specific Cloud project. You can also use your own string
# to use your own Cloud project.
"gcloud_project_env": "GOOGLE_CLOUD_PROJECT",
# 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT',
# A dictionary you want to inject into your test. Don't put any
# secrets here. These values will override predefined values.
"envs": {},
}
59 changes: 59 additions & 0 deletions bigquery-reservation/snippets/quickstart.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# 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
#
# https://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.

# [START bigqueryreservation_quickstart]
import argparse

from google.cloud import bigquery_reservation_v1


def main(
project_id: str = "your-project-id", location: str = "US", transport: str = "grpc"
) -> None:
# Constructs the client for interacting with the service.
client = bigquery_reservation_v1.ReservationServiceClient(transport=transport)

report_reservations(client, project_id, location)


def report_reservations(
client: bigquery_reservation_v1.ReservationServiceClient,
project_id: str,
location: str,
) -> None:
"""Prints details and summary information about reservations defined within
a given admin project and location.
"""
print("Reservations in project {} in location {}".format(project_id, location))
req = bigquery_reservation_v1.ListReservationsRequest(
parent=client.common_location_path(project_id, location)
)
total_reservations = 0
for reservation in client.list_reservations(request=req):
print(
f"\tReservation {reservation.name} "
f"has {reservation.slot_capacity} slot capacity."
)
total_reservations = total_reservations + 1
print(f"\n{total_reservations} reservations processed.")


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--project_id", type=str)
parser.add_argument("--location", default="US", type=str)
args = parser.parse_args()
main(project_id=args.project_id, location=args.location)

# [END bigqueryreservation_quickstart]
26 changes: 26 additions & 0 deletions bigquery-reservation/snippets/quickstart_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 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
#
# https://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.

import pytest

from . import quickstart


@pytest.mark.parametrize("transport", ["grpc", "rest"])
def test_quickstart(
capsys: pytest.CaptureFixture, project_id: str, transport: str
) -> None:
quickstart.main(project_id=project_id, transport=transport)
out, _ = capsys.readouterr()
assert " reservations processed." in out
2 changes: 2 additions & 0 deletions bigquery-reservation/snippets/requirements-test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest==7.3.1
google-cloud-testutils==1.3.3
1 change: 1 addition & 0 deletions bigquery-reservation/snippets/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
google-cloud-bigquery-reservation==1.11.1
79 changes: 79 additions & 0 deletions bigquery-reservation/snippets/reservation_create.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Copyright 2021 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
#
# https://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 google.cloud.bigquery_reservation_v1.types import reservation as reservation_types


def create_reservation(
project_id: str,
location: str,
reservation_id: str,
slot_capacity: str,
transport: str,
) -> reservation_types.Reservation:
original_project_id = project_id
original_location = location
original_reservation_id = reservation_id
original_slot_capacity = slot_capacity
original_transport = transport

# [START bigqueryreservation_reservation_create]
# TODO(developer): Set project_id to the project ID containing the
# reservation.
project_id = "your-project-id"

# TODO(developer): Set location to the location of the reservation.
# See: https://cloud.google.com/bigquery/docs/locations for a list of
# available locations.
location = "US"

# TODO(developer): Set reservation_id to a unique ID of the reservation.
reservation_id = "sample-reservation"

# TODO(developer): Set slot_capicity to the number of slots in the
# reservation.
slot_capacity = 100

# TODO(developer): Choose a transport to use. Either 'grpc' or 'rest'
transport = "grpc"

# [START_EXCLUDE]
project_id = original_project_id
location = original_location
reservation_id = original_reservation_id
slot_capacity = original_slot_capacity
transport = original_transport
# [END_EXCLUDE]

from google.cloud.bigquery_reservation_v1.services import reservation_service
from google.cloud.bigquery_reservation_v1.types import (
reservation as reservation_types,
)

reservation_client = reservation_service.ReservationServiceClient(
transport=transport
)

parent = reservation_client.common_location_path(project_id, location)

reservation = reservation_types.Reservation(slot_capacity=slot_capacity)
reservation = reservation_client.create_reservation(
parent=parent,
reservation=reservation,
reservation_id=reservation_id,
)

print(f"Created reservation: {reservation.name}")
# [END bigqueryreservation_reservation_create]
return reservation
58 changes: 58 additions & 0 deletions bigquery-reservation/snippets/reservation_delete.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright 2021 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
#
# https://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.


def delete_reservation(
project_id: str, location: str, reservation_id: str, transport: str
) -> None:
original_project_id = project_id
original_location = location
original_reservation_id = reservation_id
original_transport = transport

# [START bigqueryreservation_reservation_delete]
# TODO(developer): Set project_id to the project ID containing the
# reservation.
project_id = "your-project-id"

# TODO(developer): Set location to the location of the reservation.
# See: https://cloud.google.com/bigquery/docs/locations for a list of
# available locations.
location = "US"

# TODO(developer): Set reservation_id to a unique ID of the reservation.
reservation_id = "sample-reservation"

# TODO(developer): Choose a transport to use. Either 'grpc' or 'rest'
transport = "grpc"

# [START_EXCLUDE]
project_id = original_project_id
location = original_location
reservation_id = original_reservation_id
transport = original_transport
# [END_EXCLUDE]

from google.cloud.bigquery_reservation_v1.services import reservation_service

reservation_client = reservation_service.ReservationServiceClient(
transport=transport
)
reservation_name = reservation_client.reservation_path(
project_id, location, reservation_id
)
reservation_client.delete_reservation(name=reservation_name)

print(f"Deleted reservation: {reservation_name}")
# [END bigqueryreservation_reservation_delete]
Loading